[fpc-pascal]Strings vs. Ansistrings
Michael Van Canneyt
michael.vancanneyt at wisa.be
Tue Sep 19 12:27:29 CEST 2000
On Mon, 18 Sep 2000, Carlo Kok wrote:
> I don't know if it is the same as in delphi, but in delphi, you can not save
> Ansistrings directly to a file, because ansistring is a pointer.
This is also true for Free Pascal.
Michael.
> that's why
> you receive garbage. You can save an ansi string like this:
> var
> l: Longint
> begin
> L := Length(MyAnsiString);
> BlockWrite(f, l, sizeof(L));
> BlockWrite(f, MyAnsiString[1], L);
> end;
> and read it like this:
> var
> l: Longint;
> begin
> BlockRead(f, L, sizeof(L));
> SetLEngth(MyAnsiString, l);
> BlockRead(f, MyAnsiString[1], L);
> end;l
>
>
>
> Greetings
> Carlo Kok (born: 16-08-1984)
> ICQ: 73059433
> Volendam; The Netherlands
>
> ----- Original Message -----
> From: <James_Wilson at i2.com>
> To: <fpc-pascal at lists.freepascal.org>
> Sent: Monday, September 18, 2000 9:18 PM
> Subject: [fpc-pascal]Strings vs. Ansistrings
>
>
> > For go32 and Win32 targets... are strings read/written differently when
> > compiling with {$H-} and {$H+}? I have a file viewer that uses an array of
> > ^string. When compiled with {$H-}, shortstrings, the strings are read from
> > the file and displayed on the screen perfectly. But, when I compile with
> > ($H+}, ansistrings, the strings are displayed as garbage characters
> > (without making any other changes to the code). According to the byte
> count
> > I calculate while reading the file both short and ansistrings are reading
> > the exact same amount of data, but the displayed characters are all
> garbled
> > only when using ansistrings.
> >
> > I can't find anything in the docs that seem to point to this problem. Any
> > help would be appreciated. Thanks.
> >
> > Jim
> >
> >
> > _______________________________________________
> > fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> > http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> >
>
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list