请教一下大家,我有三个窗口,一个form1,一个form2,另外一个attribform,其中from1和form2中各有一个dbgrideh,而且这二个窗口都有事件打开attribform窗口,现在我想要做的就是,当我show显示attrib窗口,我要知道attribform窗口是从那个窗口打开的,好调用源窗口dbgrideh里的字段名。我在from1,form2打开attribform的事件中写了一条语名:
attribform.ckmc:=窗口名.name;然后在attribform中定义全局变量 :
ckmc:Tform;在attribform的onShow事件中写到:
procedure Tattribform.FormShow(Sender: TObject);
var
i:integer;
begin
combobox1.Clear;
for i:=0 to ckmc.dbgrideh1.Columns.Count-1 do
begin
combobox1.Items.add(distform.DBGridEh1.Columns[i].FieldName);
end
end;
怎么示是错误了。
[Error] attrib.pas(71): Undeclared identifier: 'dbgrideh1'求大家给个方示,谢谢
attribform.ckmc:=窗口名.name;然后在attribform中定义全局变量 :
ckmc:Tform;在attribform的onShow事件中写到:
procedure Tattribform.FormShow(Sender: TObject);
var
i:integer;
begin
combobox1.Clear;
for i:=0 to ckmc.dbgrideh1.Columns.Count-1 do
begin
combobox1.Items.add(distform.DBGridEh1.Columns[i].FieldName);
end
end;
怎么示是错误了。
[Error] attrib.pas(71): Undeclared identifier: 'dbgrideh1'求大家给个方示,谢谢
解决方案 »
- delphi与sql中的代码问题
- DELPH给网页中文本框赋值的问题
- delphi做的程序会破坏操作系统吗
- F7单步执行会出问题
- 有关编辑框输入格式化的问题
- 我是一个刚刚接触报表的,我不知道在delphi中有什么注意的??
- 哪位大哥有免费的词库,或者提供下载地址,提供来源方式也行,谢谢!
- 怎么用代码实现选中Treeview的第N个节点? 怎么返回Treeview的items[N]的文本? (cxj_treeview)
- 如何打印Excel文件?
- 請問HTTP协议的ContentType方法具体有中哪些属性?
- 关于Delphi调用webservices的一个问题,请教
- 新手求助应急,用TTCPBlockSocket或类似,求一函数向一指定的ip、port发送,通过监听返回接收到的数据
dbgrideh1如果是属于Form1的
就得是
ckmc:TForm1;
是属于属于Form2的
就得是
ckmc:TForm2;
而不能笼统的写为
ckmc:TForm;
TForm是个基类肯定不包含dbgrideh1了
attribform.creator:= 'form1'; or 'form2'
attribform.showmodal;
AttribForm := TattribForm.Create(nil);
AttribForm.Tag =1; \\如果是Form2 则Tag的值可设为2
AttribForm.ShowModal;
begin
application.CreateForm(Tattribform,attribform);
attribform.Tag:=1;
attribform.Show;
end;
procedure Tdist_cform.N2Click(Sender: TObject);/////////////这是form2窗口
begin
application.CreateForm(Tattribform,attribform);
attribform.Tag:=2;
attribform.Show;
end;procedure Tattribform.FormShow(Sender: TObject);/////这是attribform窗口的显示事件
var
i:integer;
a:Tdistform;
b:Tdist_cform;
begin
combobox1.Clear;
if attribform.Tag=1 then
begin
for i:=0 to a.dbgrideh1.Columns.Count-1 do
begin
combobox1.Items.add(a.DBGridEh1.Columns[i].FieldName);
end
end
else if attribform.Tag=2 then
begin
for i:=0 to b.dbgrideh1.Columns.Count-1 do
begin
combobox1.Items.add(b.DBGridEh1.Columns[i].FieldName);
end
end
end;
楼上的大侠,我这样写了为什么报错了
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0041E828 in module 'Project1.exe'. Read of address 00000008'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------麻烦你了,谢谢
procedure Tattribform.FormShow(Sender: TObject);
var
i:integer;
a:string;
begin
combobox1.Clear;
a:=distfomr;
for i:=0 to a.dbgrideh1.Columns.Count-1 do
begin
combobox1.Items.add(a.DBGridEh1.Columns[i].FieldName);
end这位高人,你看我这样写跟你的方法是不是一样的,但这样,变量a中根本引用不出dbgrideh,所以就报错
var
i:integer;
a:string;
begin
combobox1.Clear;
a:=distform; //////////// 这里打错了
for i:=0 to a.dbgrideh1.Columns.Count-1 do
begin
combobox1.Items.add(a.DBGridEh1.Columns[i].FieldName);
end纠正一下,上面打错了