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(Proces sInfo.hPro cess, INFINITE);
GetExitCodeProcess(Process Info.hProc ess, Result);
CloseHandle(ProcessInfo.hP rocess);
CloseHandle(ProcessInfo.hT hread);
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.
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:
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(Proces
GetExitCodeProcess(Process
CloseHandle(ProcessInfo.hP
CloseHandle(ProcessInfo.hT
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use another windows constant instead like for example WAIT_FAILED, declared in windows unit DWORD($FFFFFFFF)