[fpc-pascal] TStringList bug?

Michael Van Canneyt michael at freepascal.org
Thu Apr 8 08:52:20 CEST 2010



On Wed, 7 Apr 2010, Michael Müller wrote:

> Hi,
>
> the following code behaves different between Delphi and Free Pascal:
>
> {$APPTYPE CONSOLE}
>
> {$IFDEF FPC}
> {$MODE delphi}
> {$ENDIF}
>
> uses
> Classes;
>
> type TFoo = class(TStringList)
> public
> constructor Create;
> end;
>
> constructor TFoo.Create;
> begin
> inherited Create;
>
> {$IFDEF FPC}
> // Is needed by Free Pascal to get some fields initialized that are initialized automatically by Delphi
> //  CheckSpecialChars;
> {$ENDIF}
> end;
>
> var
> Foo: TFoo;
> begin
> Foo := TFoo.Create;
> try
>   writeln('NameValueSeparator = |', Foo.NameValueSeparator, '|');
>   Foo.IndexOfName('Test');
>   writeln('NameValueSeparator = |', Foo.NameValueSeparator, '|');
> finally
>   Foo.Free;
> end;
> end.
>
> Without calling CheckSpecialChars (which doesn't exist in Delphi) manually in the constructor the default value of NameValueSeparator is in Free Pascal the space character until you call a method like IndexOfName that calls CheckSpecialChars at the beginning. After such a call NameValueSeparator changes to the expected default value (=). In Delphi it has the right value from the beginning.

I have added the call. Committed in rev. 15116.

Michael.


More information about the fpc-pascal mailing list