Delphi主從窗體調用的實現


用delphi來制作一些客戶端小工具還是比較方便的。我們通常在做一個軟件的時候,首先要考慮的是窗體布局和窗體之間的互相調用問題。下面就是主從窗體的實施步驟:
第一步,打開【Delphi7】,新建一個Delphi工程,新建一個空白窗體命名為:【MainActivedForm】。
然后重寫構造函數:
代碼如下:
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TMainActivedForm = class(TForm)

  private
      FAsChild: Boolean;
    { Private declarations }
  public
    { Public declarations }
    FTempParent: TWinControl;
    constructor Create(AOwner: TComponent); overload; override;
    constructor Create(AOwner: TComponent; AParent: TWinControl); reintroduce; overload;
  end;

var
  MainActivedForm: TMainActivedForm;

implementation

{$R *.dfm}
 constructor TMainActivedForm.Create(AOwner: TComponent);
begin
  FAsChild := False;
  inherited Create(AOwner);
end;

constructor TMainActivedForm.Create(AOwner: TComponent; AParent: TWinControl);
begin
  self.BorderStyle := bsnone;
  self.Align := alclient;

  FAsChild := True;
  FTempParent := aParent;
 
  inherited Create(AOwner);
  setparent(AParent);
end;
end.

新建一個子窗體,窗體的名稱是【JXConfigForm】,窗體的基類設置為  TJXConfigForm = class(TMainActivedForm)。

然后新建主窗體,並添加【MainActivedForm】的單元引用。

在主窗體上拖一個TbsSkinPanel控件,命名為【bsSkinPanel2】。

在主窗體中聲明一個全局變量【aPnParent:TbsSkinPanel;】。

創建主窗體的FormCreate事件,事件代碼如下:
procedure TMainForm.FormCreate(Sender: TObject);
begin
aPnParent := bsSkinPanel2;
 perform(WM_SIZE,SIZE_MAXIMIZED,0);
end;

在主窗體上放置一個按鈕【bsSkinSpeedButton5】,添加按鈕事件函數:
procedure TMainForm.bsSkinSpeedButton5Click(Sender: TObject);
begin
//調出頁面
  if MainActivedForm <> nil then
    begin
      MainActivedForm.Free;
    end;
  MainActivedForm := TJXConfigForm.Create(application, apnParent);
  MainActivedForm.show;
end;

這樣,主從窗體的調用就完成了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM