大牛帮看下这个程序 为什么没反应。
RT 我想要的效果是 通过在窗体上点击鼠标 创建焦点所在RadioButton指示的控件。也就是这个样子。
我写了个程序 打包如下 热心人帮看看。
12_19_ClassRef.rar
(178.09 KB)
顺便发下工程文件和源文件。
CRefRorm.pas
程序代码:
unit CRefForm; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type // Class reference type (redeclaration) TControlClass = class of TControl; TCRefForm1 = class(TForm) Panel1: TPanel; RbtnRadio: TRadioButton; RbtnButton: TRadioButton; RbtnEdit: TRadioButton; procedure RbtnEditClick(Sender: TObject); procedure RbtnButtonClick(Sender: TObject); procedure RbtnRadioClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); private { Private declarations } ClassRef: TControlClass; Counter: Integer; public { Public declarations } end; var CRefForm1: TCRefForm1; implementation {$R *.dfm} procedure TCRefForm1.RbtnButtonClick(Sender: TObject); begin ClassRef := TButton; end; procedure TCRefForm1.RbtnEditClick(Sender: TObject); begin ClassRef := TEdit; end; procedure TCRefForm1.RbtnRadioClick(Sender: TObject); begin ClassRef := TRadioButton; end; procedure TCRefForm1.FormCreate(Sender: TObject); begin ClassRef := TRadioButton; end; procedure TCRefForm1.FormMouseDown( Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); Var NewCtrl: TControl; CtrlName: string; begin // Create the Control NewCtrl := ClassRef.Create(Self); // hide it temporarily, to avoid flickering NewCtrl.Visible := False; // set parent and position NewCtrl.Parent := Self; NewCtrl.Left := X; NewCtrl.Top := Y; // compute the unique name (and caption) Inc(Counter); CtrlName := ClassRef.ClassName + IntToStr(Counter); Delete (CtrlName, 1, 1); NewCtrl.Name := CtrlName; NewCtrl.Visible := True; end; end.ClassReference.bdsproj
程序代码:
program ClassReference; uses Forms, CRefForm in 'CRefForm.pas' {CRefForm1}; {$R *.res} begin Application.Initialize; Application.CreateForm(TCRefForm1, CRefForm1); Application.Run; end.
检查了多次 那里有问题 为什么我点击鼠标没反应?
百分求解。。。