全局的FORM 变量 找超市进销存系统
form_pub
var
Pubfrm:TForm;
implementation
FROM1 给他付值,
form1
button1Click 中
pubfrm:=form1
FROM2 中调用
pubfrm.query.commandtext:=''select...''
出错,提示 query 没有定义, 但它在 form1 存在啊.
谁能指点指点啊, 谢谢了.
2楼: Pubfrm是TForm类型的,大家知道TForm是一个空白的窗体,里面是没有query控件的!
所以:
1.要把 Pubfrm 定义为 TForm1类型的!
2.if (Pubfrm is TForm1) then
(Pubfrm as TForm1).query.commandtext:=''select...'' 如excel做进销存
3楼: 要引用Form1的变量,需要先引用它的单元:uses Form1的单元文件名
4楼: 单元引用,最好不要直接使用全局变量,实在要使用,也最好通过函数来调用。
5楼: 最好不要用全局变量直接定义
再说TADOQuery控件也没有commandtext
6楼: 谢谢大家,
to royal1442, 但是Pubfrm 也可以从其他 pubfrm:=Tform2 啊.
销售管理软件版7楼: 那就用第二种方法来做,(pubfrm as Tform2)!
8楼: 还是不太明白,下面是整个问题,再给个大概的做法,谢谢哈.
form_pub
var
Pubfrm:TForm;
implementation
FROM1 给他付值,
form1
button1Click 中
pubfrm:=form1
FROM2 给他付值,
form2
button1Click 中
pubfrm:=form2
FROM3 中调用
pubfrm.query.commandtext:=''select...''
9楼: if pubfrm is TForm1 then
(pubfrm as TForm1).query.commandtext:=''select...''
else if pubfrm is TForm2 then
(pubfrm as TForm1).query.commandtext:=''select...''
else
ShowMessage(''未知窗体!呵呵'');
10楼: 在form3中有很多(pubfrm as TForm1).query.commandtext:=''select...''这样的语句并且分布在不同的 button.click 中啊.[:)]
11楼: 那也只能这么写啊!谁叫你调用的窗体不固定呢!
要不你做个过程
procedure TFrom3.ExecuteSQL(ASQLText : string);
begin
if pubfrm is TForm1 then
begin
(pubfrm as TForm1).query.Close;
(pubfrm as TForm1).query.commandtext:=ASQLText;
....
end
else if pubfrm is TForm2 then
begin
(pubfrm as TForm1).query.Close;
(pubfrm as TForm1).query.commandtext:=ASQLText;
....
end
else
ShowMessage(''未知窗体!呵呵'');
end;
然后每个按钮调用此过程,传递一个SQL 语句给过程!
12楼: 对于上面的问题, 没有更好的办法了吗? 如超市进销存系统
13楼: 多人接受答案了。