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 27 by tony, Tue Apr 14 13:10:23 2015 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 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;
# Line 618 | Line 661 | procedure TIBTreeView.Notification(AComp
661   begin
662    inherited Notification(AComponent, Operation);
663    if (Operation = opRemove) and
664 <     (FDataLink <> nil) and (AComponent = DataSource) then DataSource := nil;
664 >     (FDataLink <> nil) and (AComponent = DataSource) then
665 >     DataSource := nil;
666   end;
667  
668   procedure TIBTreeView.Reinitialise;
# Line 632 | Line 676 | constructor TIBTreeView.Create(TheCompon
676   begin
677    inherited Create(TheComponent);
678    FDataLink := TIBTreeViewDatalink.Create(self);
679 +  FIBTreeViewControlLink := TIBTreeViewControlLink.Create(self);
680   end;
681  
682   destructor TIBTreeView.Destroy;
683   begin
684    if assigned(FDataLink) then FDataLink.Free;
685 +  if assigned(FIBTreeViewControlLink) then FIBTreeViewControlLink.Free;
686    inherited Destroy;
687   end;
688  
# Line 733 | Line 779 | begin
779    FOwner.ActiveChanged(self)
780   end;
781  
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
782   procedure TIBTreeViewDatalink.DataSetChanged;
783   begin
784    FOwner.DataSetChanged(self)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines