unit ListForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Panel1: TPanel;
ComboBox1: TComboBox;
procedure ComboBox1Change(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
SelPropName: string;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
TypInfo;
procedure TForm1.ComboBox1Change(Sender: TObject);
var
PropInfo: PPropInfo;
ptd: PTypeData;
I: Integer;
PropValue: Integer;
begin
// set the name of the current property
if ComboBox1.Text <> '' then
SelPropName := ComboBox1.Text;
// add to the listbox the values
// of the enumerated type
ListBox1.Items.Clear;
PropInfo := GetPropInfo (
ClassInfo, SelPropName);
// Note: ClassInfo refers to the form, self
ptd := GetTypeData (PropInfo.PropType^);
// list the values
for I := ptd.MinValue to ptd.MaxValue do
ListBox1.Items.Add (GetEnumName (
PropInfo.PropType^, I));
// select the current value
PropValue := GetOrdProp (self, PropInfo);
ListBox1.ItemIndex := ptd.MinValue + PropValue;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
var
PropInfo: PPropInfo;
ptd: PTypeData;
itemIndex: Integer;
begin
if SelPropName <> '' then
begin
PropInfo := GetPropInfo (
ClassInfo, SelPropName);
// Note: ClassInfo refers to the form, self
ptd := GetTypeData(PropInfo.PropType^);
// save combo box index
itemIndex := ComboBox1.ItemIndex;
// select the current value
SetOrdProp (self, PropInfo,
ListBox1.ItemIndex - ptd.MinValue);
// restore combo box index
ComboBox1.OnChange := nil;
ComboBox1.ItemIndex := itemIndex;
ComboBox1.OnChange := ComboBox1Change;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
pProps: PPropList;
nTotProps, nProps, I: Integer;
begin
// set the initial value
SelPropName := '';
// get the total number of properties
nTotProps := GetTypeData(ClassInfo).PropCount;
// allocate the required memory
GetMem (pProps, sizeof (PPropInfo) * nTotProps);
// protect the memory allocation
try
// fill the pProps with a filtered list
nProps := GetPropList (ClassInfo,
[tkEnumeration], pProps);
// fill the combo box
for I := 0 to nProps - 1 do
ComboBox1.Items.Add (pProps[I].Name);
finally
// free the allocated memmory
FreeMem (pProps, sizeof (PPropInfo) * nTotProps);
end;
end;
end.
|