Posted by webmaster Guido on December 20, 2002
In Reply to: Undeclared Identifier 'Handle' error posted by Lontek
on December 19, 2002
Did you try the code from within a routine that is a "member" of a form? Please read on, it will become clear.
Just try the following, in order to start "from scratch":
procedure TForm1.Button1Click(Sender: TObject); begin ShellExecute(Handle, 'open', PChar('calc.exe'), nil, nil, SW_SHOW); end;
The "Handle" in this example is the handle of the *Form*. The code is in fact a shorthand notation for:
ShellExecute(self.Handle, 'open', PChar('calc.exe'), nil, nil, SW_SHOW);
Because "self" refers to the form, we can omit it (the procedure Button1Click is a "member" of Form1). But if you call ShellExecute from a procedure that is not a member of a form, like this:
procedure StartCalculator; begin ShellExecute(Handle, 'open', PChar('calc.exe'), nil, nil, SW_SHOW); end;
...then it doesn't work, because the variable "Handle" is not declared in the procedure. Conclusion: undeclared identifier.
Please test the example with the button, and let us know in the Forum what happens.