2
votes
procedure ListMembers;
var
  Member, lMembers: string;
  lengthOfMember: Longint;
begin
  Writeln; 
  Writeln;
  Reset(FileA); //Only need read-only
  Reset(FileB); //Only need read-only
  while not Eof(FileA) do
    begin
      Readln(FileA, lMembers);
      Write(lMembers);
    end;
  Writeln(sLineBreak + sLineBreak);
  Write('Type the name of the member for more information: ');
  Readln(Member);
  lengthOfMember := Length(Member) + 2;
  Seek(FileB, lengthOfMember);
end;

I get a problem here when trying to compile. The Seek(); on the last line returns the error incompatible type. As far as I've read online, Seek takes in var: File and var: longint so I don't see why it's considered a bad type as I'm feeding it a file, and a longint.

FileB was Assigned to a text file in the main section of the code. This part is just a procedure.

Appreciate any help. More of the code below.

program WoWProject;

{$APPTYPE CONSOLE}

uses
SysUtils;

type
  TMember = record
  Name : string;
  Level : integer;
  CharClass : string;
  Role : string;
  Spec : string;
  DKP : integer;
end;

var
FileA, FileB : Textfile;

//THIS PART IS THE PROCEDURE ABOVE
//ANOTHER PROCEDURE HERE UNRELATED TO THIS
//ANOTHER HERE WHICH IS THE WELCOME PROCEDURE

//MAIN
begin
 Assign(FileA, 'CharacterNames.txt');
 Assign(FileB, 'CharacterInfo.txt');
 repeat
   Append(FileA);
   Append(FileB);
   Welcome;
 until 1=2
end.
3
Is the error about incompatible type the only one, or is there more? Could it be that the FileB isn't in the scope and because of that compiler assumes it to be a integer?ain
please post complete code with everything defined. Don't make us guess.David Heffernan
ain - This is the only error. I think it might be because Seek doesn't like text files, is that right? The text file is also defined in the global varsAstonix
Show us the declaration of the variable FileB.Steve Mayne
If you need to see the other procedures, let me know. Didn't want to add it all as it might make it quite long. The other procedures don't give any errors.Astonix

3 Answers

1
votes

The documentation describes Seek() as so:

Moves the current position of a typed or untyped file to a specified component. Not used with text files.

Herein lies your problem.

1
votes

You can use this procedure:

PROCEDURE TextSeek(VAR F : TEXT ; POS : Cardinal);
  BEGIN
    WITH TTextRec(F) DO BEGIN
      BufPos:=0; BufEnd:=0;
      SetFilePointer(Handle,POS,NIL,FILE_BEGIN)
    END
  END;

But beware that the above is intended only for READING from the file. If you WRITE to the file, you simply overwrite the bytes in the file, regardless of any line breaks or not (there's no way to "insert" text in an existing text file).

0
votes

Define RECORD type and open file as record or TFileStream. Write Your code again and then ask. You have many different code parts from... i'dont know.

Define like this (example):

type
 TMember = record
  Name : string[50];
  Level : integer;
  CharClass : string[50];
  Role : string[50];
  Spec : string[50];
  DKP : integer;
 end;
 Member = file of TMember;
var
  FileA : file of TMember;

You must enter length of strings in this case. And Seek will work as You wish ;)

You can change: from:

Seek(FileB, lengthOfMember); 

to:

Seek(FileB, length(Member));