1
General release and closed:
Form.Free - release all resources Form occupied. After Free, Form pointer can not be used unless reassigned Form.
Form .hide - Hidden Form. Form.Show display can be called again.
Form .close - Close Form, actual results depend OnCloseQuery and OnClose, if OnCloseQuery of CanClose to False, does nothing, If True, the value OnClose further study of the Action:
Canone: Do nothing
caHide: Hide Window , with form.Hide
caFree: Form release resources occupied, with form.Free
caMinimize: Form minimized.
Subform release:
T Procedure the Form1 .FormClose (Sender: TObject; var the Action: TCloseAction); the begin the Action: = caFree; // release subform End; Procedure T the Form1 .FormDestroy (Sender: TObject); the begin the Form1 : = nil; // Clear release form must use the form's name release, can not use self: = nil otherwise Assigned still be able to find end;
Another more advanced functions:
FreeAndNil (Form1); // As the name suggests, the release of dual-use and emptying.
2
Determine whether there is a form:
Method One: Assigned function does not return True parameter is nil, a pointer that already refers to a memory address, the memory address may be subject to a first address may also be a function or procedure, declare a pointer variable, no assignment to nil, no mess pointing somewhere, these two cases, assigned (pointer variable) is not nil, the function back into the True;
The argument is nil when it returns False.
Assigned is not really a function.
Correct usage:
if Assigned(Form1) then begin Form1.close; Form1:=nil; end; 或: if Assigned(Form1) then begin Form1.close; FreeAndNil(Form1); end;
Method two: the FindWindow function is used to obtain a handle to open window
The FindWindow (
the lpClassName, {} window class name if blank write nil
lpWindowName: the PChar {} window title if the title is empty write nil
): the HWND; {returns a handle to the window; else return 0}
// find the program's main window handle var H: HWND; the begin H: = FindWindow ( 'TForm1', 'form title'); // know the title and window class name of the window, is empty write nil ShowMessage (IntToStr ( h)); {h = 656180 ; this is a random, not the same each time window starts}
There is also a spread function FindWindowEx
FindWindowEx get a child window specified window handle
format: FindWindowEx (handle to handle child windows of the parent window's class name, title)
Note: When the handle of the child window is 0, the acquisition of the handle is in the parent window in line with handle of the first window class name and title, if the child window handle is the handle of a child window, you get to handle, the next window is the handle of the child window (this is important oh)
mentioned here window is not necessarily FORM, possibly BUTTON, EDIT, LABEL. .