Use Controls Of Another Form
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 OutputF开发者_运维百科orm 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?
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)
...
Hm, isn't "output" a reserved word in Pascal?
精彩评论