31 |
|
|
32 |
|
uses |
33 |
|
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ComCtrls, |
34 |
< |
DB, IBSQLParser; |
34 |
> |
DB, IBSQLParser, IBCustomDataSet; |
35 |
|
|
36 |
|
type |
37 |
|
{ |
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; |
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) |
85 |
|
private |
86 |
|
{ Private declarations } |
87 |
|
FDataLink: TIBTreeViewDatalink; |
88 |
+ |
FIBTreeViewControlLink: TIBTreeViewControlLink; |
89 |
|
FHasChildField: string; |
90 |
|
FKeyField: string; |
91 |
|
FTextField: string; |
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); |
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; |
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; |
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} |
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); |
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 |
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); |
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; |
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 |
|
|
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; |
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 |
|
|
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) |