获取Delphi 2010命令行编译行号

时间:2011-03-31 02:14:38

标签: delphi delphi-2010

有没有办法让Delphi 2010命令行编译器(dcc32.exe)行号传回管道中的GUI应用程序进度条?

作为替代方案,从以下字符串返回(行号)是一个很好的函数:

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)  

2 个答案:

答案 0 :(得分:6)

查看JEDI JVCL安装程序。它确实如此,它是开源的,所以你可以看到它是如何完成的。

答案 1 :(得分:2)

寻找到最后一行。你在那里找到的角色应该是一个右括号。向后寻找左括号。您传递的字符是行号。

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;