Object or class type required - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Object or class type required

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;



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


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

procedure newfile;
var mainfile : textfile;
filetext , charname : string;
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]);
[color=Red]gamecharname := Tcharacter.character;
currentgold := StrtoInt(Tcharacter.goldamount);[/color]
closefile (gamefile);
end; // of procedure

procedure loadfile;
var mainfile : textfile;
filetext: string;
{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;
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
end; // of if
if input = 2 then
end; // of if
if (input > 2) or (input < 1) then
writeln ('You idiot! Get an education before playing this game!');
end; // of if
end; // of procedure

writeln (gamecharname);
writeln (currentgold);
end. // of program


Sign In or Register to comment.