type Tcontrolacess= class(Tcontrol);
procedure TForm3.ControlCMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
Twincontrol(sender).Perform(WM_SYSCOMMAND, $F012, 0 );
end;
procedure TForm3.FormCreate(Sender: TObject);
var i:integer;
begin
for i:= 0 to componentcount -1 do
begin
if components[i] is TWincontrol then
Tcontrolacess(components[i]).onmousedown := ControlCMouseDown;
end;
end;
2014年1月12日 星期日
2014年1月11日 星期六
Delphi Create Owner Free 元件建立與釋放
Delphi 元件建立與釋放
var component1
begin
component1 := Tcomponent.Create(Owner);
Owner = nil --> xxx.Free; 自己釋放
Owner <> nil --> xxx 由Owner 釋放 ,不用自己釋放
....
end;
//必須是繼承自TComponent
// Create(Owner: TComponent) 才有Owner
//Tchildcpmponent = class(TComponent);
// TObject ,TPersistent
//Create; 無Owner 必須自己釋放
var component1
begin
component1 := Tcomponent.Create(Owner);
Owner = nil --> xxx.Free; 自己釋放
Owner <> nil --> xxx 由Owner 釋放 ,不用自己釋放
....
end;
//必須是繼承自TComponent
// Create(Owner: TComponent) 才有Owner
//Tchildcpmponent = class(TComponent);
// TObject ,TPersistent
//Create; 無Owner 必須自己釋放
Delphi Change Owner 變更可視元件(TWinControl)擁有者
//變更可視元件(TWinControl)擁有者
procedure ChangeOwner(Control: array of TComponent;
newOwner: TWinControl);
var
i: integer;
begin
for i := low(Control) to high(Control) do
begin
newOwner.InsertComponent(Control[i]);
if Control[i] is TWinControl then
TWinControl(Control[i]).Parent := newOwner;
end;
end;
//Example
procedure TForm3.Button3Click(Sender: TObject);
begin
ChangeOwner([cxGrid1, cxGrid1DBTableView1, cxGrid1Level1,
cxGrid1DBTableView1Column1, cxGrid1DBTableView1Column2,
cxGrid1DBTableView1Column3, cxGrid1DBTableView1Column4], Panel1);
end;
procedure ChangeOwner(Control: array of TComponent;
newOwner: TWinControl);
var
i: integer;
begin
for i := low(Control) to high(Control) do
begin
newOwner.InsertComponent(Control[i]);
if Control[i] is TWinControl then
TWinControl(Control[i]).Parent := newOwner;
end;
end;
//Example
procedure TForm3.Button3Click(Sender: TObject);
begin
ChangeOwner([cxGrid1, cxGrid1DBTableView1, cxGrid1Level1,
cxGrid1DBTableView1Column1, cxGrid1DBTableView1Column2,
cxGrid1DBTableView1Column3, cxGrid1DBTableView1Column4], Panel1);
end;
訂閱:
文章 (Atom)