Board index » delphi » Bug with ShellExecute in D3?

Bug with ShellExecute in D3?

I have a D2 application I recently compiled with D3.  Aside from the Quick
Reports and a few new/renamed.moved units, all went relatively well.  Now,
however, one section of my previously stable codes produces an access
violation when the SHELLEXECUTE routine is called in the following
program.  Anyone know why or, most importantly, how to work around the
problem.

Thanks in advance.

function ExecuteFile(const FileName, Params, DefaultDir: string; ShowCmd:
Integer): Boolean;
var
    zFileName, zParams, zDir: array[0..79] of Char;
begin
    {open file using command  such as  ExecuteFile(FileName, '',
Directory, SW_SHOW);  }

    Result := (ShellExecute(Application.MainForm.Handle, nil,
                StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
                StrPCopy(zDir, DefaultDir), ShowCmd) > 32);
end;

Note: this is an almost exact duplicate of the routine in FMXUtils.pas in
the D2 and D3 demo programs.
M. Scott St.Cyr
Cyrious Software, Inc.
//***************************************************************//

 

Re:Bug with ShellExecute in D3?


There is no bug. Try this:

function ExecuteFile(const FileName, Params, DefaultDir: string; ShowCmd:
Integer): Boolean;
begin
  {open file using command  such as  ExecuteFile(FileName, '',
  Directory, SW_SHOW);  }
  Result := (ShellExecute(Application.MainForm.Handle, nil,
PChar(FileName), PChar(Params),
    PChar(DefaultDir), ShowCmd) > 32);
end;

Quote
> Note: this is an almost exact duplicate of the routine in FMXUtils.pas in
> the D2 and D3 demo programs.

Make sure in the project you have enabled options: Huge strings & Extended
syntax.

I hope it'll help.

Ruslan.

Other Threads