procedure TDBTreeView_1.AddButtonClick(Sender: TObject);
var
  Node, NewNode: TTreeNode;
  NewCode, NewID: string;
begin
  if FTree.Selected=nil then exit;
  Node:= FTree.Selected.Parent;
  Frm_EditForm:= TFrm_EditForm.Create(Self);
  with Frm_EditForm do
  begin
    Pnl_MCode.Caption:= Node.Text;
    Pnl_Code.Caption:= GetNewCode;
    if ShowModal= mrOK then
    begin
      with TADOQuery(DataSource.DataSet) do
      begin
        LockType:= ltOptimistic;
        DisableControls;
        try
          Append;
          FieldByName(DataField).AsString:= NewID;
          FieldByName(FDataOperation.FMcCode).AsString:= NewCode;
          FieldByName(FDataOperation.FMcData).AsString:= LblEdit_Name.Text;
          UpdateBatch;
          NewNode:= FTree.Items.AddChild(Node, LblEdit_Name.Text)
          end;
          NewNode.SelectedIndex:= 2;
          NewNode.StateIndex:= 1; 
          Showmessage(GetNodeStr(NewNode));//在这里出错,查看数据库,新增数据已经添加到表中,但还是会出现错误,说数据集处于Eof或Bof位置,
        except
        end;
        EnableControls;
      end;
    end;
  end;
end;
function TDBTreeView_1.GetNodeStr(Node: TTreeNode): string;
var
  p: PString;
begin
  if Node= nil then exit;
  p := Node.Data;
  Result := p^;
end;

解决方案 »

  1.   

    UpdateBatch;
    后面 加一个 post  看看
      

  2.   

    或在Showmessage(GetNodeStr(NewNode));//
    前加个
    FTree.setfocus;  
    看看
      

  3.   

    function TDBTreeView_1.GetNodeStr(Node: TTreeNode): string;
    var
      p: PString;
    begin
      if Node= nil then exit;
      p := Node.Data;
      Result := p^;//其实真正的错误是在这里,错误信息:“Project Project1.exe 
                   //raised exception class EAccessViolation with message 
                   //'Access violation at address 0059BA7B in module' Project1.exe'.
                   //Read of address 00000000'.Process stopped. Use Step or Run to continue;
    end;
      

  4.   

    var 
      data:Pstring;
    begin 
    ...
    NewNode:= FTree.Items.AddChild;  
     NewNode.Caption :=Node;
    new(data);
    data := PString(@LblEdit_Name.Text);  
    NewNode.Data := data;
    ... 
      

  5.   

    TO:  DoerSoft
      按你的方法修改了,但还是不行