请教!如何直接调用form2中的过程???(50分)

Z

zhengv

Unregistered / Unconfirmed
GUEST, unregistred user!
在form2中建了个过程。
type
procedure abc;
form2=class(tform)
end;
var
implement
procedure abc
begin
form2.memo1.lines.add('看见了!');
end;

end.
在form1调用时
TForm1.aaa1Click(Sender: TObject);
begin
form2.show;
abc;
end;
end.
不能运行!如何改动?
 
在Form1的use后面加上Form2的单元文件名,比如unit2
 
form1的use后面加了form2的单元文件名,问题不在这。
上帝和你都能帮助我,上帝不在我身边,只好求你了!
 
刚用delphi不久吧。
写上form2.abc;就中以运行的了。
 
写上form2.abc也不行。
上帝和你都能帮助我,上帝不在我身边,只好求你了!
 
你的过程定义应该在tform2类中,而你把它放在外面了
type
form2=class(tform)
procedure abc;
end;

试试看,应该可以。
上帝当然是在你身边的:)
 
[Error] Unit2.pas(10): 标识符盼望但是 'PROCEDURE'发现。
[Error] Unit2.pas(11): 未知命令: 'TForm2'
[Error] Unit2.pas(19): 'IMPLEMENTATION'盼望但是 ';'发现
[Error] Unit2.pas(22): 未说明标识符: 'TForm2'
[Error] Unit2.pas(24): '.'盼望但是 'IMPLEMENTATION'发现
[Error] Unit2.pas(10): Unsatisfied朝向或外部说明: 'abc'
[Fatal Error] Unit1.pas(7): 不能编译使用单元 'Unit2.pas'
上帝和你都能帮助我,上帝不在我身边,只好求你了!
 
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type

TForm2 = class(TForm)
procedure abc;
Memo1: TMemo;//改完这过不去??????????????????????

private
{ Private declarations }
public

{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.DFM}
procedure abc;
begin
form2.memo1.lines.add('看见了!');
end;

end.
 
type
Form2=Class(TForm)
public
procedure abc;
end;
implement
procedure abc
begin
form2.memo1.lines.add('看见了!');
end;

end.
在form1调用时
TForm1.aaa1Click(Sender: TObject);
begin
form2.show;
abc;
end;
end.
 
我告诉你错在那里:
在form2中建了个过程。
type
procedure abc;//[red]错在这里!!!!![/red]
form2=class(tform)
end;
[red]//把那一句移到这里:[/red]
procedure abc;
var
implement
procedure abc
begin
form2.memo1.lines.add('看见了!');
end;

end.
在form1调用时
TForm1.aaa1Click(Sender: TObject);
begin
form2.show;
abc;
end;
end.
 
up 一下。
直接好像不行,可以用类实例的方法代替阿,或者用一个过程变量引用
 
chuguozhen是高手!就你方法通了,虽然不明白为什么但感谢你!
上帝和你都能帮助我,上帝不在我身边,只好求你了!
 
unit1的代码
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
form2.show;
addstring;
end;
end.

unit2的代码
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm2 = class(TForm)
Memo1: TMemo;
Button1: TButton;
private
{ Private declarations }
public
{ Public declarations }
end;
procedure addstring;
var
Form2: TForm2;

implementation

{$R *.dfm}

procedure addstring;
begin
form2.Memo1.lines.add('I have looled');
end;

end.

在我的机器上测试通过!你可以使用!
 
顶部