Component Properties

Question

I want to know if there is any component or command that gives me the list of properties of a component, like table or text box, for example I want to have the list of properties of a text box to change the caption of it or other properties. If I select the component like text box I can see the list of properties of that component.

Answer by Youri

1. Put an edit-box called Edit1 on your Delphi form. We will show its properties in a listbox.

2. Add the unit TYPINFO to the USES clause of the form.

3. Add following procedure at the beginning of the implementation part of the form:

procedure CompPropsToList(Comp: TComponent; Strings: TStrings);
var
   PropCount, Size, I: Integer;
   PropList: PPropList;
PropInfo: PPropInfo;
   PropValue: string;
begin
   PropCount := GetPropList(Comp.ClassInfo, tkAny, nil);
   Size := PropCount * SizeOf(Pointer);
   GetMem(PropList, Size);
   try
     PropCount := GetPropList(Comp.ClassInfo, tkAny, PropList);
     for I := 0 to PropCount - 1 do
     begin
       PropInfo := PropList^[I];
       PropValue := VarToStr(GetPropValue(Comp, PropInfo^.Name));
       Strings.Add(PropInfo^.Name + ': ' + PropInfo^.PropType^.Name +
        ': ' + PropValue);
     end;
   finally
     FreeMem(PropList);
   end;
end;

4. In order to test it:
4.1. Put a Delphi listbox called ListBox1 on the form.
4.2. Put a Delphi button called Button1 on the form.
4.3. Add a button-click procedure:

procedure TForm1.Button1Click(Sender: TObject);
begin
   CompPropsToList(Edit1, ListBox1.Items);
end;

Success!
Youri