Forum > Databases

ZedDBTreeView - issue

(1/1)

Snoopy_jb:
Hi,
this component is really great but I found some issue. When my table is empty, everything is ok. When table has some data - parent node, more child nodes etc. it's still ok. But when my table has only one node (parent node) without any child nodes, my program crashes and shows error in this section:


--- Code: ---(******************************************************************************
* Synchronize the tree with database after adding a row directly into DB.
*******************************************************************************)
procedure TZedDBTreeView.CheckAppend;
var
  Node : TZedTreeNode;
begin
  if (DatasetAvailable) and ((FTextDataLink.DataSet.RecordCount - Self.Items.Count) = 1) then
    begin
      Self.BeginUpdate;
      try
       Node := Self.Items.AddNewChild(GetNodeByID(FParentDataLink.Field.AsInteger), FTextDataLink.Field.AsString);
        Node.ID := FTextDataLink.DataSet.FieldByName(FIDField).AsInteger;
        Node.ParentID := FParentDataLink.Field.AsInteger;
      finally
        Self.EndUpdate;
      end;
    end;
end;
--- End code ---


My table looks like this:
id pid name

main root node has pid field as null.

magno.gst:
Hi.
I registered just to answer your call.

I had that problem, resolved by correcting the ZedDBTreeView.CheckAppend method as below.


--- Code: ---

procedure TZedDBTreeView.CheckAppend;
var
  Node      : TZedTreeNode;
  ParentNode: TZedTreeNode;
begin
  if (DatasetAvailable) and ((FTextDataLink.DataSet.RecordCount - Self.Items.Count) = 1) then
    begin
      Self.BeginUpdate;
      try

        ParentNode := nil;
        if Assigned(FParentDataLink.Field) then
        begin
              ParentNode := GetNodeByID(FParentDataLink.Field.AsInteger);
        end;

        Node := Self.Items.AddNewChild(ParentNode, FTextDataLink.Field.AsString);
        Node.ID := FTextDataLink.DataSet.FieldByName(FIDField).AsInteger;

        Node.ParentID := -1;
        if Assigned(FParentDataLink.Field) then
        begin
              Node.ParentID := FParentDataLink.Field.AsInteger;
        end;
      finally
        Self.EndUpdate;
      end;
    end;
end;   


--- End code ---

I attached the fixed zeddbtreeview.pas.

Cheers o/

eldonfsr:
where i can find zedtreeview requiered by ths component

paweld:
@eldonfsr: https://code.google.com/archive/p/zeddbtreeview/downloads

eldonfsr:
Thanks let me learn litte more about dbtree..

Navigation

[0] Message Index

Go to full version