[fpc-pascal] GetPropValue and Unknown property
Leonardo M. Ramé
martinrame at yahoo.com
Tue Jun 23 15:26:20 CEST 2009
Yes, Mattias is right, I copied-pasted-removed some stuff from one of my programs and leaved out the FreeMem part.
This is a modified version:
procedure GetClassProperties(AClass: TClass);
(* get published properties into a list *)
var
PropList: ppropList;
ClassTypeInfo: PTypeInfo;
I: Integer;
lProps: Integer;
begin
(* Get properties and a pointer to class *)
lProps := GetTypeData(AClass.ClassInfo)^.PropCount;
if lProps <> 0 then
begin
(* Properties list to be analyzed *)
GetPropList(AClass.ClassInfo, PropList);
for I := 0 to lProps -1 do
writeln(PropList[I]^.name);
(* Free memory allocated for PropList *)
FreeMem(PropList);
end;
end;
Leonardo M. Ramé
http://leonardorame.blogspot.com
----- Original Message ----
From: Mattias Gärtner <nc-gaertnma at netcologne.de>
To: fpc-pascal at lists.freepascal.org
Sent: Tuesday, June 23, 2009 10:20:10 AM
Subject: Re: [fpc-pascal] GetPropValue and Unknown property
Zitat von "Leonardo M. Ramé" <martinrame at yahoo.com>:
>
>
>
> How are you filling the ASortProps array? if it is by hand, you have to take care of Case Sensitivity of property names.
>
> You can use this function to know the published properties of any class. Try it inside your DoCompareProps, passing TFTPListRec(AItem1).ClassType as param, if AItem1 is an instance it should list all its properties:
>
> procedure GetClassProperties(AClass: TClass);
> (* get published properties into a list *)
> var
> PropList: ppropList;
> ClassTypeInfo: PTypeInfo;
> I: Integer;
> lProps: Integer;
> begin
> (* Get properties and a pointer to class *)
> lProps := GetTypeData(AClass.ClassInfo)^.PropCount;
> if lProps <> 0 then
> begin
> (* Properties list to be analyzed *)
> for I := 0 to GetPropList(AClass.ClassInfo, PropList) -1 do
> writeln(PropList[I]^.name);
> end;
> end;
This will create a mem leak. Call GetPropList only once and FreeMem the PropList at the end.
Mattias
--
Powered by NetMail
_______________________________________________
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