views:

115

answers:

1

I'm developing a program using Lazarus, that execute gcc:

var
AProcess: TProcess;

begin
if SaveDialog1.Execute then
AProcess := TProcess.Create(nil);
AProcess.CommandLine := 'gcc.exe ' + SaveDialog1.FileName + ' -o ' TextField23.Text;
AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
AProcess.Execute;
AProcess.Free;
end;

But I want to display the log(output) of gcc on another Form(OutputForm), that have only a TMemo(OutputMemo).

How can I do it?

+1  A: 

you can use the Output property from the TProcess object.

try this code

var
  AProcess: TProcess;
begin
  if SaveDialog1.Execute then begin
    AProcess := TProcess.Create(nil);
    try
      AProcess.CommandLine := 'gcc.exe ' + SaveDialog1.FileName + ' -o '
        + TextField23.Text;
      AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
      AProcess.Execute;

      OutputForm.OutputMemo.Lines.BeginUpdate;
      //OutputForm.OutputMemo.Lines.Clear;
      OutputForm.OutputMemo.Lines.LoadFromStream(AProcess.Output);
      OutputForm.OutputMemo.Lines.EndUpdate;
    finally
      AProcess.Free;
    end;
  end;
end;
RRUZ
When I've tried. I got this: `Identifier not found "OutputForm"`
Nathan Campos
-1 for not even *trying* to improve the atrocious code in the question.
mghie
@mghie, maybe you can propose a better solution? instead of criticizing the proposed code.
RRUZ
@Nathan "OutputForm" is the name of the form or the type of the form?
RRUZ
I second RRUZ. I often find mghie's comments to be full of criticism, but without a lot of help. The question was not "help me add exception handling and cleanly free my resources" . Next time, just tell the commenter he's dense for even having to ask for your "help", and then tell all people that do respond that their answers suck and wouldn't be as good as yours, if you actually gave one....
Mick
@Nathan to help you, first you must clarify whether OutputForm refers to a type or a variable of type TForm? besides you must indicate You must indicate if the form is in the same unit of your example code.
RRUZ
Check http://stackoverflow.com/questions/1970387/use-controls-of-another-form
Nathan Campos
@RRUZ: No, I won't propose a better solution. I'm just asking for better form, and I'm more than a little tired of you posting code that's just sub-par when you clearly know your stuff (and hopefully don't write such crap for real). I've asked more than once to use `try` and `finally` as $deity intended, and I can't believe you don't know how or can't spare the time to do so. @Mick: Thanks for venting, but I won't stop commenting on or downvoting stuff that makes us all (by association) look like amateurs.
mghie
@mghie, if you consider yourself a professional, why your use foul language in your comments?
RRUZ
@mghie --- Correct, I was venting. You make a relevant point, but you only offer a criticism, not a solution. Also, I *am* an amateur and I always will be no matter how much I learn. I like SO b/c I learn from the wisdom and experience of others...not from the useless criticisms. I can tell from other posts of yours that you know your Delphi and I *want* to learn from you and others; but criticizing commenters for not fixing code, and then not fixing it yourself is a bit hypocritical. When someone knows their stuff like you do, they help the most when they lead by example
Mick
@Mick: Thanks for your considered comment. You may notice that I did in fact edit the answer to address my concerns. And I did so because I don't want to appear childish or petty; but I have tried to get RRUZ *more* than once to post code that is a good example, without success so far. I don't *have* a solution to that. @RRUZ: To make a point. Could you *please* post your code samples in such a way that it promotes good practices? You'll **never** see any "foul" language from me in a comment again, and that's a promise.
mghie
@Mick: Also, can criticism really be useless? It may hurt, but there's more to learn from it than from careless acceptance. I usually don't post an answer if somebody already wrote more or less what I would, but I comment to address details - positive or negative, I don't care.
mghie