Recent

Author Topic: ZedDBTreeView - issue  (Read 3928 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 »

eldonfsr

  • Hero Member
  • *****
  • Posts: 514
Re: ZedDBTreeView - issue
« Reply #2 on: August 02, 2024, 09:13:04 pm »
where i can find zedtreeview requiered by ths component

paweld

  • Hero Member
  • *****
  • Posts: 1245
Re: ZedDBTreeView - issue
« Reply #3 on: August 02, 2024, 09:27:55 pm »
Best regards / Pozdrawiam
paweld

eldonfsr

  • Hero Member
  • *****
  • Posts: 514
Re: ZedDBTreeView - issue
« Reply #4 on: August 03, 2024, 07:18:13 pm »
Thanks let me learn litte more about dbtree..

 

TinyPortal © 2005-2018