Link to home
Start Free TrialLog in
Avatar of PallaviSaxena
PallaviSaxena

asked on

E1012 Constant expression violates subrange bound

I was using the link for one of my problems:

https://www.experts-exchange.com/questions/21986064/Using-CreateProcess-instead-of-WinExec.html

It had the below code snippet at http://www.scalabium.com/faq/dct0050.htm location which I was using:

function WinExecAndWait32(FileName: string; Visibility: Integer): dWord;
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
    Result := -1 { pointer to PROCESS_INF }
  else
  begin
    WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
  end;
end;

But I am getting the error:
E1012 Constant expression violates subrange bound
on Result := -1 line.

Please can you let me know what is the problem with dWord to accept -1 value.
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

dword range is the same of cardinal, so it starts from 0 and -1 is out of range

Use another windows constant instead like for example WAIT_FAILED, declared in windows unit DWORD($FFFFFFFF)
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial