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 |
366 |
|
DataSet.First; |
367 |
|
while not DataSet.EOF do |
368 |
|
begin |
369 |
< |
Node := Items.AddChild(FExpandNode,DataSet.FieldByName(TextField).AsString); |
370 |
< |
TIBTreeNode(Node).FKeyValue := DataSet.FieldByName(KeyField).AsVariant; |
371 |
< |
Node.HasChildren := (HasChildField = '') or (DataSet.FieldByName(HasChildField).AsInteger <> 0); |
372 |
< |
Inc(ChildCount); |
369 |
> |
if (FExpandNode = nil) or (TIBTreeNode(FExpandNode).KeyValue <> DataSet.FieldByName(KeyField).AsVariant) then |
370 |
> |
begin |
371 |
> |
Node := Items.AddChild(FExpandNode,DataSet.FieldByName(TextField).AsString); |
372 |
> |
if ImageIndexField <> '' then |
373 |
> |
Node.ImageIndex := DataSet.FieldByName(ImageIndexField).AsInteger; |
374 |
> |
if SelectedIndexField <> '' then |
375 |
> |
Node.SelectedIndex := DataSet.FieldByName(SelectedIndexField).AsInteger; |
376 |
> |
TIBTreeNode(Node).FKeyValue := DataSet.FieldByName(KeyField).AsVariant; |
377 |
> |
Node.HasChildren := (HasChildField = '') or (DataSet.FieldByName(HasChildField).AsInteger <> 0); |
378 |
> |
Inc(ChildCount); |
379 |
> |
end; |
380 |
|
DataSet.Next |
381 |
|
end; |
382 |
|
finally |
390 |
|
|
391 |
|
procedure TIBTreeView.DataSetChanged(Sender: TObject); |
392 |
|
begin |
393 |
< |
// Reinitialise |
393 |
> |
// Do nothing; |
394 |
|
end; |
395 |
|
|
396 |
|
function TIBTreeView.GetDataSet: TDataSet; |
459 |
|
end; |
460 |
|
end |
461 |
|
else |
462 |
+ |
if assigned(Field) and (Field.FieldName = ImageIndexField) then |
463 |
+ |
begin |
464 |
+ |
Node := FindNode(DataSet.FieldByName(KeyField).AsVariant); |
465 |
+ |
if assigned(Node) then |
466 |
+ |
begin |
467 |
+ |
FUpdating := true; |
468 |
+ |
try |
469 |
+ |
Node.ImageIndex := Field.AsInteger |
470 |
+ |
finally |
471 |
+ |
FUpdating := false |
472 |
+ |
end; |
473 |
+ |
end; |
474 |
+ |
end |
475 |
+ |
else |
476 |
|
if assigned(Field) and (Field.FieldName = ParentField) then |
477 |
|
begin |
478 |
|
Node := FindNode(DataSet.FieldByName(KeyField).AsVariant); |
483 |
|
else |
484 |
|
Destination := FindNode(DataSet.FieldByName(ParentField).AsVariant); |
485 |
|
|
486 |
< |
if Destination = Node.Parent then Exit; |
486 |
> |
if (Destination = nil) or (Destination = Node.Parent) then Exit; |
487 |
|
|
488 |
|
FUpdating := true; |
489 |
|
try |
502 |
|
Reinitialise |
503 |
|
end; |
504 |
|
|
505 |
+ |
procedure TIBTreeView.SetImageIndexField(AValue: string); |
506 |
+ |
begin |
507 |
+ |
if FImageIndexField = AValue then Exit; |
508 |
+ |
FImageIndexField := AValue; |
509 |
+ |
Reinitialise |
510 |
+ |
end; |
511 |
+ |
|
512 |
|
procedure TIBTreeView.SetKeyField(AValue: string); |
513 |
|
begin |
514 |
|
if FKeyField = AValue then Exit; |
516 |
|
Reinitialise |
517 |
|
end; |
518 |
|
|
519 |
+ |
procedure TIBTreeView.SetSelectedIndexField(AValue: string); |
520 |
+ |
begin |
521 |
+ |
if FSelectedIndexField = AValue then Exit; |
522 |
+ |
FSelectedIndexField := AValue; |
523 |
+ |
Reinitialise; |
524 |
+ |
end; |
525 |
+ |
|
526 |
|
procedure TIBTreeView.SetTextField(AValue: string); |
527 |
|
begin |
528 |
|
if FTextField = AValue then Exit; |
549 |
|
if Result then |
550 |
|
begin |
551 |
|
if DataSet.Active and (DataSet.RecordCount > 0) |
552 |
< |
and (Node.KeyValue = DataSet.FieldByName(KeyField).AsVariant) then Exit; |
552 |
> |
and DataSet.Locate(KeyField,Node.KeyValue,[]) then Exit; |
553 |
|
|
554 |
|
FUpdateNode := Node; |
555 |
|
try |
610 |
|
Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" is null') |
611 |
|
else |
612 |
|
if assigned(FExpandNode) then |
613 |
+ |
begin |
614 |
|
Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" = :IBX_PARENT_VALUE'); |
615 |
+ |
Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_PARENT_VALUE',true); |
616 |
+ |
end; |
617 |
|
end; |
618 |
|
|
619 |
|
procedure TIBTreeView.Added(Node: TTreeNode); |
675 |
|
FExpandNode := Node; |
676 |
|
DataSet.Active := false; |
677 |
|
DataSet.Active := true; |
678 |
< |
if assigned(Selected) then |
628 |
< |
ScrollToNode(TIBTreeNode(Selected)) |
678 |
> |
Selected := Node; |
679 |
|
end; |
680 |
|
end; |
681 |
|
|
737 |
|
inherited Destroy; |
738 |
|
end; |
739 |
|
|
740 |
< |
function TIBTreeView.FindNode(KeyValuePath: array of variant; |
741 |
< |
SelectNode: boolean): TIBTreeNode; |
740 |
> |
function TIBTreeView.FindNode(KeyValuePath: TVariantArray; SelectNode: boolean |
741 |
> |
): TIBTreeNode; |
742 |
|
var Node: TTreeNode; |
743 |
|
i,j: integer; |
744 |
|
begin |
745 |
|
Result := nil; |
746 |
+ |
if Length(KeyValuePath) = 0 then Exit; |
747 |
+ |
|
748 |
|
FLocatingNode := true; |
749 |
|
try |
750 |
|
for j := 0 to Items.TopLvlCount - 1 do |
754 |
|
Node.Expand(false); |
755 |
|
while assigned(Node) do |
756 |
|
begin |
757 |
< |
if TIBTreeNode(Node).KeyValue = KeyValuePath[i] then |
757 |
> |
if not VarIsNull(TIBTreeNode(Node).KeyValue) and |
758 |
> |
(TIBTreeNode(Node).KeyValue = KeyValuePath[i]) then |
759 |
|
begin |
760 |
|
Inc(i); |
761 |
|
if i = Length(KeyValuePath) then |