Bill
Bill

Reputation: 3033

Get The Delphi 2010 Comandline Compiler Line Number

Is there any way to get the Delphi 2010 commandline compiler (dcc32.exe) line number to pass back to a GUI application progressbar in a pipe?

As an alternative what is a good function to return the (line number) from the following strings:

C:\Components\Dabbler\Pipes\Demos\Demo3\TestUnit\uGlobal.pas(20) 
C:\Components\Dabbler\Pipes\Demos\Demo3\TestUnit\uGlobal.pas(339) 
C:\Components\Dabbler\Pipes\Demos\Demo3\TestUnit\uGlobal.pas(341) 
C:\Components\Dabbler\Pipes\Demos\Demo3\TestUnit\uGlobal.pas(512) 
C:\Components\Dabbler\Pipes\Demos\Demo3\TestUnit\uGlobal.pas(1024) 
C:\Components\Dabbler\Pipes\Demos\Demo3\TestUnit\uGlobal.pas(1536) 
C:\Components\Dabbler\Pipes\Demos\Demo3\TestUnit\uGlobal.pas(2048) 
C:\Components\Dabbler\Pipes\Demos\Demo3\TestUnit\uGlobal.pas(2560) 
C:\Components\Dabbler\Pipes\Demos\Demo3\TestUnit\uGlobal.pas(3072) 
C:\Components\Dabbler\Pipes\Demos\Demo3\TestUnit\uGlobal.pas(3342)  

Upvotes: 1

Views: 274

Answers (2)

Rob Kennedy
Rob Kennedy

Reputation: 163357

Seek to the end of the line. The character you find there should be a closing parenthesis. Seek backward to the opening parenthesis. The characters you passed over are the line number.

function ExtractLineNumber(const Line: string): Integer;
var
  i, len: Integer;
begin
  i := Length(Line);
  Assert(Line[i] = ')', 'unexpected line format');
  len := -1;
  while (i > 0) and (Line[i] <> '(') do begin
    Dec(i);
    Inc(len);
  end;
  Assert(i > 0, 'unexpected line format');
  Assert(len > 0, 'unexpected line format');
  Result := StrToInt(Copy(Line, i + 1, len));
end;

Upvotes: 2

Ken White
Ken White

Reputation: 125748

Look at the JEDI JVCL installer. It does exactly this, and it's open-source so you can see how it was done.

Upvotes: 6

Related Questions