"Read beyond end of file" error when migrating Delphi 7 app To RAD Studio 10

110 views Asked by At

I have an old program in Delphi 7 and want to convert it to RAD Studio 10.3.

The old program uses these record structures in a file.

TYPE
TPanel = RECORD
  Name     : String[40];
  Width    : Integer;
  Height   : Integer;
  TypeID   : String[20];
  TypeName : String[40];
  Price    : Extended;
END;

TWorktop = RECORD
  Width    : Integer;
  Height   : Integer;
  TypeID   : String[20];
  TypeName : String[40];
  Price    : Extended;
End;

TData = RECORD
  ID: String[20];
  IDName   : String[30];
  OrderName: String[30];
  OrderAdr : String[30];
  Quantity : Integer;
  CselcsicsAzon : String[30];
  dateCreate    : TDate;
  ProjectChanged: Boolean;
  PanelCount    : Integer;
  Panels   : Array[1..orderMaxPanel+1] Of TPanel;
  PanelCount    : Integer;
  Worktops : Array[1..orderMaxWorktop+1] Of TWorktop;
  WorktopCount  : Integer;
  Price    : Extended;
END;

Var
  Data: TData;
  F: File Of TData;

Begin
  AssignFile(F,Filename);
  Reset(F);
  Read(F,D);
  CloseFile(F);
End;

Delphi 7 reads the file OK.

RAD Studio 10.3 errors when reading the file (Read beyond end of file).

As I looked into it, the String type in RAD Studio is not the same as the Delphi 7 String type. It should be AnsiString instead. But AnsiString[40] is not accepted.

How should I modify the code so that I can create the file in Delphi 7 and then read/write it in RAD Studio?


UPDATE:

The difference:

TTest = RECORD
    rhLeft,
    rhTop,
    rhRight,
    rhBottom    : Extended;
end;

Size is not equal in Delphi 7 and RAD Studio.

But:

TTest = RECORD
    rhLeft: Extended;
    rhTop: Extended;
    rhRight: Extended;
    rhBottom    : Extended;
end;

Size is equal, but Delphi 7 cannot read the file!


UPDATE:

The solution is packed record! Thanks!

0

There are 0 answers