使用另一种形式的控件

发布于 2024-08-16 04:54:37 字数 952 浏览 3 评论 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;

但是当我尝试编译此代码时,出现错误:

未找到标识符“OutputForm”

在 OutputForm 单元的顶部我有:

unit Output;

当我尝试从 FormMain 单元调用它时(OutputForm: Output;) 我收到此错误:

类型定义错误

我该怎么办?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别把无礼当个性 2024-08-23 04:54:37

正如 RRUZ 所说,您需要对声明 OutputForm 的单元的引用。基本思想如下:

每个表单都有一个表单声明文件(Delphi 中的 DFM;我认为 Lazarus 称它们为 LFM)和一个相应的 Object Pascal 单元文件 (.PAS),您可以在其中放置其代码。就编译器而言,这是一个像任何其他文件一样的普通单元文件。唯一的区别是它有一个与之关联的形式。

打开 OutputForm 的代码并查看顶部。它会显示类似“unit OutputForm;”的内容复制单元名称,并将其粘贴到 FormMain 单元的 uses 子句中,然后它应该可以工作。

编辑:不太确定您要对该编辑执行什么操作,但您不需要重新声明 OutputForm。它应该已经在输出单元中声明为全局变量。您只需将 Output 添加到 use 子句中,最终会得到类似于以下内容的结果:

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

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)
  ...
筱果果 2024-08-23 04:54:37

嗯,“输出”不是 Pascal 中的保留字吗?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文