我想动态创建组件并可以删除掉它,但...
roger 2000-10-24 11:58:00 各位大虾,我想在run-time时创建不同的组件并可以用backspace键删掉它,我使用了类引用和对象方法指针,程序大概如下,但创建的组件的OnkeyPress不能响应键盘,不知为什么?请大家指教。
type
TControlClass=class of TControl;
type
TForm1 = class(TForm)
........
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
ClassRef:TControlClass;
Counter:Integer;
ToDestroy:TControl;
........
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
MyName:String;
begin
if ClassRef<>nil then
if (Button=mbLeft) then
with ClassRef.Create(self) do//ClassRef可能是多种组件
begin
Visible:=False;
Parent:=self;
........
OnKeyPress:=GetKeyPress;//这句好象不起作用,不知为什么?
SetFocus;
Form1.Caption:=Format('Count Object:%d Components',[Counter]);
end;
end;
end;