troubleshooting Question

How to fix "Types of actual and formal var parameters must be identical." error?

Avatar of IT79637
IT79637Flag for United States of America asked on
Delphi
8 Comments6 Solutions3887 ViewsLast Modified:
Hi Experts,

I'm using Delphi 7 on a win xp pro sp2 box.

From Delphi, I want to execute a Win batch file and wait for the successful/failure execution of the bat file.  I'm using the code below that came from:

https://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21809937.html.

However, it throws an error:

[Error] Unit1.pas(198): Types of actual and formal var parameters must be identical
[Fatal Error] CallWinPrograms.dpr(5): Could not compile used unit 'Unit1.pas'

The compile error occurs on this line in the code below:

GetExitCodeProcess(ProcessInfo.hProcess, Result);

Can someone please help resolve this issue?

Thanks.

Does Result need to be a double word?
function WinExecAndWait32aFileName: string; Visibility: Integer): integer;
 { returns -1 if the Exec failed, otherwise returns the process' exit
   code when the process terminates }
var
  zAppName: array[0..512] of char;
  lpCommandLine: array[0..512] of char;
  zCurDir: array[0..255] of char;
  WorkDir: string;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  StrPCopy(zAppName, '');
  StrPCopy(lpCommandLine, FileName);
  GetDir(0, WorkDir);
  StrPCopy(zCurDir, WorkDir);
  FillChar(StartupInfo, Sizeof(StartupInfo), #0);
  StartupInfo.cb := Sizeof(StartupInfo);
 
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(
    nil, { pointer to command line string }
    lpCommandLine,
    nil, { pointer to process security attributes }
    nil, { pointer to thread security attributes}
    False, { handle inheritance flag }
    CREATE_NEW_CONSOLE or { creation flags }
    NORMAL_PRIORITY_CLASS,
    nil, { pointer to new environment block}
    nil, { pointer to current directory name }
    StartupInfo, { pointer to STARTUPINFO }
    ProcessInfo) then Result := -1 { pointer to PROCESS_INF }
  else begin
    WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);          // <<---error occurs here
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
  end;
end;
 
procedure TForm1.Button8Click(Sender: TObject);
var
  sBatchFileName : string;
begin
  sBatchFileName:= 'c:\windows\batch\icp.bat';
  WinExecAndWait32a(sBatchFileName, SW_HIDE);
end;
ASKER CERTIFIED SOLUTION
SteveBay

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 6 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 6 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros