I need ShellAPI help for my unit

I have a small unit 'ExeMod.pas' and in the Initialization section I have code like this


initialization
begin
ShellExecute(Handle, 'open', PChar('My.exe'), PChar('-a'), nil, SW_SHOW);
end;
end.

I put ShellAPI in the unit's uses clause
but when I try to run a program that uses
ExeMod.pas I get this error

Undeclared identifier 'Handle'

what silly little thing am I forgetting to do...or what am I doing wrong?
:-)
LVL 5
GwenaAsked:
Who is Participating?
 
NickRepinConnect With a Mentor Commented:
Looks like you don't need the Handle at all. Use 0 or nil instead.
0
 
Mohammed NasmanSoftware DeveloperCommented:
seems that you don't use forms, so the contorl unit not included in the uses clause
0
 
GwenaAuthor Commented:
Hi :-)

 adding control to the uses does not help :-(
 setting Handle to 0 does seem to work :-)

But It's late and I'm groggy (must be that long island tea that guy got me :-)

I will check out using 0 to replace Handle a bit more in the morning :-)
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
intheCommented:
just to add ,used in the usual delphi context
(ie in some procedure of a form) "handle"  would refer to the form1.handle property

for instance

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(inttostr(handle));
showmessage(inttostr(form1.Handle));
end;

would both show same result
so to use a 0 a nick said will be fine

 from win32 help about the hwnd param of shellexecute:
This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box.

if that functionality was needed you would probably use createprocess anyway..
0
 
d32coderCommented:
Try using
Application.Handle
instead.

Don
0
 
GwenaAuthor Commented:


  Your solution works fine... so here's your points
Thanks a bunch :-)
0
 
GwenaAuthor Commented:
Hi inthe
  Thanks for the extra info about handles... handles still seem a bit mysterious to me :-)
0
 
GwenaAuthor Commented:
Hi d32coder

 Application.handle seems to work fine as well... thanks for the info :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.