Skip to content

Instantly share code, notes, and snippets.

@stijnsanders
Last active July 1, 2026 20:03
Show Gist options
  • Select an option

  • Save stijnsanders/c7dce4365cde11659c4892d2e7d7109a to your computer and use it in GitHub Desktop.

Select an option

Save stijnsanders/c7dce4365cde11659c4892d2e7d7109a to your computer and use it in GitHub Desktop.
(Ab)Use the Delphi IDE to get your project built, but still get the output over standard out.
program fixdpb;
{$APPTYPE CONSOLE}
uses
Windows,
SysUtils,
Classes;
const
CheckCompilerResultIntervalMS=2000;
WM_CLOSE = $0010;//all we need from Messages.pas
var
pi:TProcessInformation;
pn:boolean;
function FindCompileBtn(hwnd:THandle;lparam:DWORD):BOOL; stdcall;
var
s:WideString;
i:integer;
begin
Result:=true;//continue enumeration
SetLength(s,1000);
i:=GetClassNameW(hwnd,PWideChar(s),999);
SetLength(s,i);
if s='TButton' then
begin
SetLength(s,1000);
i:=GetWindowTextW(hwnd,PWideChar(s),999);
SetLength(s,i);
if s='OK' then //TODO: localize or from config
begin
//not 'Cancel' so assume compile failed
pn:=true;
Result:=false;//end enumeration
end;
end;
end;
function FindCompileWin(hwnd:THandle;lparam:DWORD):BOOL; stdcall;
var
tid:DWORD;
s:string;
i:integer;
begin
Result:=true;//continue enumeration
tid:=GetWindowThreadProcessId(hwnd,nil);//pid);
if tid=pi.dwThreadId then
begin
SetLength(s,1000);
i:=GetClassName(hwnd,PChar(s),999);
SetLength(s,i);
if s='TProgressForm' then
begin
pn:=false;
EnumChildWindows(hwnd,@FindCompileBtn,0);
if pn then
SendMessage(hwnd,WM_CLOSE,0,0);
Result:=false;//stop enumeration
end;
end;
end;
var
sl:TStringList;
si:TStartupInfo;
cl,fn:string;
i:integer;
r:cardinal;
begin
fn:=ParamStr(1);
sl:=TStringList.Create;
try
sl.LoadFromFile(ChangeFileExt(ParamStr(0),'.ini'));
cl:='"'+sl[0]+'" "'+fn+'" '+sl[1];
finally
sl.Free;
end;
i:=SizeOf(TStartupInfo);
ZeroMemory(@si,i);
si.cb:=i;
if CreateProcess(nil,PChar(cl),nil,nil,true,0,nil,nil,si,pi) then
begin
CloseHandle(pi.hThread);
//WaitForSingleObject(pi.hProcess,INFINITE);
repeat
r:=WaitForSingleObject(pi.hProcess,CheckCompilerResultIntervalMS);
if r=WAIT_TIMEOUT then
EnumWindows(@FindCompileWin,0);
//until r=WAIT_OBJECT_0;
until r<>WAIT_TIMEOUT;
if GetExitCodeProcess(pi.hProcess,r) then ExitCode:=r;
CloseHandle(pi.hProcess);
sl:=TStringList.Create;
try
//TODO: support UTF8
sl.LoadFromFile(ChangeFileExt(fn,'.err'));
for i:=0 to sl.Count-1 do
begin
if Copy(sl[i],1,14)='[dcc32 Error] ' then
Writeln(Copy(sl[i],15,999))
else
if Copy(sl[i],1,16)='[dcc32 Warning] ' then
Writeln(Copy(sl[i],17,999))
else
Writeln(sl[i]);
if sl[i]='Failed' then ExitCode:=9;//?
end;
finally
sl.Free;
end;
end
else
RaiseLastOSError;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment