(page requirements)

Your own object inspector

We all like the "Object Inspector" for its ease of use and all the information it can provide. Wouldn't it be great to have your own possibly non-visual object inspector available at run time -- so you can find out which properties and methods a given object (or component) may have and what type these properties are? Try this:
uses TypInfo;

procedure ObjectInspector(
  Obj   : TObject;
  Items : TStrings );
  n        : integer;
  PropList : TPropList;
  n := 0;
    tkProperties + [ tkMethod ],
    @PropList );
  while( (Nil <> PropList[ n ]) and
         (n < High(PropList)) ) do
      PropList[ n ].Name + ': ' +
      PropList[ n ].PropType^.Name );
    Inc( n );
Listing #1 : Delphi code. Download objins (0.38 KB).
For example, let's say you want to get information about a listbox named "ListBox1" and store the information in the same "ListBox1"
ObjectInspector( ListBox1, ListBox1.Items );
Listing #2 : Delphi code. Download sample (0.17 KB).
Applicable Keywords : Delphi, Delphi 1.x, Delphi 2.x, Delphi 3.x, Functions
Copyright © 2009 Chami.com. All Rights Reserved. | Advertise | Created in HTML Kit editor