How to get all Properties and Methods of a component automatic?

li_fang
li_fang used Ask the Experts™
on
hi,

I want to get all Properties and Methods of a component,
example:
The below is memo's properties,but i want to automatic get these name,how can i to do?? thanks!!!

...
Alignment
CanRedo
CanUndo
CaretPos
Handle
HMargin
Lines
Modified
ReadOnly
.....

Regards
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
{uses TypInfo}


Function GetObjProps(Obj:Tobject):Tstrings;
var
  PropInfo: PPropList;
  Count: Integer;
  I: Integer;
  Resultlist:Tstringlist;
begin
  Count := Abs(Longint(PTypeData(Obj.ClassInfo).PropCount));
  GetMem(PropInfo, Count * SizeOf(PPropInfo));
  GetPropInfoS(Obj.ClassInfo, PropInfo);
  Resultlist:=Tstringlist.create;
try
  try
    for I := 0 to Count-1 do
    begin
        if propinfo[i]=nil then break;
        Resultlist.Add(Propinfo[i].name);
    end;
   EXCEPT
      result:=resultlist;
  end;
 Finally
   result:=resultlist;
end;
freemem(propinfo);
end;




Good luck!!

Author

Commented:
DrDelphi,

hi,I am a beginner,I use your code ,but how to see the result,please give me some advices:).

or if you have time give me a example,thanks!uuhasoo@hotmail.com
something like this (to add on to DrDelphi's comment) in the Button's OnClick:

procedure TForm1.Button1OnClick(Sender: TObject);
var
  sResult: TStringList;
begin
  sResult := GetObjProps(Memo1);
  ShowMessage(sResult.Text);
end;

or perhaps you have a ListBox and you want to display everything inside the ListBox, replace ShowMessage above with

ListBox1.Items.Assign(sResult);

Have fun!



PS: Give the points to DrDelphi :)
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Author

Commented:
DragonSlayer,

thanks!!,I have funs!

DrDelphi,

Function GetObjProps(Obj:Tobject):Tstrings;
maybe is
Function GetObjProps(Obj:Tobject):Tstringlist;

thanks!!
TStrings works as well because TStringList inherits from TStrings :)

Author

Commented:
DragonSlayer,

tks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial