Astonix
Astonix

Reputation: 23

Delphi - Seek(); Procedure. Incompatible Type

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.

Upvotes: 2

Views: 2785

Answers (3)

wcale
wcale

Reputation: 51

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)); 

Upvotes: 0

HeartWare
HeartWare

Reputation: 8243

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).

Upvotes: 1

David Heffernan
David Heffernan

Reputation: 612993

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.

Upvotes: 1

Related Questions