Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-04

TStringList bug?

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Müller

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

Michael Van Canneyt
to Michael Müller
Michael Müller wrote 42 lines
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.