萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> 編程語言綜合 >> Delphi 動態創建窗體,鎖定窗口賦值

Delphi 動態創建窗體,鎖定窗口賦值

  Var

  TempForm: array of TForm2;

  procedure TForm1.Button2Click(Sender: TObject);

  Var

  i:Integer;

  bNew:Boolean;

  begin

  bNew:=True;

  For i:=Low(TempForm) to High(TempForm) do

  begin

  IF TempForm[i].Caption=Trim(Edit1.Text) then

  begin

  TempForm[i].Show;

  bNew:=False;

  Exit;

  end;

  bNew:=True;

  end;

  IF bNew then

  begin

  SetLength(TempForm,Length(TempForm)+1); //給數據增加一個值

  TempForm[High(TempForm)]:=TForm2.Create(nil); //創建窗體

  TempForm[High(TempForm)].Caption:=Trim(Edit1.Text); //窗體Caption賦於值,以便鎖定

  Self.CheckListBox1.Items.Add(Trim(Edit1.Text));

  TempForm[High(TempForm)].Show; //數組的最高值便是當前所創建的窗體

  end;

  end;

  procedure TForm1.Button3Click(Sender: TObject);

  Var

  i:integer;

  bName:String;

  begin

  For I:=0 to CheckListBox1.Count-1 do

  begin

  if CheckListBox1.Selected[i] then

  bName:=CheckListBox1.Items.Strings[i];

  end;

  For I:=Low(TempForm) to high(TempForm) do

  begin

  if TempForm[i].Caption=bName then

  begin

  TempForm[i].Edit1.text:=Edit2.text;

  end;

  end;

  end;

copyright © 萬盛學電腦網 all rights reserved