关于TForm窗体创建过程
近日在看vcl源码时,一直很好奇创体是啥时候创建出来的,查网上一篇文单,对其中涉及到窗体创建的过程,觉得有点不对的地方.
我们在程序当中建TForm窗体,一般这样写
aForm:=TForm.Create;
aForm.show;
网上分析是这样的:
1 、TCustomForm.Create
在 TCustomForm.Create 中调用 TCustomForm.CreateNew;
2、TCustomForm.CreateNew;
调用 FCanvas := TControlCanvas.Create;
触发 TControlCanvas.Create;
触发 TControlCanvas.CreateHandle;
.....
本人觉得写的这一步写得有问题,TControlCcanvas.create不会触发CreateHandle,你给他赋值一个Control也不会触发
CreateHandle 只有在画图的时候才会触发,在RequiredState函数里面,TCanvas的每个画图函数,几乎都夹着这个函数;
事实上,窗体的建立在aForm.show的代码中;
procedure TCustomForm.Show;
begin
Visible := True;
BringToFront;
end;
visible:=true须要句柄
[解决办法]
TWinControl.CreateWindowHandle(('Form2', 114229248, 65536, 193, 114, 735, 399, 263160, nil, (8, $40622C, 0, 0, 4194304, 0, 65553, 0, nil, nil), ('T', 'F', 'o', 'r', 'm', '2', #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0)))
TCustomForm.CreateWindowHandle(('Form2', 114229248, 65536, 193, 114, 735, 399, 263160, nil, (8, $40622C, 0, 0, 4194304, 0, 65553, 0, nil, nil), ('T', 'F', 'o', 'r', 'm', '2', #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0, #0)))
TWinControl.CreateWnd
TScrollingWinControl.CreateWnd
TCustomForm.CreateWnd
TWinControl.CreateHandle
TWinControl.HandleNeeded
TWinControl.GetHandle
TWinControl.GetDeviceContext(0)
TControlCanvas.CreateHandle
TCanvas.RequiredState([csHandleValid..csFontValid])
TCanvas.TextExtent('0')
TCanvas.TextHeight('0')
TCustomForm.GetTextHeight
TCustomForm.ReadState($95565C)
TReader.ReadRootComponent($9550B0)
TStream.ReadComponent($9550B0)
InternalReadComponentRes('TForm2',4194304,$9550B0)
InitComponent(TForm2)
InitInheritedComponent($9550B0,TForm)
TCustomForm.Create(nil)