Sign in Join

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

Mailing lists / fpc-devel / 2005-12

GetPropList and order of properties returned

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

What are the rules regarding the order of a unsorted list of published properties using the GetPropList method, when inheritance has been used. I had unit tests from a Delphi app that detected this difference.

Below is the results from Delphi and FPC. The first set has been compiled with Delphi 7 and the second set of results from a exectable compiled with FPC 2.0.1

As you can see, Delphi lists the properties from the root object out, and FPC lists them from the outer object in. Which one is doing it correctly, or is there no set rule?

[Delphi 7]
C:\Programming\Tests\GetPropList\D7_2>Project1.exe
Total property Count: 4
Property 1: Caption
Property 2: IntProp
Property 3: StrProp
Property 4: AnotherStrProp
---------------
[FPC 2.0.1]
C:\Programming\Tests\GetPropList\D7_2>Project1.exe
Total property Count: 4
Property 1: AnotherStrProp
Property 2: IntProp
Property 3: StrProp
Property 4: Caption
---------------

Here is the full source of the application
-------------------------------------------------
program project1;

{$IFDEF FPC}
   {$mode objfpc}{$H+}
{$ELSE}
   {$APPTYPE CONSOLE}
{$ENDIF}

uses
SysUtils,
TypInfo,

   Classes;
type
   TAObject = class(TPersistent)
   private
     FCaption: string;
   published
     property Caption: string read FCaption write FCaption;
   end;
   TBObject = class(TAObject)
   private
     FIntProp: Integer;
     FStrProp: String;
   published
     property IntProp: Integer read FIntProp write FIntProp;
     property StrProp: String read FStrProp write FStrProp;
   end;
   TCObject = class(TBObject)
   private
      FAStrProp: String;
   published
     property AnotherStrProp: String read FAStrProp write FAStrProp;
   end;
procedure ShowProperties;
var
   Obj: TCObject;
   i: Longint;
   lPropFilter: TTypeKinds;
   lCount: Longint;
   lSize: Integer;
   lList: PPropList;
begin
   Obj := TCObject.Create;
   lPropFilter := [tkInteger, tkLString {$ifdef FPC}, tkAString{$endif}];
   lCount  := GetPropList(Obj.ClassInfo, lPropFilter, nil, false);
   lSize   := lCount * SizeOf(Pointer);
   GetMem(lList, lSize);
   Writeln('Total property Count: ' + IntToStr(lCount));
   lCount := GetPropList(Obj.ClassInfo, lPropFilter, lList, false);
   for i := 0 to lCount-1 do
   begin
     Writeln('Property '+IntToStr(i+1)+': ' + lList^[i]^.Name);
   end;
   FreeMem(lList);
   Obj.Free;
   Writeln('---------------');
end;
begin
   ShowProperties;
end.

-------------------------------------------------

I'm running FPC 2.0.1 that came with Lazarus 0.9.10 on Windows 2000.

Regards,
- Graeme -

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 13 lines
Hi, What are the rules regarding the order of a unsorted list of published properties using the GetPropList method, when inheritance has been used. I had unit tests from a Delphi app that detected this difference. Below is the results from Delphi and FPC. The first set has been compiled with Delphi 7 and the second set of results from a exectable compiled with FPC 2.0.1 As you can see, Delphi lists the properties from the root object out, and FPC lists them from the outer object in. Which one is doing it correctly, or is there no set rule?

There is no set rule. If I remember correctly, the order changed in Delphi, because I seem to remember that it was as FPC (D5 or so).

Michael.

Reply by email

Peter Vreman
to Michael Van Canneyt
Show quoted text 24 lines
On Tue, 20 Dec 2005, Graeme Geldenhuys wrote: > Hi, > > What are the rules regarding the order of a unsorted list of published > properties using the GetPropList method, when inheritance has been used. > I had unit tests from a Delphi app that detected this difference. > > Below is the results from Delphi and FPC. The first set has been > compiled > with Delphi 7 and the second set of results from a exectable compiled > with > FPC 2.0.1 > > As you can see, Delphi lists the properties from the root object out, > and FPC > lists them from the outer object in. Which one is doing it correctly, > or is > there no set rule? There is no set rule. If I remember correctly, the order changed in Delphi, because I seem to remember that it was as FPC (D5 or so).

Fixed. The order is defined by the NameIndex

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: There is no set rule. If I remember correctly, the order changed in Delphi, because I…
Michael Van Canneyt wrote
There is no set rule. If I remember correctly, the order changed in Delphi, because I seem to remember that it was as FPC (D5 or so).

Might have been before D5 then, I don't know. The application/framework I am porting runs the same set of unit tests under D5-D7 and D2005 (win32) and the order of the properties are definitely the same.

Regards,
- Graeme -

Reply by email

Martin Schreiber
to Graeme Geldenhuys: What are the rules regarding the order of a unsorted list of published properties using…

Another incompatibility:
FPC reports multiple published properties multiple, Delphi /Kylix ones.

FPC 2.0.2:
Total property Count: 3
Property 1: IntProp
Property 2: IntProp
Property 3: IntProp
---------------

Kylix 3:
Total property Count: 1
Property 1: IntProp
---------------

program project1;
{$IFDEF FPC}
   {$mode objfpc}{$H+}
{$ELSE}
   {$APPTYPE CONSOLE}
{$ENDIF}

uses
SysUtils,
TypInfo,

   Classes;
type
   TAObject = class(TPersistent)
   private
     FIntProp: Integer;
   published
     property IntProp: Integer read FIntProp write FIntProp;
   end;
   TBObject = class(TAObject)
   published
     property IntProp default 1;
   end;
   TCObject = class(TBObject)
   published
     property IntProp default 2;
   end;
procedure ShowProperties;
var
   Obj: TCObject;
   i: Longint;
   lPropFilter: TTypeKinds;
   lCount: Longint;
   lSize: Integer;
   lList: PPropList;
begin
   Obj := TCObject.Create;
   lPropFilter := [tkInteger, tkLString {$ifdef FPC}, tkAString{$endif}];
   lCount  := GetPropList(Obj.ClassInfo, lPropFilter, nil, false);
   lSize   := lCount * SizeOf(Pointer);
   GetMem(lList, lSize);
   Writeln('Total property Count: ' + IntToStr(lCount));
   lCount := GetPropList(Obj.ClassInfo, lPropFilter, lList, false);
   for i := 0 to lCount-1 do
   begin
     Writeln('Property '+IntToStr(i+1)+': ' + lList^[i]^.Name);
   end;
   FreeMem(lList);
   Obj.Free;
   Writeln('---------------');
end;
begin
   ShowProperties;
end.

Reply by email

Peter Vreman
to Martin Schreiber
Show quoted text 14 lines
Another incompatibility: FPC reports multiple published properties multiple, Delphi /Kylix ones. FPC 2.0.2: Total property Count: 3 Property 1: IntProp Property 2: IntProp Property 3: IntProp --------------- Kylix 3: Total property Count: 1 Property 1: IntProp ---------------

Fixed, thanks for the test.

Reply by email