TcxCustomTreeList.Find(Pointer,TcxTreeListNode,Boolean,Boolean,TcxTreeListFindFunc,Boolean) Method
Searches for a node using the specified criteria and parameters.
Declaration
function Find(AData: Pointer; AStart: TcxTreeListNode; AExpandedOnly: Boolean; AForward: Boolean; AFilter: TcxTreeListFindFunc; AIgnoreStartNode: Boolean = False): TcxTreeListNode; virtual;
Parameters
Name | Type |
---|---|
AData | Pointer |
AStart | TcxTreeListNode |
AExpandedOnly | Boolean |
AForward | Boolean |
AFilter | TcxTreeListFindFunc |
AIgnoreStartNode | Boolean |
Returns
Type |
---|
TcxTreeListNode |
Remarks
AData specifies the search criteria to be forwarded to the TcxTreeListFindFunc function implementation passed as the AFilter parameter. Normally, AData is a reference to the data that helps you identify a matching node by the node Data property value. For instance, if you associated a node with an object via the Data property, you can pass a reference to this object as the AData parameter and compare the reference with a node’s Data property value within the AFilter function as shown (see the code example below).
AStart specifies the starting point of the search. If nil is passed, the search is performed from the beginning of the View.
AExpandedOnly specifies whether child nodes of the expanded parents are included into the search.
AForward specifies the search direction. Set AForward to True, to search forward. Otherwise, a backward search is performed.
AFilter specifies the function (a TcxTreeListFindFunc function implementation) which performs the search based on the AData criteria. This function is called for every node within the search range. If a node matches the AData criteria, the function must return True; otherwise – False.
AIgnoreStartNode specifies whether to ignore a node that matches AStart. Set AIgnoreStartNode to True, to ignore this node.
If the matching node is not found, the Find function returns nil.
The following code example shows how to search for a particular node by an order (a TOrder object) associated with it. An order stored by the FOrder variable is used to initialize the node Data property, and is then passed as the search criteria to the Find function.
var
FOrder: TOrder;
// Creating and initializing the order object.
FOrder := TOrder.Create;
// ...
// Associating a node with the order.
ANode.Data := FOrder;
// ...
// A TcxTreeListFindFunc function implementation.
function MyFilter(ANode: TcxTreeListNode; AData: Pointer): Boolean;
begin
Result := ANode.Data = AData;
end;
// ...
var
ASampleNode: TcxTreeListNode;
// ...
// Searching for the first node associated with the order.
ASampleNode := cxTreeList1.Find(FOrder, nil, False, True, MyFilter);
// ...
// Node manipulations.
// ...
// Handling the tree list OnDeletion event to release the order object
// before the node associated with this object is removed.
// We can safely do this, since no other node is associated with this object.
procedure <Form>.cxTreeList1Deletion(Sender: TcxCustomTreeList;
ANode: TcxTreeListNode);
begin
if ANode.Data <> nil then TOrder(ANode.Data).Free;
end;