开发者

TOpenDialog And Spaces

开发者 https://www.devze.com 2022-12-14 20:15 出处:网络
I have a project on Lazarus that I want to compile a source using gcc, for this I ha开发者_高级运维ve a TOpenDialog called OpenDialog1 and a TProcess called AProcess.

I have a project on Lazarus that I want to compile a source using gcc, for this I ha开发者_高级运维ve a TOpenDialog called OpenDialog1 and a TProcess called AProcess.

I call gcc with this code:

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;

It compiles ok(the project on Lazzarus), but when I was testing it, by trying to compile the source test.c, that is located at C:\Documents and Settings\Nathan Campos\Desktop, I got this on OutputMemo:

'C:\Documents': No such file or directory

Then, OpenDialog1 isn't getting the full path with the spaces, or gcc can't locate it on the folder with spaces.

Any suggestion to help me on this?


It needs to be in quotes so spaces won't trip it up. So like this:

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

That should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消