Board index » delphi » Delphi 4 launching another application/batch file

Delphi 4 launching another application/batch file

Hi everyone,

related to Antonio Sanchez Zaplana's enquiry: I'd like to launch another .exe (or .bat) from
inside a Delphi application using Delphi 4 running under Windows 95 (or Windows NT4).

My problem is that I don't appear to have access to help pages for any of the suggestions I've
found so I can't get the appropriate syntax right: CreateProcess, WinExec or ShellExec. Does
anyone know where I could find documentation for the Windows API calls that can be used in
Delphi? Would anyone be kind enough to mail me an example piece of code to accomplish this
in Delphi 4?

A related problem: I guess from what I have seen that the Windows API calls take strings as
PChars, for instance the suggestion in the Delphi Developer's Guide (page 486) for launching
another application hinges on converting parameters from strings to PChars. Is this right, and if
so, has anyone out there found a way of doing this? Every way I try this I get errors such as  
"Path[0] inaccessible, use Length or SetLength" or "incompatible types".

And am I missing something, or aren't the Delphi 4 help pages themselves quite annoying: has
anyone managed to find a list of ASCII codes in there, for instance, which I'd have said was a
pretty basic and obvious requirement?

Thank you for any help,
Jon

P.S. I'm a newbie, please be gentle...

 

Re:Delphi 4 launching another application/batch file


this is the function, is uses ShellAPI:

function ExecuteFile(const FileName, Params, DefaultDir: string; howCmd:
Integer): THandle;
var
  zFileName, zParams, zDir: array[0..256] of Char;
begin
  Result:=ShellExecute(Application.MainForm.Handle, nil, StrPCopy(zFileName,
FileName), StrPCopy(zParams, Params), StrPCopy(zDir, DefaultDir), ShowCmd);
end;

and this is how you can call it:

ExecuteFile('<filename.exe>','','',SW_SHOW);

Alex

--
remove .nospam if you reply by e-mail
--
The Motherboard Monitor:
http://www.euronet.nl/users/darkside/mbmonitor/
--

Quote
Jon Clarke wrote in message <6ttn86$s0...@lightning.cise.npl.co.uk>...
>Hi everyone,

>related to Antonio Sanchez Zaplana's enquiry: I'd like to launch another
.exe (or .bat) from
>inside a Delphi application using Delphi 4 running under Windows 95 (or
Windows NT4).

>My problem is that I don't appear to have access to help pages for any of

the suggestions I've
Quote
>found so I can't get the appropriate syntax right: CreateProcess, WinExec
or ShellExec. Does
>anyone know where I could find documentation for the Windows API calls that
can be used in
>Delphi? Would anyone be kind enough to mail me an example piece of code to
accomplish this
>in Delphi 4?

>A related problem: I guess from what I have seen that the Windows API calls
take strings as
>PChars, for instance the suggestion in the Delphi Developer's Guide (page
486) for launching
>another application hinges on converting parameters from strings to PChars.

Is this right, and if
Quote
>so, has anyone out there found a way of doing this? Every way I try this I
get errors such as
>"Path[0] inaccessible, use Length or SetLength" or "incompatible types".

>And am I missing something, or aren't the Delphi 4 help pages themselves
quite annoying: has
>anyone managed to find a list of ASCII codes in there, for instance, which
I'd have said was a
>pretty basic and obvious requirement?

>Thank you for any help,
>Jon

>P.S. I'm a newbie, please be gentle...

Re:Delphi 4 launching another application/batch file


Jon,

Quote
> My problem is that I don't appear to have access to help pages for any of the suggestions I've
> found so I can't get the appropriate syntax right: CreateProcess, WinExec or ShellExec. Does
> anyone know where I could find documentation for the Windows API calls that can be used in
> Delphi? Would anyone be kind enough to mail me an example piece of code to accomplish this
> in Delphi 4?

You have the help files - you're like my partner, though: you don't
read README files... <g>

Win32.HLP is located in Program Files\Common Files\Borland Shared\
MSHelp.

You can also use ExecuteFile(), contained in FMXUtils.pas (located
in Delphi4\Demos\Doc\FileManEx) to run an external process.

Quote
> A related problem: I guess from what I have seen that the Windows API calls take strings as
> PChars, for instance the suggestion in the Delphi Developer's Guide

With Delphi 32 bit, this is a piece of cake - there really isn't
any conversion:

var
   sStr: String;
begin
   sStr := 'This is a value for an API call';
   UseApiFunction(PChar(sStr));
end;

That's it... A simple typecast.

Quote
> "Path[0] inaccessible, use Length or SetLength" or "incompatible types".

The problem is that, in Delphi 1 and earlier versions of Pascal,
strings were restricted to 255 characters, and String[0] was
a place to store the length of the string. This isn't true in
32-bit versions of Delphi, where String is the same (by default)
as AnsiString and has virtually no limit (OK, 2GB). The AnsiString
type is 1-based, so the beginning of the string starts at Str[1] -
that's why you got the above error message.

Quote
> And am I missing something, or aren't the Delphi 4 help pages themselves quite annoying: has
> anyone managed to find a list of ASCII codes in there, for instance, which I'd have said was a
> pretty basic and obvious requirement?

ASCII codes aren't really appropriate under Windows, as it doesn't
normally use ASCII (OEM) character sets; it uses the ANSI character
set instead.

I'm sorry - I may be dense, but I'm not sure why this is a 'basic
and obvious requirement'... It may have been in the DOS world, so
you had line drawing and non-US character support... But I've been
developing for Windows for about 5 years now, and haven't needed
an ASCII chart yet...

If you really have a need for one, you can use the Character Map
application that comes with Windows (you may need to install it
from your Windows 95 CD, under the Accessories category).

Quote
> P.S. I'm a newbie, please be gentle...

I hope I met this request... :-)

Ken
--
Ken White

Clipper Functions for Delphi
http://members.aol.com/clipfunc

Other Threads