使用另一种形式的控件
我在 Lazarus 上有一个项目,有两个表单:FormMain
和 OutputForm
。我想使用以下代码在第二个表单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 RRUZ 所说,您需要对声明 OutputForm 的单元的引用。基本思想如下:
每个表单都有一个表单声明文件(Delphi 中的 DFM;我认为 Lazarus 称它们为 LFM)和一个相应的 Object Pascal 单元文件 (.PAS),您可以在其中放置其代码。就编译器而言,这是一个像任何其他文件一样的普通单元文件。唯一的区别是它有一个与之关联的形式。
打开 OutputForm 的代码并查看顶部。它会显示类似“unit OutputForm;”的内容复制单元名称,并将其粘贴到 FormMain 单元的 uses 子句中,然后它应该可以工作。
编辑:不太确定您要对该编辑执行什么操作,但您不需要重新声明 OutputForm。它应该已经在输出单元中声明为全局变量。您只需将 Output 添加到 use 子句中,最终会得到类似于以下内容的结果:
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:
嗯,“输出”不是 Pascal 中的保留字吗?
Hm, isn't "output" a reserved word in Pascal?