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;

{$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]);
[color=Red]gamecharname := Tcharacter.character;
currentgold := StrtoInt(Tcharacter.goldamount);[/color]
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

Comments

  • Hi

    You should try:




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

    since the variable's named characterdata; TCharacter being its type;
  • thanks for info
Sign In or Register to comment.

Howdy, Stranger!

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

Categories