首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

Delphi怎么在表格的各列中使用控件名称+变量这样的

2012-07-30 
Delphi如何在表格的各列中使用控件名称+变量这样的我需要得到,常量+变量,这样的控件名,一般的方式是(FindC

Delphi如何在表格的各列中使用控件名称+变量这样的
我需要得到,常量+变量,这样的控件名,一般的方式是

 (FindComponent('Edit'+inttostr(i)) as TEdit).Text := inttostr(i);或者

TEdit(FindComponent('Edit'+inttostr(i)) ).Text := inttostr(i);

但是我需要在一个表格中某列循环检查,表格中的列名都是cxgrdbclmn_+变量,这样的特定形式,但是我在操作时,当我在表格中输入第一个值后,正常,但是输入第二个之后,就出现了下图

代码如下

Delphi(Pascal) code
  for i:=0 to  cxgrdbtblvw_Cartoon.DataController.RecordCount-1 do    begin      if cxgrdbtblvw_Cartoon.DataController.Values[i, TcxGridDBColumn(FindComponent('cxgrdbclmn_'+ScanNameTxt.Text)).Index]=ScanNumTxt.Text then      begin        ShowMessage('此数据在列表中已存在');        ScanNumTxt.Clear;        ScanNumTxt.SetFocus;        Exit;      end;    end;

 

[解决办法]
漏了-1:
Delphi(Pascal) code
var i,itemidx:integer;begin  itemidx:=cxgrdbtblvw_Cartoon.FindItemByName('cxgrdbclmn_'+ScanNameTxt.Text).Index;  for i:=0 to cxgrdbtblvw_Cartoon.DataController.RecordCount-1 do begin    if cxgrdbtblvw_Cartoon.DataController.Values[i,itemidx]=ScanNumTxt.Text then begin      ShowMessage('此数据在列表中已存在');      ScanNumTxt.Clear;      ScanNumTxt.SetFocus;      Exit;    end;  end;end; 

热点排行