两个Unit单元可以共用同一个form窗体吗?(50分)

L

Liyue

Unregistered / Unconfirmed
GUEST, unregistred user!
两个Unit单元可以共用同一个form窗体吗?
例如:Form窗体上有个edit1。我希望在unit1单元中
包含"edit1.text:='good'。
在unite2单元中包含"edit1.text:='bad' 。
怎样实现?请给个例程。谢谢!!!
 
你的表达有问题!
在unite2中 uses unit1;则可以Form1.edit1.text:='bad' ;
不知道你是不是这个意思?
 
to wjiachun
仅仅加上 uses unit1 不能运行。
我的问题是:
在一个form窗体form1 和与其配套的unit主程
序unit1 之外,再新建一个unit程序unit2,希望
在unit2 中对form1 进行操作(例如,在unit2中
加上“form1.edit1.text:='nnnnnnn' ”)
怎样实现?
谢谢!!
 
在UNIT2的USES子句中加入UNIT1就行了。
 
以下程序有错误,请更正,谢谢!!!本来是个很简单的问题。
unit Unit1;
interface
uses
unit2,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
unit2.qqq;
end;
end.
------------------------------
unit Unit2;
interface
implementation
procedure qqq;
begin
form1.edit1.text:='ppp';//此句出错,找不到form1 。
end;
end.

 
两个Unit单元可以对同一个form窗体进行操作吗?
例如:Form窗体上有个edit1。我希望在主单元unit1中
包含"unit2.myfrind" 语句。
在unite2单元中包含
"procedure myfrind
form1.edit1.text:='大龙' "语句。
怎样实现?请给个例程。谢谢!!!
如果在 unit1 的 uses 中加上unit2,则出错提
示:unit2中的form1无定义。
如果在 unit2的 uses 中加上 unit1,则出错提
示:unit1 中的unit2无定义 。
如果在 unit1 的uses 中加上 unit2,
在 unit2 的uses 中加上unit1,则出错提
示:相互调用。
当两个人共同编写一个程序时,会遇到类似的问
题。这时每个人写一个独立的unit程序,unit之间可以
相互调用。
大虾们是怎样实现的?急,谢谢!!


 
两个Unit单元可以对同一个form窗体进行操作吗?
例如:Form窗体上有个edit1。我希望在主单元unit1中
包含"unit2.myfrind" 语句。
在unite2单元中包含
"procedure myfrind
form1.edit1.text:='大龙' "语句。
怎样实现?请给个例程。谢谢!!!
如果在 unit1 的 uses 中加上unit2,则出错提
示:unit2中的form1无定义。
如果在 unit2的 uses 中加上 unit1,则出错提
示:unit1 中的unit2无定义 。
如果在 unit1 的uses 中加上 unit2,
在 unit2 的uses 中加上unit1,则出错提
示:相互调用。
当两个人合作共同编写一个程序时,会遇到类似的问
题。这时每个人写一个独立的unit程序,unit之间可以
相互调用。
大虾们是怎样实现的?急,谢谢!!


 
两个Unit单元可以对同一个form窗体进行操作吗?
例如:Form窗体上有个edit1。我希望在主单元unit1中
包含"unit2.myfrind" 语句。
在unite2单元中包含
"procedure myfrind
form1.edit1.text:='大龙' "语句。
怎样实现?请给个例程。谢谢!!!
如果在 unit1 的 uses 中加上unit2,则出错提
示:unit2中的form1无定义。
如果在 unit2的 uses 中加上 unit1,则出错提
示:unit1 中的unit2无定义 。
如果在 unit1 的uses 中加上 unit2,
在 unit2 的uses 中加上unit1,则出错提
示:相互调用。
当两个人合作共同编写一个程序时,会遇到类似的问
题。这时每个人写一个独立的unit程序,unit之间可以
相互调用。
大虾们是怎样实现两个人合作编写一个程序的?
怎样吧一个程序分成两部分?急,谢谢!!
给点提示性回答也可以。


 
try add 'unit1' in unit2,but not in 'uses' ,you should add in 'interface'
example:
unit Unit2;
interface
uses //add this and try
unit1;

implementation
end.

 
两个Unit单元可以对同一个form窗体进行操作吗?
例如:Form窗体上有个edit1。我希望在主单元unit1中
包含"unit2.myfrind" 语句。
在unite2单元中包含
"procedure myfrind
form1.edit1.text:='大龙' "语句。
怎样实现?请给个例程。谢谢!!!
如果在 unit1 的 uses 中加上unit2,则出错提
示:unit2中的form1无定义。
如果在 unit2的 uses 中加上 unit1,则出错提
示:unit1 中的unit2无定义 。
如果在 unit1 的uses 中加上 unit2,
在 unit2 的uses 中加上unit1,则出错提
示:相互调用。
当两个人合作共同编写一个程序时,会遇到类似的问
题。这时每个人写一个独立的unit程序,unit之间可以
相互调用。
大虾们是怎样实现两个人合作编写一个程序的?
怎样吧一个程序分成两部分?急,谢谢!!
给点提示性回答也可以。


 
try add 'unit1' in unit2,but not in 'uses' ,you should add in 'interface'
example:
unit Unit2;
interface
uses //add this and try
unit1;

implementation
end.

 
try add 'unit1' in unit2,but not in 'uses' ,you should add in 'interface'
example:
unit Unit2;
interface
uses //add this and try
unit1;

implementation
end.

 
两个Unit单元可以对同一个form窗体进行操作吗?
例如:Form窗体上有个edit1。我希望在主单元unit1中
包含"unit2.myfrind" 语句。
在unite2单元中包含
"procedure myfrind
form1.edit1.text:='大龙' "语句。
怎样实现?请给个例程。谢谢!!!
如果在 unit1 的 uses 中加上unit2,则出错提
示:unit2中的form1无定义。
如果在 unit2的 uses 中加上 unit1,则出错提
示:unit1 中的unit2无定义 。
如果在 unit1 的uses 中加上 unit2,
在 unit2 的uses 中加上unit1,则出错提
示:相互调用。
当两个人合作共同编写一个程序时,会遇到类似的问
题。这时每个人写一个独立的unit程序,unit之间可以
相互调用。
大虾们怎样实现两个人合作编写一个程序?
怎样吧一个程序分成两部分分别编写?急,谢谢!!
给点提示性回答也可以。


 
我K!你们两个干嘛?重复发了多次还是一样的??
 
大富豪速度太慢,多按了几次按钮,抱歉!!!
 
me too
sorry
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses unit2;
//在此处加入Unit2就行了
{$R *.DFM}
 
谢谢wind2000!!!
按照wind2000的方法可以搞定。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
918
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
顶部 底部