[fpc-pascal] Typed file problem.
Michalis Kamburelis
michalis at camelot.homedns.org
Wed Jun 22 23:55:21 CEST 2005
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
More information about the fpc-pascal
mailing list