home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / misc / objects / enuminfo / main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-21  |  2.1 KB  |  99 lines

  1. unit Main;
  2.  
  3. { Program copyright (c) 1995 by Charles Calvert }
  4. { Project Name: ENUMINFO }
  5.  
  6. { This unit shows how to use some
  7.   of the calls from TypInfo. The
  8.   Button2 call shown below works,
  9.   Button3 is broken.
  10.  
  11.   The key point here is that you can discover
  12.   type information about Published properties
  13.   at run time.  }
  14.  
  15. interface
  16.  
  17. uses
  18.   SysUtils, WinTypes, WinProcs,
  19.   Messages, Classes, Graphics,
  20.   Controls, Forms, Dialogs,
  21.   ExtCtrls, StdCtrls;
  22.  
  23. type
  24.   TForm1 = class(TForm)
  25.     ComboBox1: TComboBox;
  26.     Edit1: TEdit;
  27.     ListBox1: TListBox;
  28.     CurType: TButton;
  29.     ListEm: TButton;
  30.     procedure Button2Click(Sender: TObject);
  31.     procedure Button3Click(Sender: TObject);
  32.     procedure FormCreate(Sender: TObject);
  33.   private
  34.     { Private declarations }
  35.   public
  36.     { Public declarations }
  37.   end;
  38.  
  39. var
  40.   Form1: TForm1;
  41.  
  42. implementation
  43.  
  44. uses
  45.   TypInfo;
  46.  
  47. {$R *.DFM}
  48.  
  49. procedure TForm1.Button2Click(Sender: TObject);
  50. var
  51.   P : PPropInfo;
  52.   Name: String;
  53.   i: Integer;
  54. begin
  55.   P := GetPropInfo(ListBox1.ClassInfo, ComboBox1.Items.Strings[ComboBox1.ItemIndex]);
  56.   i := GetOrdProp(ListBox1, P);
  57.   Edit1.Text := GetEnumName(P^.PropType, i)^;  { pstring }
  58. end;
  59.  
  60. { Study CLASSES.PAS, DSGNINTF.PAS and TYPINFO
  61.   in the BROWSER if you want to try to get
  62.   this one working correctly. }
  63. procedure TForm1.Button3Click(Sender: TObject);
  64. var
  65.   SPtr: PString;
  66.   P: PPropInfo;
  67.   i, LNum, HNum: Integer;
  68. begin
  69.   ListBox1.Clear;
  70.   case ComboBox1.ItemIndex of
  71.     0: begin
  72.       LNum := Ord(Low(TBorderStyle));
  73.       HNum := Ord(High(TBorderStyle));
  74.     end;
  75.     1: begin
  76.       LNum := Ord(Low(TDragMode));
  77.       HNum := Ord(High(TDragMode));
  78.     end;
  79.     2: begin
  80.       LNum := Ord(Low(TListBoxStyle));
  81.       HNum := Ord(High(TListBoxStyle));
  82.     end;
  83.   end;
  84.  
  85.   P := GetPropInfo(ListBox1.ClassInfo, ComboBox1.Items.Strings[ComboBox1.ItemIndex]);
  86.   for i := LNum to HNum do begin
  87.     SPtr := GetEnumName(P^.PropType, i);
  88.     if SPtr <> nil then
  89.     ListBox1.Items.Add(SPtr^);
  90.   end;
  91. end;
  92.  
  93. procedure TForm1.FormCreate(Sender: TObject);
  94. begin
  95.   ComboBox1.ItemIndex := 0;
  96. end;
  97.  
  98. end.
  99.