There is a Delphi memory object, followed by a handle (if necessary), and then the last display

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.