开发环境(Delphi6/ADO/TdxDBGrid/TdxDBEdit)
=========================================我的目的是把一个某表单中的TdxDBTree的Datasource.Dataset 作为另一个编辑表单的各控件的 DataSource.Dataset.然后把这个RecordSet的字段绑字到 各个TdxDBEdit.DataField.以便对记录操作!
但是打开编辑表单后,编辑表单的各编辑控件对绑定的数据不敏感,数据的操作不能在这些控件反应出来. 这些控件的DataField与DataSource都已正确设置.绑定数据源代码
=========================================
procedure TfrmTBASESimpleEditor.loadData;
begin
  AdoSetMaster := TADODataSet(oMainTree.DataSource.Dataset);
end;function  TfrmTBASESimpleEditor.setControlState:boolean;
var
  i ,j: integer;
begin
  result :=true;
  j :=1;  Caption :=sCaption;  LbTitle.Caption := sCaption+'编辑';
  if ADOSetMaster.Active then
  begin
    for i:=0 to oMainTree.ColumnCount-1 do
    begin
      if not oMainTree.Columns[i].Visible  then continue;
      (FindComponent('Label'+intToStr(j)) as TLabel).Caption :=oMainTree.Columns[i].Caption + ':';
      (FindComponent('dxEdit'+intToStr(j)) as TdxDBEdit).DataField :=oMainTree.Columns[i].FieldName;
      (FindComponent('dxEdit'+intToStr(j)) as TdxDBEdit).Enabled :=true;
      j := j+1;
    end;
    while j<=5 do
    begin
      (FindComponent('Label'+intToStr(j)) as TLabel).Visible:=false;
      (FindComponent('dxEdit'+intToStr(j)) as TdxDBEdit).Visible:=false;
      j :=j+1;
    end;
    bRet :=true;
    case vEditorAction of
    eaADD:;
    eaEdit: bsOKNew.Visible :=false;
    eaView:
    begin
      bsSkinPanel1.Enabled  :=false;
      bsOK.Visible          :=false;
      bsOKNew.Visible       :=false;
    end;
    end;
  end
  else
  begin
    bRet :=false;
  end;
end;

解决方案 »

  1.   

    (FindComponent('dxEdit'+intToStr(j)) as TdxDBEdit).DataField :=oMainTree.Columns[i].FieldName;
          (FindComponent('dxEdit'+intToStr(j)) as TdxDBEdit).Enabled :=true;仅仅指定了“DataField”而没有指定“DataSource”啊。
    另,应该事先用变量保存FindComponent的结果,这样一是可以提高程序执行速度,另外是让代码更加条理清楚,也便于以后维护。—————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    —————————————————————————————————
      

  2.   

    问题解决了,是这些控要重新给这些控件的DataSource的Dataset重新赋值。