Put a Panel1 and Button1 in the design period, and then set the Panel1.visible:=false
At this time execution:
procedure Tform1.button4click (sender:tobject); begin showmessage (IntToStr (Panel1. instancesize)); End;
Get 552, indicating that this Panel1 memory object already exists. Change its visible to true, or get 552. Indicates that the memory object already exists, and the size is no different (its contents may vary).
Again, change the visible to false to test the following code:
procedure Tform1.button1click (sender:tobject); begin if (Panel1. handle=0then showmessage ('no Handle') Else showmessage ('handled'); End;
The result always shows that there is already a handle. What is this for? Obviously there is no display control, it should be executed handleneeded
proceduretwincontrol.handleneeded;begin ifFhandle =0 Then begin ifParent <>Nil Thenparent.handleneeded; CreateHandle; End;End;functionTWinControl.GetHandle:HWnd;beginhandleneeded; Result:=Fhandle;End;
This is because when using the handle property, the GetHandle function is used, and the handle is created in an instant, so there is already a handle to the test.
So to test, it should be tested fhandle. This would require the fhandle to be changed from private to public. Then test:
procedureTform1.button1click (sender:tobject);varPanel1:tpanel;beginPanel1:=tpanel.Create(Nil); Panel1. Left:= -; Panel1.top:= -; if(Panel1. fhandle=0) ThenShowMessage ('No handle') ElseShowMessage ('handled');End;
The result is no handle.
The design period changes the panel1.visible to False, then tests:
procedure Tform1.button1click (sender:tobject); begin if (Panel1. fhandle=0then showmessage ('no handle') Else showmessage ('handled'); End;
The result is no handle
--------------------------------------------------------------------------------------------------------------- ---------------------------
One more error code:
procedureTform1.button1click (sender:tobject);varPanel1:tpanel;beginPanel1:=tpanel.Create(Nil); Panel1. Left:= -; Panel1.top:= -; if(Panel1. handle=0) ThenShowMessage ('No handle') ElseShowMessage ('handled');End;
Immediately went wrong. An error occurred while executing the GetHandle method of the handle property because the parent control was not specified. In fact, I am from this wrong example, suddenly understand that the direct use of panel1.handle=0 is not so simple, there is a problem, can not use this method to judge.
--------------------------------------------------------------------------------------------------------------- ---------------------------
Another problem, the design period to place Image1 and load the picture, but the visible is set to false, at this time Image1 in memory of the state will be what? It is not clear ...
There is a Delphi memory object, followed by a handle (if necessary), and then the last display