We help IT Professionals succeed at work.
Get Started

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

IT79637
IT79637 asked
on
3,886 Views
Last Modified: 2012-05-06
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;

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 6 Answers and 8 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE