ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/journaling/ibcontrols/IBTreeView.pas
(Generate patch)

Comparing ibx/trunk/ibcontrols/IBTreeView.pas (file contents):
Revision 23 by tony, Fri Mar 13 10:26:52 2015 UTC vs.
Revision 80 by tony, Mon Jan 1 11:31:07 2018 UTC

# Line 31 | Line 31 | interface
31  
32   uses
33    Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ComCtrls,
34 <  DB, IBSQLParser;
34 >  DB, IBSQLParser, IBCustomDataSet;
35  
36   type
37    {
# Line 52 | Line 52 | type
52      FOwner: TIBTreeView;
53    protected
54      procedure ActiveChanged; override;
55    procedure DataEvent(Event: TDataEvent; Info: Ptrint); override;
55      procedure DataSetChanged; override;
56      procedure RecordChanged(Field: TField); override;
57      procedure UpdateData; override;
# Line 60 | Line 59 | type
59      constructor Create(AOwner: TIBTreeView);
60    end;
61  
62 +  { TIBTreeViewControlLink }
63 +
64 +  TIBTreeViewControlLink = class(TIBControlLink)
65 +  private
66 +    FOwner: TIBTreeView;
67 +  protected
68 +    procedure UpdateSQL(Sender: TObject); override;
69 +    procedure UpdateParams(Sender: TObject); override;
70 +  public
71 +    constructor Create(AOwner: TIBTreeView);
72 +  end;
73 +
74    { TIBTreeNode }
75  
76    TIBTreeNode = class(TTreeNode)
77    private
78      FKeyValue: variant;
79    public
80 +    constructor Create(AnOwner: TTreeNodes); override;
81      procedure DeleteAll;
82      property KeyValue: variant read FKeyValue;
83    end;
# Line 74 | Line 86 | type
86    private
87      { Private declarations }
88      FDataLink: TIBTreeViewDatalink;
89 +    FIBTreeViewControlLink: TIBTreeViewControlLink;
90      FHasChildField: string;
91      FKeyField: string;
92      FTextField: string;
# Line 93 | Line 106 | type
106      function GetDataSource: TDataSource;
107      function GetRelationNameQualifier: string;
108      function GetSelectedKeyValue: variant;
109 +    procedure IBControlLinkChanged;
110      procedure NodeMoved(Node: TTreeNode);
111      procedure NodeUpdated(Node: TTreeNode);
112      procedure RecordChanged(Sender: TObject; Field: TField);
# Line 121 | Line 135 | type
135      { Public declarations }
136      constructor Create(TheComponent: TComponent); override;
137      destructor Destroy; override;
138 <    function FindNode(KeyValuePath: array of variant; SelectNode: boolean): TIBTreeNode; overload;
138 >    function FindNode(KeyValuePath: TVariantArray; SelectNode: boolean): TIBTreeNode; overload;
139      function FindNode(KeyValue: variant): TIBTreeNode; overload;
140      function GetNodePath(Node: TTreeNode): TVariantArray;
141      property DataSet: TDataSet read GetDataSet;
# Line 232 | Line 246 | type
246  
247   implementation
248  
249 < uses IBQuery,IBCustomDataSet, Variants;
249 > uses IBQuery,Variants;
250  
251   function StrIntListToVar(s: string): TVariantArray;
252   var i, idx: integer;
# Line 268 | Line 282 | begin
282          raise Exception.Create('Ordinal Type Expected when converting to integer string');
283   end;
284  
285 + { TIBTreeViewControlLink }
286 +
287 + constructor TIBTreeViewControlLink.Create(AOwner: TIBTreeView);
288 + begin
289 +  inherited Create;
290 +  FOwner := AOwner;
291 + end;
292 +
293 + procedure TIBTreeViewControlLink.UpdateParams(Sender: TObject);
294 + begin
295 +  FOwner.UpdateParams(self,TIBParserDataSet(Sender).Parser)
296 + end;
297 +
298 + procedure TIBTreeViewControlLink.UpdateSQL(Sender: TObject);
299 + begin
300 +  FOwner.UpdateSQL(self,TIBParserDataSet(Sender).Parser)
301 + end;
302 +
303   { TIBTreeNode }
304  
305 + constructor TIBTreeNode.Create(AnOwner: TTreeNodes);
306 + begin
307 +  inherited Create(AnOwner);
308 +  FKeyValue := NULL;
309 + end;
310 +
311   procedure TIBTreeNode.DeleteAll;
312   var Node, NextNode: TTreeNode;
313   begin
# Line 290 | Line 328 | procedure TIBTreeView.ActiveChanged(Send
328   var AtTopLevel: boolean;
329   begin
330    if (csDesigning in ComponentState) then Exit;
331 +  IBControlLinkChanged;
332    if assigned(DataSet) and not DataSet.Active then
333    begin
334      if not assigned(FExpandNode) and not assigned(FUpdateNode) then {must really be closing}
# Line 391 | Line 430 | procedure TIBTreeView.RecordChanged(Send
430   var Node: TIBTreeNode;
431      Destination: TIBTreeNode;
432   begin
433 +  if DataSet.State = dsInsert then Exit;
434 +
435    if assigned(Field) and (Field.FieldName = TextField) then
436    begin
437      Node := FindNode(DataSet.FieldByName(KeyField).AsVariant);
# Line 415 | Line 456 | begin
456        else
457          Destination := FindNode(DataSet.FieldByName(ParentField).AsVariant);
458  
459 <      if Destination = Node.Parent then Exit;
459 >      if (Destination = nil) or (Destination = Node.Parent) then Exit;
460  
461        FUpdating := true;
462        try
# Line 450 | Line 491 | end;
491  
492   procedure TIBTreeView.SetDataSource(AValue: TDataSource);
493   begin
494 <  FDataLink.DataSource := AValue
494 >  FDataLink.DataSource := AValue;
495 >  IBControlLinkChanged;
496   end;
497  
498   procedure TIBTreeView.SetParentField(AValue: string);
# Line 466 | Line 508 | begin
508    if Result then
509    begin
510      if DataSet.Active and (DataSet.RecordCount > 0)
511 <         and (Node.KeyValue = DataSet.FieldByName(KeyField).AsVariant) then Exit;
511 >         and DataSet.Locate(KeyField,Node.KeyValue,[]) then Exit;
512  
513      FUpdateNode := Node;
514      try
# Line 496 | Line 538 | procedure TIBTreeView.UpdateParams(Sende
538   begin
539    if not assigned(FExpandNode) and assigned(FUpdateNode)  then {Scrolling dataset}
540     begin
541 <     if (Sender as TDataLink).DataSet is TIBQuery then
542 <       TIBQuery((Sender as TDataLink).DataSet).ParamByName('IBX_KEY_VALUE').Value :=
541 >     if DataSource.DataSet is TIBQuery then
542 >       TIBQuery(DataSource.DataSet).ParamByName('IBX_KEY_VALUE').Value :=
543           FUpdateNode.KeyValue
544       else
545 <     if (Sender as TDataLink).DataSet is TIBDataSet then
546 <       TIBDataSet((Sender as TDataLink).DataSet).ParamByName('IBX_KEY_VALUE').Value :=
545 >     if DataSource.DataSet is TIBDataSet then
546 >       TIBDataSet(DataSource.DataSet).ParamByName('IBX_KEY_VALUE').Value :=
547           FUpdateNode.KeyValue
548     end
549    else
550    if assigned(FExpandNode) then
551    begin
552 <    if (Sender as TDataLink).DataSet is TIBQuery then
553 <      TIBQuery((Sender as TDataLink).DataSet).ParamByName('IBX_PARENT_VALUE').Value :=
552 >    if DataSource.DataSet is TIBQuery then
553 >      TIBQuery(DataSource.DataSet).ParamByName('IBX_PARENT_VALUE').Value :=
554          TIBTreeNode(FExpandNode).KeyValue
555      else
556 <    if (Sender as TDataLink).DataSet is TIBDataSet then
557 <      TIBDataSet((Sender as TDataLink).DataSet).ParamByName('IBX_PARENT_VALUE').Value :=
556 >    if DataSource.DataSet is TIBDataSet then
557 >      TIBDataSet(DataSource.DataSet).ParamByName('IBX_PARENT_VALUE').Value :=
558          TIBTreeNode(FExpandNode).KeyValue
559    end;
560   end;
# Line 594 | Line 636 | begin
636    end;
637   end;
638  
639 + procedure TIBTreeView.IBControlLinkChanged;
640 + begin
641 +  if assigned(DataSource) and (DataSource.DataSet <> nil) and (DataSource.DataSet is TIBParserDataset) then
642 +    FIBTreeViewControllink.IBDataSet := TIBCustomDataSet(DataSource.DataSet)
643 +  else
644 +    FIBTreeViewControllink.IBDataSet := nil;
645 + end;
646 +
647   procedure TIBTreeView.Loaded;
648   begin
649    inherited Loaded;
650 +  IBControlLinkChanged;
651    Reinitialise
652   end;
653  
# Line 618 | Line 669 | procedure TIBTreeView.Notification(AComp
669   begin
670    inherited Notification(AComponent, Operation);
671    if (Operation = opRemove) and
672 <     (FDataLink <> nil) and (AComponent = DataSource) then DataSource := nil;
672 >     (FDataLink <> nil) and (AComponent = DataSource) then
673 >     DataSource := nil;
674   end;
675  
676   procedure TIBTreeView.Reinitialise;
# Line 632 | Line 684 | constructor TIBTreeView.Create(TheCompon
684   begin
685    inherited Create(TheComponent);
686    FDataLink := TIBTreeViewDatalink.Create(self);
687 +  FIBTreeViewControlLink := TIBTreeViewControlLink.Create(self);
688   end;
689  
690   destructor TIBTreeView.Destroy;
691   begin
692    if assigned(FDataLink) then FDataLink.Free;
693 +  if assigned(FIBTreeViewControlLink) then FIBTreeViewControlLink.Free;
694    inherited Destroy;
695   end;
696  
697 < function TIBTreeView.FindNode(KeyValuePath: array of variant;
698 <  SelectNode: boolean): TIBTreeNode;
697 > function TIBTreeView.FindNode(KeyValuePath: TVariantArray; SelectNode: boolean
698 >  ): TIBTreeNode;
699   var Node: TTreeNode;
700      i,j: integer;
701   begin
702    Result := nil;
703 +  if Length(KeyValuePath) = 0 then Exit;
704 +
705    FLocatingNode := true;
706    try
707     for j := 0 to Items.TopLvlCount - 1 do
# Line 655 | Line 711 | begin
711      Node.Expand(false);
712      while assigned(Node)  do
713      begin
714 <      if TIBTreeNode(Node).KeyValue = KeyValuePath[i] then
714 >      if not VarIsNull(TIBTreeNode(Node).KeyValue) and
715 >                        (TIBTreeNode(Node).KeyValue = KeyValuePath[i]) then
716        begin
717          Inc(i);
718          if i = Length(KeyValuePath) then
# Line 733 | Line 790 | begin
790    FOwner.ActiveChanged(self)
791   end;
792  
736 procedure TIBTreeViewDatalink.DataEvent(Event: TDataEvent; Info: Ptrint);
737 begin
738  if (Event = deCheckBrowseMode) and (Info = 1) and not DataSet.Active then
739  begin
740    if (DataSet is TIBDataSet) then
741      FOwner.UpdateSQL(self,TIBDataSet(DataSet).Parser)
742    else
743    if (DataSet is TIBQuery) then
744      FOwner.UpdateSQL(self,TIBQuery(DataSet).Parser)
745  end
746  else
747  if (Event = deCheckBrowseMode) and (Info = 2) and not DataSet.Active then
748  begin
749    if (DataSet is TIBDataSet) then
750      FOwner.UpdateParams(self,TIBDataSet(DataSet).Parser)
751    else
752    if (DataSet is TIBQuery) then
753      FOwner.UpdateParams(self,TIBQuery(DataSet).Parser)
754  end
755  else
756    inherited DataEvent(Event, Info);
757 end;
758
793   procedure TIBTreeViewDatalink.DataSetChanged;
794   begin
795    FOwner.DataSetChanged(self)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines