Re: delphi component properties

Posted by Youri on August 06, 2008

In Reply to Component Properties posted by Hanieh Behzadian on July 17, 2008

: Hi
: I want to know that is there any component or command that gives me the list of properties of the component like table or text box, for example I want to have the list of properties of text box to change the caption of it or other properties. If I select the component like text box with one function or Extra things I can see the list of properties of that component.
: tnxs for your help in advance
: Hanieh

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);
PropCount, Size, I: Integer;
PropList: PPropList;
PropInfo: PPropInfo;
PropValue: string;
PropCount := GetPropList(Comp.ClassInfo, tkAny, nil);
Size := PropCount * SizeOf(Pointer);
GetMem(PropList, Size);
PropCount := GetPropList(Comp.ClassInfo, tkAny, PropList);
for I := 0 to PropCount - 1 do
PropInfo := PropList^[I];
PropValue := VarToStr(GetPropValue(Comp, PropInfo^.Name));
Strings.Add(PropInfo^.Name + ': ' + PropInfo^.PropType^.Name +
': ' + PropValue);

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);
CompPropsToList(Edit1, ListBox1.Items);

Success! Let me know if it works please!

Related articles


Follow Ups