for m:=0 to self.ComponentCount-1 do
if self.Components[m].ClassName='TComboBox' then begin
CB := TComboBox(Self.Components[i]);
for j:=0 to adoquery.FieldCount-1 do begin
if trim(adoquery.Fields.Fields[j].DisplayName)='学校' then
cb.ItemIndex:=cb.Items.IndexOfName(adoquery.Fields.Fields[j].DisplayName);
end;
end;运行到第六行时总说访问了非法内存地址,试了一下问题出在cb.Items.IndexOfName上,不让访问,但为什么呢?如何解决?
if self.Components[m].ClassName='TComboBox' then begin
CB := TComboBox(Self.Components[i]);
for j:=0 to adoquery.FieldCount-1 do begin
if trim(adoquery.Fields.Fields[j].DisplayName)='学校' then
cb.ItemIndex:=cb.Items.IndexOfName(adoquery.Fields.Fields[j].DisplayName);
end;
end;运行到第六行时总说访问了非法内存地址,试了一下问题出在cb.Items.IndexOfName上,不让访问,但为什么呢?如何解决?
解决方案 »
- AdoQuery中的InsertRecord用法问题
- 用delphi用calendar控件如何在edit里面显示日期
- 我要WebSnap中文书。
- access表里一字段位单精度类型,小数2位,但在库里2.3的数据显示在dbgrid变成了2.29999993523168这样的数,为什么?
- 如何让dbgrid显示storedproc的返回结果
- 怎样删除多个监视器?
- 怎么抓图可以把windows的开始菜单那一行一起抓进去(在线等待)
- 软件的背景音乐怎么实现
- windows下如何获取系统级按键消息?不用消息钩子。
- 我想这样,如何办
- 请教一个问题?怎样设置stringgrid的字居中!
- 如何将TClientDataSet数据导出到Tadodataset中?
if self.Components[m].ClassName='TComboBox' then begin
CB := TComboBox(Self.Components[m]); //请注意:这里不应是 i 吧, 应是m
=============
for j:=0 to adoquery.FieldCount-1 do begin
if trim(adoquery.Fields.Fields[j].DisplayName)='学校' then
cb.ItemIndex:=cb.Items.IndexOfName(adoquery.Fields.Fields[j].DisplayName);
end;
end;还有一个问题: cb是如何定义的?
if self.Components[m].ClassName='TComboBox' then begin
CB := TComboBox(Self.Components[i]);// <--这里的"i"是不是应该是"m"
var
i: integer;
Cur: integer;
begin
for i := 0 to Self.ComponentCount - 1 do
begin
if Self.Components[i].ClassName='TComboBox' then
begin
Cur := TComboBox(Self.Components[i]).Items.IndexOf('学校');
TComboBox(Self.Components[i]).ItemIndex := Cur;
end;
end;
end;