77 |
|
private |
78 |
|
FKeyValue: variant; |
79 |
|
public |
80 |
+ |
constructor Create(AnOwner: TTreeNodes); override; |
81 |
|
procedure DeleteAll; |
82 |
|
property KeyValue: variant read FKeyValue; |
83 |
|
end; |
88 |
|
FDataLink: TIBTreeViewDatalink; |
89 |
|
FIBTreeViewControlLink: TIBTreeViewControlLink; |
90 |
|
FHasChildField: string; |
91 |
+ |
FImageIndexField: string; |
92 |
|
FKeyField: string; |
93 |
+ |
FSelectedIndexField: string; |
94 |
|
FTextField: string; |
95 |
|
FParentField: string; |
96 |
|
FExpandNode: TTreeNode; |
113 |
|
procedure NodeUpdated(Node: TTreeNode); |
114 |
|
procedure RecordChanged(Sender: TObject; Field: TField); |
115 |
|
procedure SetHasChildField(AValue: string); |
116 |
+ |
procedure SetImageIndexField(AValue: string); |
117 |
|
procedure SetKeyField(AValue: string); |
118 |
+ |
procedure SetSelectedIndexField(AValue: string); |
119 |
|
procedure SetTextField(AValue: string); |
120 |
|
procedure SetDataSource(AValue: TDataSource); |
121 |
|
procedure SetParentField(AValue: string); |
139 |
|
{ Public declarations } |
140 |
|
constructor Create(TheComponent: TComponent); override; |
141 |
|
destructor Destroy; override; |
142 |
< |
function FindNode(KeyValuePath: array of variant; SelectNode: boolean): TIBTreeNode; overload; |
142 |
> |
function FindNode(KeyValuePath: TVariantArray; SelectNode: boolean): TIBTreeNode; overload; |
143 |
|
function FindNode(KeyValue: variant): TIBTreeNode; overload; |
144 |
|
function GetNodePath(Node: TTreeNode): TVariantArray; |
145 |
|
property DataSet: TDataSet read GetDataSet; |
171 |
|
property Images; |
172 |
|
property Indent; |
173 |
|
property HasChildField: string read FHasChildField write SetHasChildField; |
174 |
+ |
property ImageIndexField: string read FImageIndexField write SetImageIndexField; |
175 |
+ |
property SelectedIndexField: string read FSelectedIndexField write SetSelectedIndexField; |
176 |
|
property KeyField: string read FKeyField write SetKeyField; |
177 |
|
property MultiSelect; |
178 |
|
property MultiSelectStyle; |
308 |
|
|
309 |
|
{ TIBTreeNode } |
310 |
|
|
311 |
+ |
constructor TIBTreeNode.Create(AnOwner: TTreeNodes); |
312 |
+ |
begin |
313 |
+ |
inherited Create(AnOwner); |
314 |
+ |
FKeyValue := NULL; |
315 |
+ |
end; |
316 |
+ |
|
317 |
|
procedure TIBTreeNode.DeleteAll; |
318 |
|
var Node, NextNode: TTreeNode; |
319 |
|
begin |
331 |
|
{ TIBTreeView } |
332 |
|
|
333 |
|
procedure TIBTreeView.ActiveChanged(Sender: TObject); |
321 |
– |
var AtTopLevel: boolean; |
334 |
|
begin |
335 |
|
if (csDesigning in ComponentState) then Exit; |
336 |
|
IBControlLinkChanged; |
341 |
|
end |
342 |
|
else |
343 |
|
begin |
332 |
– |
AtTopLevel := Items.TopLvlCount = 0; |
344 |
|
AddNodes; |
345 |
|
if not FLocatingNode and (Selected = nil) and (Items.TopLvlCount > 0) then |
346 |
|
begin |
364 |
|
DataSet.First; |
365 |
|
while not DataSet.EOF do |
366 |
|
begin |
367 |
< |
Node := Items.AddChild(FExpandNode,DataSet.FieldByName(TextField).AsString); |
368 |
< |
TIBTreeNode(Node).FKeyValue := DataSet.FieldByName(KeyField).AsVariant; |
369 |
< |
Node.HasChildren := (HasChildField = '') or (DataSet.FieldByName(HasChildField).AsInteger <> 0); |
370 |
< |
Inc(ChildCount); |
367 |
> |
if (FExpandNode = nil) or (TIBTreeNode(FExpandNode).KeyValue <> DataSet.FieldByName(KeyField).AsVariant) then |
368 |
> |
begin |
369 |
> |
Node := Items.AddChild(FExpandNode,DataSet.FieldByName(TextField).AsString); |
370 |
> |
if ImageIndexField <> '' then |
371 |
> |
Node.ImageIndex := DataSet.FieldByName(ImageIndexField).AsInteger; |
372 |
> |
if SelectedIndexField <> '' then |
373 |
> |
Node.SelectedIndex := DataSet.FieldByName(SelectedIndexField).AsInteger; |
374 |
> |
TIBTreeNode(Node).FKeyValue := DataSet.FieldByName(KeyField).AsVariant; |
375 |
> |
Node.HasChildren := (HasChildField = '') or (DataSet.FieldByName(HasChildField).AsInteger <> 0); |
376 |
> |
Inc(ChildCount); |
377 |
> |
end; |
378 |
|
DataSet.Next |
379 |
|
end; |
380 |
|
finally |
388 |
|
|
389 |
|
procedure TIBTreeView.DataSetChanged(Sender: TObject); |
390 |
|
begin |
391 |
< |
// Reinitialise |
391 |
> |
// Do nothing; |
392 |
|
end; |
393 |
|
|
394 |
|
function TIBTreeView.GetDataSet: TDataSet; |
457 |
|
end; |
458 |
|
end |
459 |
|
else |
460 |
+ |
if assigned(Field) and (Field.FieldName = ImageIndexField) then |
461 |
+ |
begin |
462 |
+ |
Node := FindNode(DataSet.FieldByName(KeyField).AsVariant); |
463 |
+ |
if assigned(Node) then |
464 |
+ |
begin |
465 |
+ |
FUpdating := true; |
466 |
+ |
try |
467 |
+ |
Node.ImageIndex := Field.AsInteger |
468 |
+ |
finally |
469 |
+ |
FUpdating := false |
470 |
+ |
end; |
471 |
+ |
end; |
472 |
+ |
end |
473 |
+ |
else |
474 |
|
if assigned(Field) and (Field.FieldName = ParentField) then |
475 |
|
begin |
476 |
|
Node := FindNode(DataSet.FieldByName(KeyField).AsVariant); |
481 |
|
else |
482 |
|
Destination := FindNode(DataSet.FieldByName(ParentField).AsVariant); |
483 |
|
|
484 |
< |
if Destination = Node.Parent then Exit; |
484 |
> |
if (Destination = nil) or (Destination = Node.Parent) then Exit; |
485 |
|
|
486 |
|
FUpdating := true; |
487 |
|
try |
500 |
|
Reinitialise |
501 |
|
end; |
502 |
|
|
503 |
+ |
procedure TIBTreeView.SetImageIndexField(AValue: string); |
504 |
+ |
begin |
505 |
+ |
if FImageIndexField = AValue then Exit; |
506 |
+ |
FImageIndexField := AValue; |
507 |
+ |
Reinitialise |
508 |
+ |
end; |
509 |
+ |
|
510 |
|
procedure TIBTreeView.SetKeyField(AValue: string); |
511 |
|
begin |
512 |
|
if FKeyField = AValue then Exit; |
514 |
|
Reinitialise |
515 |
|
end; |
516 |
|
|
517 |
+ |
procedure TIBTreeView.SetSelectedIndexField(AValue: string); |
518 |
+ |
begin |
519 |
+ |
if FSelectedIndexField = AValue then Exit; |
520 |
+ |
FSelectedIndexField := AValue; |
521 |
+ |
Reinitialise; |
522 |
+ |
end; |
523 |
+ |
|
524 |
|
procedure TIBTreeView.SetTextField(AValue: string); |
525 |
|
begin |
526 |
|
if FTextField = AValue then Exit; |
547 |
|
if Result then |
548 |
|
begin |
549 |
|
if DataSet.Active and (DataSet.RecordCount > 0) |
550 |
< |
and (Node.KeyValue = DataSet.FieldByName(KeyField).AsVariant) then Exit; |
550 |
> |
and DataSet.Locate(KeyField,Node.KeyValue,[]) then Exit; |
551 |
|
|
552 |
|
FUpdateNode := Node; |
553 |
|
try |
608 |
|
Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" is null') |
609 |
|
else |
610 |
|
if assigned(FExpandNode) then |
611 |
+ |
begin |
612 |
|
Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" = :IBX_PARENT_VALUE'); |
613 |
+ |
Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_PARENT_VALUE',true); |
614 |
+ |
end; |
615 |
|
end; |
616 |
|
|
617 |
|
procedure TIBTreeView.Added(Node: TTreeNode); |
673 |
|
FExpandNode := Node; |
674 |
|
DataSet.Active := false; |
675 |
|
DataSet.Active := true; |
676 |
< |
if assigned(Selected) then |
628 |
< |
ScrollToNode(TIBTreeNode(Selected)) |
676 |
> |
Selected := Node; |
677 |
|
end; |
678 |
|
end; |
679 |
|
|
735 |
|
inherited Destroy; |
736 |
|
end; |
737 |
|
|
738 |
< |
function TIBTreeView.FindNode(KeyValuePath: array of variant; |
739 |
< |
SelectNode: boolean): TIBTreeNode; |
738 |
> |
function TIBTreeView.FindNode(KeyValuePath: TVariantArray; SelectNode: boolean |
739 |
> |
): TIBTreeNode; |
740 |
|
var Node: TTreeNode; |
741 |
|
i,j: integer; |
742 |
|
begin |
743 |
|
Result := nil; |
744 |
+ |
if Length(KeyValuePath) = 0 then Exit; |
745 |
+ |
|
746 |
|
FLocatingNode := true; |
747 |
|
try |
748 |
|
for j := 0 to Items.TopLvlCount - 1 do |
752 |
|
Node.Expand(false); |
753 |
|
while assigned(Node) do |
754 |
|
begin |
755 |
< |
if TIBTreeNode(Node).KeyValue = KeyValuePath[i] then |
755 |
> |
if not VarIsNull(TIBTreeNode(Node).KeyValue) and |
756 |
> |
(TIBTreeNode(Node).KeyValue = KeyValuePath[i]) then |
757 |
|
begin |
758 |
|
Inc(i); |
759 |
|
if i = Length(KeyValuePath) then |