Delphi 동적 생성 하위 창 예

763 단어 delphi
Delphi 동적 생성 하위 창 예
procedure TForm1.mlskntlbr2ItemDown(Sender: TObject; const ItemIndex: Integer);
begin
  case ItemIndex of
    0:
      ShowSubForm(Form2, TForm2);
    1:
      ShowSubForm(Form3, TForm3);
    2:
      ; //    
    3:
      ShowSubForm(Form4, TForm4);
    4:
      ;
    5:
      ;
    6:
      ;
    7:
      ;
  end;
end;

procedure TForm1.ShowSubForm(var Ref; AFormClass: TFormClass);
var
  Instance: TForm;
begin
  if not Assigned(TForm(Ref)) then
  begin
    Instance := TForm(AFormClass.NewInstance);
    TForm(Ref) := Instance;
    Instance.Create(Self);
    Instance.Parent := pnl2;
    Instance.Align := alClient;
    Instance.BorderStyle := bsNone;
  end
  else
    Instance := TForm(Ref);
  Instance.Show;
end;

좋은 웹페이지 즐겨찾기