Hi everybody,

I have this procedure for launching an application and wait
for it to finish, but I get an error:

[Error] Main.pas(57): Types of actual and formal var parameters must be identical

What do I do wrong? Who can help me?

function WinExecAndWait32(FileName: string; Visibility: integer): integer; 
var 
  zAppName: array[0..512] of char; 
  zCurDir : array[0..255] of char; 
  WorkDir : string; 
  StartupInfo: TStartupInfo; 
  ProcessInfo: TProcessInformation; 
begin 
  StrPCopy(zAppName, 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, 
                       zAppName, { pointer to command line string } 
                       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 { pointer to PROCESS_INF } 
    Result := -1 
  else 
    begin 
      WaitforSingleObject(ProcessInfo.hProcess, INFINITE); 
      GetExitCodeProcess(ProcessInfo.hProcess, Result);   <-----Error 
    end; 
end;
 
procedure TForm1.Button1Click(Sender: TObject); 
var 
  sBatchFileName: String; 
begin 
  sBatchFileName := 'c:\SAY.bat'; 
  if FileExists(SBatchFileName) then 
  begin 
    WinExecAndWait32(sBatchFileName, SW_HIDE); 
  end; 
end;

Greetings,

Peter Kiers

it's so hard to look at line 57 and see what is happening? how can we know which is the 57th line of your code?

also take a look here http://www.cs.wisc.edu/~rkennedy/var-identical

if you still can not handle with this error post the line where the compiler trow this error.

best regards

Member Avatar for Micheus

Hi everybody,

I have this procedure for launching an application and wait
for it to finish, but I get an error:

[Error] Main.pas(57): Types of actual and formal var parameters must be identical

What do I do wrong? Who can help me?

function WinExecAndWait32(FileName: string; Visibility: integer): integer; 
var 
  zAppName: array[0..512] of char; 
  zCurDir : array[0..255] of char; 
  WorkDir : string; 
  StartupInfo: TStartupInfo; 
  ProcessInfo: TProcessInformation; 
begin 
  StrPCopy(zAppName, FileName); 
  ...
    begin 
      WaitforSingleObject(ProcessInfo.hProcess, INFINITE); 
      GetExitCodeProcess(ProcessInfo.hProcess, Result);   <-----Error 
    end; 
end;
 
...

Just look at this from help:
BOOL GetExitCodeProcess(
HANDLE hProcess, // handle to the process
LPDWORD lpExitCode // address to receive termination status
);

Did you perceived? Your funtion result is declared Integer, but GetExitCodeProcess expected by a DWORD param (in the true, LPDWORD). So, just change return type from Integer to Longword.

bye.

uh, it expects a far pointer to a DWORD, which is a far pointer to longword, not a longword.

Member Avatar for Micheus

Just make the change and try. I had test it and worked fine.

Member Avatar for Micheus

Just extending my last post...
The observation in jwenting's post #4 is true. In this case, we have only to put "@" char before variable:
GetExitCodeProcess(ProcessInfo.hProcess, @Result);But, my answer was based in Delphi 7, where function's declaration (in Windows.pas unit) the parameter is declarede like Var reference to DWord - not PDWord:

function GetExitCodeProcess(hProcess: THandle; var lpExitCode: DWORD): BOOL; stdcall;

Bye

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.