Problem Source: http://www.cnblogs.com/del/archive/2008/05/21/1101470.html#1204455
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} var btnglobal: tbutton; {define a global object (tbutton) variable} procedure tform1.button1click (Sender: tobject); var btnlocal: tbutton; {define a local object (tbutton) variable} begin {"object" itself is a pointer, which points to the location where the object data exists;} {"@ object" is a pointer to the object, which points to the "object" variable itself, if the "object" variable exists, it must exist} {the following four rows Code The address where the pointer can be obtained. If the result is 0, the object has not been assigned a value, that is, nil} showmessage (inttostr (INTEGER (btnglobal); {0 ;} showmessage (inttostr (INTEGER (@ btnglobal); {4607236} showmessage (inttostr (INTEGER (btnlocal ))); {0} showmessage (inttostr (INTEGER (@ btnlocal); {1242560} {assigned (object) returns false} showmessage (booltostr (assigned (btnglobal), true); {false} showmessage (booltostr (assigned (btnlocal), true )); {false} {because the object variable already exists, the "@ object" pointing to the object variable will not be nil} showmessage (booltostr (assigned (@ btnglobal), true )); {true} showmessage (booltostr (assigned (@ btnlocal), true); {true} {after the value is assigned ...} btnglobal: = tbutton (sender); btnlocal: = tbutton (sender); showmessage (booltostr (assigned (btnglobal), true )); {true} showmessage (booltostr (assigned (btnlocal), true); {true} showmessage (booltostr (assigned (@ btnglobal), true )); {true} showmessage (booltostr (assigned (@ btnlocal), true); {true} end; {Because delphi will give some types of local variables a useless default value, so the following situation may occur} procedure tform1.button2click (Sender: tobject); var BTN: tbutton; begin showmessage (inttostr (INTEGER (BTN); {15012064; if you do not comment out the following sentence, it will be 0} // showmessage (inttostr (INTEGER (@ BTN); {1242560} {my conclusion is: it is unreliable to use assigned to judge a local variable that has not been initialized. This should be considered a bug} {solution: IfProgram To determine this, initialize the local variable to be null first, for example:} BTN: = nil; showmessage (booltostr (assigned (BTN), true )); {false} BTN: = tbutton (sender); showmessage (booltostr (assigned (BTN), true); {true} end; end.