【问题标题】:TOpenDialog And SpacesTOpenDialog 和空间
【发布时间】:2009-12-29 00:52:12
【问题描述】:

我有一个关于 Lazarus 的项目,我想使用 gcc 编译源代码,为此我有一个名为 OpenDialog1TOpenDialog 和一个名为 AProcessTProcess

我用这段代码调用 gcc:

procedure TFormMain.btCompileClick(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    AProcess := TProcess.Create(nil);
    try
      AProcess.CommandLine := 'gcc.exe ' + OpenDialog1.FileName;
      AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
      AProcess.Execute;
      OutputMemo.Lines.BeginUpdate;
      OutputMemo.Lines.Clear;
      OutputMemo.Lines.LoadFromStream(AProcess.Output);
      OutputMemo.Lines.EndUpdate;
    finally
      AProcess.Free;
    end;
  end;
end;

它可以编译(Lazzarus 上的项目),但是当我测试它时,通过尝试编译位于 C:\Documents and Settings\Nathan Campos\Desktop 的源 test.c,我在 OutputMemo 上得到了这个:

'C:\Documents': 没有这样的文件或目录

那么,OpenDialog1 没有得到带空格的完整路径,或者 gcc 无法在带空格的文件夹中找到它。

有什么建议可以帮助我吗?

【问题讨论】:

    标签: delphi directory spaces lazarus


    【解决方案1】:

    它需要用引号引起来,这样空格才不会出错。像这样:

    AProcess.CommandLine := 'gcc.exe "' + OpenDialog1.FileName + '"';
    

    应该可以的。

    【讨论】:

    • 非常感谢!我忘了这件事,抱歉让你耽误你的时间:(
    猜你喜欢
    • 2011-07-19
    • 1970-01-01
    • 2011-09-18
    • 2011-09-08
    • 2011-11-17
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 2021-10-17
    相关资源
    最近更新 更多