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 80 by tony, Mon Jan 1 11:31:07 2018 UTC vs.
Revision 217 by tony, Fri Mar 16 10:27:26 2018 UTC

# Line 88 | Line 88 | type
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;
# Line 111 | Line 113 | type
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);
# Line 167 | Line 171 | type
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;
# Line 325 | Line 331 | end;
331   { TIBTreeView }
332  
333   procedure TIBTreeView.ActiveChanged(Sender: TObject);
328 var AtTopLevel: boolean;
334   begin
335    if (csDesigning in ComponentState) then Exit;
336    IBControlLinkChanged;
# Line 336 | Line 341 | begin
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
# Line 360 | Line 364 | 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
# Line 377 | Line 388 | end;
388  
389   procedure TIBTreeView.DataSetChanged(Sender: TObject);
390   begin
391 < //  Reinitialise
391 > //  Do nothing;
392   end;
393  
394   function TIBTreeView.GetDataSet: TDataSet;
# Line 446 | Line 457 | begin
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);
# Line 475 | Line 500 | begin
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;
# Line 482 | Line 514 | begin
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;
# Line 569 | Line 608 | begin
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);
# Line 631 | Line 673 | begin
673      FExpandNode := Node;
674      DataSet.Active := false;
675      DataSet.Active := true;
676 <    if assigned(Selected) then
635 <      ScrollToNode(TIBTreeNode(Selected))
676 >    Selected := Node;
677    end;
678   end;
679  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines