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); |
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; |
331 |
|
{ TIBTreeView } |
332 |
|
|
333 |
|
procedure TIBTreeView.ActiveChanged(Sender: TObject); |
328 |
– |
var AtTopLevel: boolean; |
334 |
|
begin |
335 |
|
if (csDesigning in ComponentState) then Exit; |
336 |
|
IBControlLinkChanged; |
341 |
|
end |
342 |
|
else |
343 |
|
begin |
339 |
– |
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 |
> |
Node.HasChildren := (HasChildField = '') or (DataSet.FieldByName(HasChildField).AsInteger <> 0); |
371 |
> |
Inc(ChildCount); |
372 |
> |
end; |
373 |
|
DataSet.Next |
374 |
|
end; |
375 |
|
finally |
383 |
|
|
384 |
|
procedure TIBTreeView.DataSetChanged(Sender: TObject); |
385 |
|
begin |
386 |
< |
// Reinitialise |
386 |
> |
// Do nothing; |
387 |
|
end; |
388 |
|
|
389 |
|
function TIBTreeView.GetDataSet: TDataSet; |
452 |
|
end; |
453 |
|
end |
454 |
|
else |
455 |
+ |
if assigned(Field) and (Field.FieldName = ImageIndexField) then |
456 |
+ |
begin |
457 |
+ |
Node := FindNode(DataSet.FieldByName(KeyField).AsVariant); |
458 |
+ |
if assigned(Node) then |
459 |
+ |
begin |
460 |
+ |
FUpdating := true; |
461 |
+ |
try |
462 |
+ |
Node.ImageIndex := Field.AsInteger |
463 |
+ |
finally |
464 |
+ |
FUpdating := false |
465 |
+ |
end; |
466 |
+ |
end; |
467 |
+ |
end |
468 |
+ |
else |
469 |
|
if assigned(Field) and (Field.FieldName = ParentField) then |
470 |
|
begin |
471 |
|
Node := FindNode(DataSet.FieldByName(KeyField).AsVariant); |
495 |
|
Reinitialise |
496 |
|
end; |
497 |
|
|
498 |
+ |
procedure TIBTreeView.SetImageIndexField(AValue: string); |
499 |
+ |
begin |
500 |
+ |
if FImageIndexField = AValue then Exit; |
501 |
+ |
FImageIndexField := AValue; |
502 |
+ |
Reinitialise |
503 |
+ |
end; |
504 |
+ |
|
505 |
|
procedure TIBTreeView.SetKeyField(AValue: string); |
506 |
|
begin |
507 |
|
if FKeyField = AValue then Exit; |
509 |
|
Reinitialise |
510 |
|
end; |
511 |
|
|
512 |
+ |
procedure TIBTreeView.SetSelectedIndexField(AValue: string); |
513 |
+ |
begin |
514 |
+ |
if FSelectedIndexField = AValue then Exit; |
515 |
+ |
FSelectedIndexField := AValue; |
516 |
+ |
Reinitialise; |
517 |
+ |
end; |
518 |
+ |
|
519 |
|
procedure TIBTreeView.SetTextField(AValue: string); |
520 |
|
begin |
521 |
|
if FTextField = AValue then Exit; |
603 |
|
Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" is null') |
604 |
|
else |
605 |
|
if assigned(FExpandNode) then |
606 |
+ |
begin |
607 |
|
Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FParentField + '" = :IBX_PARENT_VALUE'); |
608 |
+ |
Parser.Add2WhereClause(GetRelationNameQualifier + '"' + FKeyField + '" = :IBX_PARENT_VALUE',true); |
609 |
+ |
end; |
610 |
|
end; |
611 |
|
|
612 |
|
procedure TIBTreeView.Added(Node: TTreeNode); |
613 |
|
begin |
614 |
< |
if assigned(DataSet) and DataSet.Active and not FNoAddNodeToDataset then |
614 |
> |
if assigned(DataSet) and DataSet.Active then |
615 |
|
begin |
616 |
< |
DataSet.Append; |
616 |
> |
if not FNoAddNodeToDataset then |
617 |
> |
begin |
618 |
> |
DataSet.Append; |
619 |
> |
if (Node.Text = '') and not DataSet.FieldByName(TextField).IsNull then |
620 |
> |
Node.Text := DataSet.FieldByName(TextField).AsString; |
621 |
> |
FModifiedNode := TIBTreeNode(Node); |
622 |
> |
FDataLink.UpdateRecord; |
623 |
> |
end; |
624 |
|
TIBTreeNode(Node).FKeyValue := DataSet.FieldByName(KeyField).AsVariant; |
625 |
< |
if (Node.Text = '') and not DataSet.FieldByName(TextField).IsNull then |
626 |
< |
Node.Text := DataSet.FieldByName(TextField).AsString; |
627 |
< |
FModifiedNode := TIBTreeNode(Node); |
628 |
< |
FDataLink.UpdateRecord |
625 |
> |
if ImageIndexField <> '' then |
626 |
> |
Node.ImageIndex := DataSet.FieldByName(ImageIndexField).AsInteger; |
627 |
> |
if SelectedIndexField <> '' then |
628 |
> |
Node.SelectedIndex := DataSet.FieldByName(SelectedIndexField).AsInteger; |
629 |
|
end; |
630 |
|
inherited Added(Node); |
631 |
|
end; |
675 |
|
FExpandNode := Node; |
676 |
|
DataSet.Active := false; |
677 |
|
DataSet.Active := true; |
678 |
< |
if assigned(Selected) then |
635 |
< |
ScrollToNode(TIBTreeNode(Selected)) |
678 |
> |
Selected := Node; |
679 |
|
end; |
680 |
|
end; |
681 |
|
|