2009-12-28 49 views
0

我有一個Lazarus項目有兩種形式,FormMainOutputForm。我想在此代碼的第二形式展現在OutputMemo一個輸出:使用另一種形式的控件

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; 

但是當我嘗試編譯這段代碼,我得到了錯誤:

Identifier not found "OutputForm"

在OutputForm單元的頂部我有:

unit Output; 

當我嘗試從FormMain單元(OutputForm: Output;)調用它,我得到這個錯誤:

Error in type definiition

我該怎麼辦?

+1

嘗試將OutputForm的單位添加到uses子句。 – RRUZ 2009-12-28 17:00:41

+0

如何做到這一點? – 2009-12-28 17:01:34

+0

更新了我的回覆。 – 2009-12-28 18:29:18

回答

2

正如RRUZ所說,您需要對聲明OutputForm的單元的引用。這裏的基本思路是:

每個表單都有一個表單聲明文件(Delphi中的DFM;我認爲Lazarus稱它們爲LFM)和一個相應的Object Pascal單元文件(.PAS),在其中放置它們的代碼。就編譯器而言,這是一個正常的單元文件。唯一的區別是它有一個與之相關的形式。

打開OutputForm的代碼並查看頂部。它會說類似「單元OutputForm;」複製單元名稱,並將其粘貼到使用FormMain單元的子句,然後它應該工作。

編輯:不太清楚你想要做的修改,但你不需要重新聲明OutputForm。它應該已經在輸出單元中聲明爲全局變量。你只需要輸出添加到您的使用條款,所以你會類似於這樣結束了:

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) 
    ... 
+0

請現在看看這個問題。 – 2009-12-28 17:48:08

0

嗯,不是「輸出」 Pascal的保留字?

+1

你問或說? – 2009-12-28 19:25:19

+0

我在暗示一個可能的答案。我對拉撒路知之甚少,對此並不瞭解。 – dummzeuch 2009-12-30 22:07:34