views:

78

answers:

2

I have a project on Lazarus that have two Forms, FormMain and OutputForm. I want to show a output on OutputMemo at the second Form with this code:

procedure FormMain.ShowButton(Object: Sender);
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; 

  OutputForm.OutputMemo.Lines.BeginUpdate; 
  //OutputForm.OutputMemo.Lines.Clear; 
  OutputForm.OutputMemo.Lines.LoadFromStream(AProcess.Output); 
  OutputForm.OutputMemo.Lines.EndUpdate; 

  AProcess.Free; 
end;

But when I try to compile this code, I got the error:

Identifier not found "OutputForm"

At the top of OutputForm unit I have:

unit Output;

And when I try to call it from FormMain unit(OutputForm: Output;) I got this error:

Error in type definiition

What I have to do?

+2  A: 

As RRUZ said, you need a reference to the unit where OutputForm is declared. Here's the basic idea:

Each form has a form declaration file (DFM in Delphi; I think Lazarus calls them LFMs) and a corresponding Object Pascal unit file (.PAS) where you put their code. This is a normal unit file like any other, as far as the compiler's concerned. The only difference is that it has a form associated with it.

Open the code for OutputForm and look at the top. It'll say something like "unit OutputForm;" Copy the unit name, and paste it into the uses clause of FormMain's unit, and then it should work.

EDIT: Not quite sure what you're trying to do with that edit, but you don't need to redeclare OutputForm. It should already be declared as a global variable in the Output unit. You just need to add Output to your uses clause, so you'll end up with something similar to this:

unit Main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Output; //on a separate line to show it's not a system lib

type
  TFrmMain = class(TForm)
  ...
Mason Wheeler
Take a look at the question now please.
Nathan Campos
A: 

Hm, isn't "output" a reserved word in Pascal?

dummzeuch
Are you asking or telling?
Rob Kennedy
I am suggesting a possible answer. I don't know enough about Lazarus to know whether this is the case.
dummzeuch