顯示具有 delphi 標籤的文章。 顯示所有文章
顯示具有 delphi 標籤的文章。 顯示所有文章

2014年1月12日 星期日

runtime move component

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月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 必須自己釋放

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;

2011年11月5日 星期六

TStringList 使用技巧 DelimitedText and StrictDelimiter

TStringList 繼承自TStrings,
一般常用 CommaText,DelimitedText 作多行輸入
用法

var List: TStringList;
....
//CommaText
List.CommaText := 'aa,bb,cc,dd';
...
aa
bb
cc
dd
 //DelimitedText
List.Delimiter := '/';
List.DelimitedText := 'aaa/bb b/ccc/ddd';
//bbb若有空格,那麼它的Count就是5而不是4
aaa
bb
b
ccc
ddd
//不是我們要的結果
//StrictDelimiter 用法
List.StrictDelimiter := True;
List.Delimiter := '/';
List.DelimitedText := 'aaa/bb b/ccc/ddd';
aaa
bb b
ccc
ddd