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 21 by tony, Thu Feb 26 10:33:34 2015 UTC vs.
Revision 39 by tony, Tue May 17 08:14:52 2016 UTC

# Line 15 | Line 15
15   *
16   *  The Initial Developer of the Original Code is Tony Whyman.
17   *
18 < *  The Original Code is (C) 2011 Tony Whyman, MWA Software
18 > *  The Original Code is (C) 2015 Tony Whyman, MWA Software
19   *  (http://www.mwasoftware.co.uk).
20   *
21   *  All Rights Reserved.
# 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)
# Line 74 | Line 85 | type
85    private
86      { Private declarations }
87      FDataLink: TIBTreeViewDatalink;
88 +    FIBTreeViewControlLink: TIBTreeViewControlLink;
89      FHasChildField: string;
90      FKeyField: string;
91      FTextField: string;
# Line 93 | Line 105 | type
105      function GetDataSource: TDataSource;
106      function GetRelationNameQualifier: string;
107      function GetSelectedKeyValue: variant;
108 +    procedure IBControlLinkChanged;
109      procedure NodeMoved(Node: TTreeNode);
110      procedure NodeUpdated(Node: TTreeNode);
111      procedure RecordChanged(Sender: TObject; Field: TField);
# Line 232 | Line 245 | type
245  
246   implementation
247  
248 < uses IBQuery,IBCustomDataSet, Variants;
248 > uses IBQuery,Variants;
249  
250   function StrIntListToVar(s: string): TVariantArray;
251   var i, idx: integer;
# Line 268 | Line 281 | begin
281          raise Exception.Create('Ordinal Type Expected when converting to integer string');
282   end;
283  
284 + { TIBTreeViewControlLink }
285 +
286 + constructor TIBTreeViewControlLink.Create(AOwner: TIBTreeView);
287 + begin
288 +  inherited Create;
289 +  FOwner := AOwner;
290 + end;
291 +
292 + procedure TIBTreeViewControlLink.UpdateParams(Sender: TObject);
293 + begin
294 +  FOwner.UpdateParams(self,TIBParserDataSet(Sender).Parser)
295 + end;
296 +
297 + procedure TIBTreeViewControlLink.UpdateSQL(Sender: TObject);
298 + begin
299 +  FOwner.UpdateSQL(self,TIBParserDataSet(Sender).Parser)
300 + end;
301 +
302   { TIBTreeNode }
303  
304   procedure TIBTreeNode.DeleteAll;
# Line 290 | Line 321 | procedure TIBTreeView.ActiveChanged(Send
321   var AtTopLevel: boolean;
322   begin
323    if (csDesigning in ComponentState) then Exit;
324 +  IBControlLinkChanged;
325    if assigned(DataSet) and not DataSet.Active then
326    begin
327      if not assigned(FExpandNode) and not assigned(FUpdateNode) then {must really be closing}
# Line 391 | Line 423 | procedure TIBTreeView.RecordChanged(Send
423   var Node: TIBTreeNode;
424      Destination: TIBTreeNode;
425   begin
426 +  if DataSet.State = dsInsert then Exit;
427 +
428    if assigned(Field) and (Field.FieldName = TextField) then
429    begin
430      Node := FindNode(DataSet.FieldByName(KeyField).AsVariant);
# Line 415 | Line 449 | begin
449        else
450          Destination := FindNode(DataSet.FieldByName(ParentField).AsVariant);
451  
452 <      if Destination = Node.Parent then Exit;
452 >      if (Destination = nil) or (Destination = Node.Parent) then Exit;
453  
454        FUpdating := true;
455        try
# Line 450 | Line 484 | end;
484  
485   procedure TIBTreeView.SetDataSource(AValue: TDataSource);
486   begin
487 <  FDataLink.DataSource := AValue
487 >  FDataLink.DataSource := AValue;
488 >  IBControlLinkChanged;
489   end;
490  
491   procedure TIBTreeView.SetParentField(AValue: string);
# Line 496 | Line 531 | procedure TIBTreeView.UpdateParams(Sende
531   begin
532    if not assigned(FExpandNode) and assigned(FUpdateNode)  then {Scrolling dataset}
533     begin
534 <     if (Sender as TDataLink).DataSet is TIBQuery then
535 <       TIBQuery((Sender as TDataLink).DataSet).ParamByName('IBX_KEY_VALUE').Value :=
534 >     if DataSource.DataSet is TIBQuery then
535 >       TIBQuery(DataSource.DataSet).ParamByName('IBX_KEY_VALUE').Value :=
536           FUpdateNode.KeyValue
537       else
538 <     if (Sender as TDataLink).DataSet is TIBDataSet then
539 <       TIBDataSet((Sender as TDataLink).DataSet).ParamByName('IBX_KEY_VALUE').Value :=
538 >     if DataSource.DataSet is TIBDataSet then
539 >       TIBDataSet(DataSource.DataSet).ParamByName('IBX_KEY_VALUE').Value :=
540           FUpdateNode.KeyValue
541     end
542    else
543    if assigned(FExpandNode) then
544    begin
545 <    if (Sender as TDataLink).DataSet is TIBQuery then
546 <      TIBQuery((Sender as TDataLink).DataSet).ParamByName('IBX_PARENT_VALUE').Value :=
545 >    if DataSource.DataSet is TIBQuery then
546 >      TIBQuery(DataSource.DataSet).ParamByName('IBX_PARENT_VALUE').Value :=
547          TIBTreeNode(FExpandNode).KeyValue
548      else
549 <    if (Sender as TDataLink).DataSet is TIBDataSet then
550 <      TIBDataSet((Sender as TDataLink).DataSet).ParamByName('IBX_PARENT_VALUE').Value :=
549 >    if DataSource.DataSet is TIBDataSet then
550 >      TIBDataSet(DataSource.DataSet).ParamByName('IBX_PARENT_VALUE').Value :=
551          TIBTreeNode(FExpandNode).KeyValue
552    end;
553   end;
# Line 594 | Line 629 | begin
629    end;
630   end;
631  
632 + procedure TIBTreeView.IBControlLinkChanged;
633 + begin
634 +  if assigned(DataSource) and (DataSource.DataSet <> nil) and (DataSource.DataSet is TIBParserDataset) then
635 +    FIBTreeViewControllink.IBDataSet := TIBCustomDataSet(DataSource.DataSet)
636 +  else
637 +    FIBTreeViewControllink.IBDataSet := nil;
638 + end;
639 +
640   procedure TIBTreeView.Loaded;
641   begin
642    inherited Loaded;
643 +  IBControlLinkChanged;
644    Reinitialise
645   end;
646  
# Line 618 | Line 662 | procedure TIBTreeView.Notification(AComp
662   begin
663    inherited Notification(AComponent, Operation);
664    if (Operation = opRemove) and
665 <     (FDataLink <> nil) and (AComponent = DataSource) then DataSource := nil;
665 >     (FDataLink <> nil) and (AComponent = DataSource) then
666 >     DataSource := nil;
667   end;
668  
669   procedure TIBTreeView.Reinitialise;
# Line 632 | Line 677 | constructor TIBTreeView.Create(TheCompon
677   begin
678    inherited Create(TheComponent);
679    FDataLink := TIBTreeViewDatalink.Create(self);
680 +  FIBTreeViewControlLink := TIBTreeViewControlLink.Create(self);
681   end;
682  
683   destructor TIBTreeView.Destroy;
684   begin
685    if assigned(FDataLink) then FDataLink.Free;
686 +  if assigned(FIBTreeViewControlLink) then FIBTreeViewControlLink.Free;
687    inherited Destroy;
688   end;
689  
# Line 733 | Line 780 | begin
780    FOwner.ActiveChanged(self)
781   end;
782  
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
783   procedure TIBTreeViewDatalink.DataSetChanged;
784   begin
785    FOwner.DataSetChanged(self)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines