[fpc-pascal] Typed file problem.

Inpromptu inpromptu at operamail.com
Thu Jun 23 00:36:47 CEST 2005


I've found the problem... !

if the record is 

Myrecord=record
         MyInteger:integer;
         Mystring:string;
         end;

compiled with c:\lazarus\pp\bin\i386-bin\ppc386 without any other parameter, sizeof(Myrecord.Myinteger) shows 2.

compiled inside Lazarus sizeof(Myrecord.Myinteger) shows  4 !

Because of this, Mystring is readed wrong from the file.


I think this is a trivial problem, but I don't know how to force MyInteger to be 2 bytes long inside and outside Lazarus... Or 4 bytes long ?


Thanks !






> 
> Inpromptu wrote:
> [...]
> >
> >
> >> Are you sure that exactly the same definition of TSomeType is 
> >> used when you compile GUI and console version of your program ? 
> >> Maybe some structures are aligned differently when you compile 
> >> GUI and console version of your program ? Are you sure that the 
> >> unit where TSomeType type is declared is always compiled in the 
> >> same FPC $mode ? Maybe you use "string" inside your TSomeType 
> >> and sometimes it's understood as "ShortString" and sometimes as 
> >> "AnsiString" ?
> >>
> >
> >
> > This seems to be the problem. Is there any way to stop the 
> > compilation of the non-delphi part, to avoid string problem ? Is 
> > there anyway to force ShortStrings in the console app ?.
> >
> 
> You can always just write "ShortString" instead of writing 
> "string", then you know that you're for sure using ShortStrings. 
> Also, you can use compiler directive {$H-} to say that "string" 
> should mean "ShortString". {$H+} means that "string" is 
> "AnsiString". The default state of $H depends on FPC $mode that you 
> use.
> 
> Note that ShortString length is limited to 255 characters. Usually 
> you shouldn't use ShortString at all in new programs, unless you're 
> really sure that your data will always fit within these 255 
> characters.
> 
> However, storing AnsiStrings in a file cannot be done using Pascal 
> typed files (because AnsiString is a special pointer, so you can't 
> simply read/write it to a file). So if it sounds like you don't 
> want to actually use ShortString, you may want to drop using typed 
> files.
> 
> Michalis
> 
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal


-- 
_______________________________________________
Surf the Web in a faster, safer and easier way:
Download Opera 8 at http://www.opera.com




More information about the fpc-pascal mailing list