Delphi 窗體建立過程

2022-02-18 05:39:41 字數 1947 閱讀 9772

來自大富翁.

1、tcustomform.create

在 tcustomform.create 中呼叫 tcustomform.createnew;

2、tcustomform.createnew;

呼叫 fcanvas := tcontrolcanvas.create;

觸發 tcontrolcanvas.create;

觸發 tcontrolcanvas.createhandle;

3、tcontrolcanvas.createhandle;

呼叫 fcontrol.getdevicecontext(fwindowhandle);

即 twincontrol.getdevicecontext(fwindowhandle);

4、twincontrol.getdevicecontext(fwindowhandle);

呼叫 twincontrol.getdc(handle);

此處說明一下:

對 twincontrol 的 handle 屬性的讀取會觸發 twincontrol.gethandle;

可以察看 property handle; 的宣告。

5、第四步中對 handle 進行讀取,觸發下述序列:(twincontrol)

handle->gethandle->handleneeded

6、twincontrol.handleneeded 檢查 fhandle 的值:

if fhandle = 0 then

begin

if parent <> nil then parent.handleneeded;

createhandle; // 呼叫 createhandle;

end;

7、twincontrol.createhandle

呼叫 createwnd;

if fhandle = 0 then // 此時 fhandle 仍然為零

begin

createwnd;

...end;

8、twincontrol.createwnd

呼叫 createparams(params);

// 讓使用者有機會加入新的特徵引數

createparams(params);

with params do

begin

...// 標準的 api 使用,註冊視窗類,createwindowex ...

if windows.registerclass(windowclass) = 0 then raiselastwin32error;

...createwindowhandle(params);

...end;

9、createwindowhandle(params);

fhandle := createwindowex(exstyle, winclassname, caption, style,

x, y, width, height, wndparent, 0, windowclass.hinstance, param);

完成真正的視窗建立,並賦予 fhandle 視窗控制代碼。

10、回到第一步

createnew 之後呼叫 docreate

trycreatenew(aowner);

...if oldcreateorder then docreate;

finally

...end;

11、docreate

呼叫使用者的 oncreate 事件:

if assigned(foncreate) then

tryfoncreate(self); // 呼叫 oncreate;

except

end;

if fsvisible in fformstate then visible := true;

我們oncreate事件最後才觸發的.

DELPHI動態建立窗體

第一種方式 procedure tform1.btn1click sender tobject begin try showmodal finally free end end 第二種方式 procedure tform1.btn2click sender tobject begin if not ...

delphi 窗體的建立和釋放

delphi中的窗體分為模式窗體和無模式窗體。二者的區別在於,使用者可以在無模式窗體和其他窗體之間切換。這樣,使用者就可以同時工作於乙個應用程式的幾個部分。delphi中窗體的初始化有兩種情況,動態建立,和自動建立。通過show顯示乙個無模式窗體,showmodal顯示乙個模式窗體。窗體有建立對應的...

delphi 窗體的建立和釋放

delphi中的窗體分為模式窗體和無模式窗體。二者的區別在於,使用者可以在無模式窗體和其他窗體之間切換。這樣,使用者就可以同時工作於乙個應用程式的幾個部分。delphi中窗體的初始化有兩種情況,動態建立,和自動建立。通過show顯示乙個無模式窗體,showmodal顯示乙個模式窗體。窗體有建立對應的...