Avatar of IT79637
IT79637
Flag for United States of America asked on

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

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/questions/21809937/delphi-calling-a-batch-file.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;

Open in new window

Delphi

Avatar of undefined
Last Comment
IT79637

8/22/2022 - Mon
SOLUTION
btframework

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
SteveBay

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
btframework

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
btframework

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
SteveBay

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
btframework

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
IT79637

ASKER
btframework, SteveBay

Please!!!!  (lol)

Stop adding comments so I can assign points and close the question!!!  (lol)


Seriously, thanks to both for all your comments!!!
IT79637

ASKER
I split the points between SteveBay-300 and btframework-200 (a 60%/40% split) primarily because SteveBay had a complete solution that I could copy/paste.  The first response did not catch the integer/dwond in the declaration of the function.   I did not want to get in the middle of the discussion on using another variable vs type casting.

However, in btframework comments there is information to be learned and a solution.

Hope I donot offend anyone.

Thanks again for your expert input.

Cheers.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck