Delphi类引用示例
Posted fkdelphi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Delphi类引用示例相关的知识,希望对你有一定的参考价值。
相关资料:
https://jingyan.baidu.com/article/bad08e1e2ec23b09c9512148.html
实例代码:
1 unit Unit1; 2 3 interface 4 5 uses 6 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 7 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls; 8 9 type 10 TControlClass = class of TControl; 11 12 TForm1 = class(TForm) 13 RadioGroup1: TRadioGroup; 14 procedure FormCreate(Sender: TObject); 15 procedure RadioGroup1Click(Sender: TObject); 16 procedure FormMouseDown(Sender: TObject; Button: TMouseButton; 17 Shift: TShiftState; X, Y: Integer); 18 private 19 { Private declarations } 20 public 21 { Public declarations } 22 end; 23 24 var 25 Form1: TForm1; 26 27 implementation 28 29 {$R *.dfm} 30 var 31 CtlClassRef: TControlClass; 32 33 procedure TForm1.FormCreate(Sender: TObject); 34 begin 35 RadioGroup1.Width := 400; 36 RadioGroup1.Columns := 3; 37 RadioGroup1.Items.Add(‘Button‘); 38 RadioGroup1.Items.Add(‘Edit‘); 39 RadioGroup1.Items.Add(‘Checkbox‘); 40 RadioGroup1.ItemIndex := 0; 41 CtlClassRef := TButton; 42 end; 43 44 procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; 45 Shift: TShiftState; X, Y: Integer); 46 var 47 NewCtrl: TControl; 48 begin 49 NewCtrl := CtlClassRef.Create(Self); 50 NewCtrl.Name := CtlClassRef.ClassName + IntToStr(Self.ControlCount); 51 NewCtrl.Parent := Self; 52 NewCtrl.Left := X; 53 NewCtrl.Top := Y; 54 end; 55 56 procedure TForm1.RadioGroup1Click(Sender: TObject); 57 begin 58 case RadioGroup1.ItemIndex of 59 0: CtlClassRef := TButton; 60 1: CtlClassRef := TEdit; 61 2: CtlClassRef := TCheckBox; 62 end; 63 end; 64 65 end.
以上是关于Delphi类引用示例的主要内容,如果未能解决你的问题,请参考以下文章