Recent

Author Topic: ZedDBTreeView - issue  (Read 2589 times)

Snoopy_jb

  • Newbie
  • Posts: 1
ZedDBTreeView - issue
« on: September 02, 2013, 12:15:55 pm »
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: [Select]
(******************************************************************************
* 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;


My table looks like this:
id pid name

main root node has pid field as null.

magno.gst

  • Newbie
  • Posts: 1
Re: ZedDBTreeView - issue
« Reply #1 on: January 01, 2014, 01:56:18 am »
Hi.
I registered just to answer your call.

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

Code: [Select]


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;   


I attached the fixed zeddbtreeview.pas.

Cheers o/
« Last Edit: January 01, 2014, 02:12:38 am by magno.gst »

 

TinyPortal © 2005-2018