Problems porting Delphi 3 to Delphi 2010

I have a source of an older project and I have to change little things, but I have big problems due to the fact that there was only delphi 2010 for this.

Record is defined:

bbil = record
  path : string;
  pos: byte;
  nr: Word;
end;

later this definition is used to read from a file:

b_bil: file of bbil;
pbbil: ^bbil;
l_bil : tlist;

while not(eof(b_bil)) do
  begin
    new(pbbil);
    read(b_bil, pbbil^);
    l_bil.add(pbbil);
  end

The main problem is that the compiler does not accept the type "string" in the record, because it wants to "finalize". So I tried changing the "string" to "string [255]" or "shortstring". This application is reading a file, but with the wrong content.

My question is how to convert the old type "string" with which the files were written to the "new" types in Delphi 2010.

, . "{$ H-}". char , , , char - lengthbyte + 255chars , shortstring .

+5
3

! , , . , Delphi, string ShortString.

, , . , - , , , , , read , - ShortString. , , , , , .

@LU RD , Delphi, packed. , Delphi, . , , .

pos nr .

bbil = record
  path : string;
  pos: byte;
  _pad: byte;
  nr: Word;
end;

, $ALIGN {$ALIGN ON}, , , .

, ANSI, . Delphi, . , .

+5

:

"string" < > "string [255]" < > "shortstring" < > AnsiString

DOS/Turbo Pascal, "" 255 . , , 0 255.

Delphi.

" ShortString" - DOS/Pascal.

"LongString" ( Borland Delphi 2006, ). Delphi 3.. Delphi 2009, LongStrings 8- . Delphi 3.. Delphi 2009, "LongStrings" "AnsiStrings".

Delphi (Delphi 2009 , Delphi XE2) Unicode "WideString". WideStrings, AnsiStrings, "" .

:

http://delphi.about.com/od/beginners/l/aa071800a.htm

PS: "sizeof (bbil)" " Packed " .

+2

, - , , , delphi 3 . :

bbil = record
  path : string;
  pos: byte;
  nr: Word;
end;

path (all between 1 and 256 - one byte for length, rest for data), pos (1 byte), nr (2 bytes), which makes your record data size vary from 1 + 1 + 2 = 4 bytes to 256 + 1 + 2 = 259 bytes. In this case, you can get garbage from the file anyway, since your program cannot now determine how many bytes to read before actually reading the data. I suggest you correct your entry so that the string has a fixed size, for example:

path : ShortString[255];

Then you can write and read both in delphi 3 and in 2010.

0
source

All Articles