home *** CD-ROM | disk | FTP | other *** search
- unit Main;
-
- { Program copyright (c) 1995 by Charles Calvert }
- { Project Name: ENUMINFO }
-
- { This unit shows how to use some
- of the calls from TypInfo. The
- Button2 call shown below works,
- Button3 is broken.
-
- The key point here is that you can discover
- type information about Published properties
- at run time. }
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs,
- Messages, Classes, Graphics,
- Controls, Forms, Dialogs,
- ExtCtrls, StdCtrls;
-
- type
- TForm1 = class(TForm)
- ComboBox1: TComboBox;
- Edit1: TEdit;
- ListBox1: TListBox;
- CurType: TButton;
- ListEm: TButton;
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- uses
- TypInfo;
-
- {$R *.DFM}
-
- procedure TForm1.Button2Click(Sender: TObject);
- var
- P : PPropInfo;
- Name: String;
- i: Integer;
- begin
- P := GetPropInfo(ListBox1.ClassInfo, ComboBox1.Items.Strings[ComboBox1.ItemIndex]);
- i := GetOrdProp(ListBox1, P);
- Edit1.Text := GetEnumName(P^.PropType, i)^; { pstring }
- end;
-
- { Study CLASSES.PAS, DSGNINTF.PAS and TYPINFO
- in the BROWSER if you want to try to get
- this one working correctly. }
- procedure TForm1.Button3Click(Sender: TObject);
- var
- SPtr: PString;
- P: PPropInfo;
- i, LNum, HNum: Integer;
- begin
- ListBox1.Clear;
- case ComboBox1.ItemIndex of
- 0: begin
- LNum := Ord(Low(TBorderStyle));
- HNum := Ord(High(TBorderStyle));
- end;
- 1: begin
- LNum := Ord(Low(TDragMode));
- HNum := Ord(High(TDragMode));
- end;
- 2: begin
- LNum := Ord(Low(TListBoxStyle));
- HNum := Ord(High(TListBoxStyle));
- end;
- end;
-
- P := GetPropInfo(ListBox1.ClassInfo, ComboBox1.Items.Strings[ComboBox1.ItemIndex]);
- for i := LNum to HNum do begin
- SPtr := GetEnumName(P^.PropType, i);
- if SPtr <> nil then
- ListBox1.Items.Add(SPtr^);
- end;
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- ComboBox1.ItemIndex := 0;
- end;
-
- end.
-