[fpc-pascal] TStringList bug?

Michael Müller mueller_michael at alice-dsl.net
Wed Apr 7 23:28:14 CEST 2010


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.

From German Delphi 2006 and 2009 Help:
Bei Strings, die das NameValueSeparator-Zeichen enthalten, handelt es sich um Namens-/Wertepaare. Das Standardzeichen für NameValueSeparator ist das Gleichheitszeichen (=).
Short translation: Default value for NameValueSeparator is =.

Why are the values not initialized in TStringList.Create?

Do you agree that it is a bug? Shall I add this to the bug tracker?

I tested it with Delphi 2006 & 2009 and Free Pascal V2.4.0.

Regards

Michael


More information about the fpc-pascal mailing list