Delphi beginners

Moderators: netgert
Number of threads: 352
Number of posts: 975

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Object or class type required Posted by tomaszavenger on 22 Oct 2009 at 3:01 AM
I'm confused as to solutions given by other people when searching for this error online. Basically, I have a variable, and I want to assign a part of a record as that variable's value (this cannot be done).

How could I get the part of the record to be assigned to the variable?

I'll post the source code to the project I'm working on (a uncomplete section for a new/load feature for a text-based rpg). Error is highlighted in red. Help is appreciated, and if you could also fix the below code, that would be appreciated (note, the load part isn't yet functional, but I hope to do this later).



program rpg2;

{$APPTYPE CONSOLE}

uses
SysUtils;

type
Tcharacter = record
character : string[5];
goldamount : string[4];
end; //of record

var

characterdata : array [1..1] of Tcharacter;
gamefile : file of Tcharacter ;
gamecharname: string;
currentgold: integer;
tchar: string;

procedure newfile;
var mainfile : textfile;
filetext , charname : string;
begin
writeln ('input new file name (do not forget to add the .txt)');
readln (filetext);
writeln ('input new character name');
readln (charname);
assignfile (mainfile,filetext);
rewrite (mainfile);
writeln (mainfile, charname);
writeln (mainfile,'0000');
closefile (mainfile);
assignfile (gamefile,filetext);
reset (gamefile);
Read (gamefile, characterdata[1]);
gamecharname := Tcharacter.character;
currentgold := StrtoInt(Tcharacter.goldamount);

closefile (gamefile);
end; // of procedure

procedure loadfile;
var mainfile : textfile;
filetext: string;
begin
{writeln ('no feature implemented yet, sorry');
writeln ('input file which you wish to load (do not forget to add the .txt)');
readln (filetext);
assignfile (mainfile , filetext);
reset (mainfile);
closefile (mainfile);}
end; // of procedure

procedure startup;
var input : integer;
begin
Writeln ('Welcome to the game! Would you like to start a new game (1),');
Writeln ('or load an existing one? (2)');
Readln (input);
if input = 1 then
begin
newfile;
end; // of if
if input = 2 then
begin
loadfile;
end; // of if
if (input > 2) or (input < 1) then
begin
writeln ('You idiot! Get an education before playing this game!');
end; // of if
end; // of procedure

begin
startup;
writeln (gamecharname);
writeln (currentgold);
end. // of program
Report
Re: Object or class type required Posted by Placo on 5 Nov 2009 at 9:58 AM
Hi

You should try:




gamecharname := characterdata[1].character;
currentgold := StrtoInt(characterdata[1].goldamount);


since the variable's named characterdata; TCharacter being its type;
Report
Re: Object or class type required Posted by dasli on 30 Jul 2010 at 3:13 AM
thanks for info



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.