算了不发邮件了.直接贴在这个上面吧.
因为TVirtualStringTree的实例你可以获取.那么它的方法也就可以调用了.
方法如下.
因为这个组件是由包vclide120.bpl提供的.那么TVirtualStringTree的方法就会被BPL导出.
我们只要声明一下就够了.对象的成员方法编译后和普通方法没什么区别,只是塞入一个参数Self作为第一个参数而已.所以TVirtualStringTree的方法我们可以把它转换成普通方法
例如我实际上在使用的时候只用到了下面三个方法
procedure SetExpanded(this : TVirtualStringTree;
Node: PVirtualNode;
Value: Boolean);external 'vclide120.bpl' name '@Idevirtualtrees@TBaseVirtualTree@SetExpanded$qqrp28Idevirtualtrees@TVirtualNodeo';
function GetNodeAt(this : TVirtualStringTree;
X, Y: Integer): PVirtualNode;
external 'vclide120.bpl'
name '@Idevirtualtrees@TBaseVirtualTree@GetNodeAt$qqrii';
function GetText(this : TVirtualStringTree; Node: PVirtualNode; Column: Cardinal): WideString;
external 'vclide120.bpl' name '@Idevirtualtrees@TCustomVirtualStringTree@GetText$qqrp28Idevirtualtrees@TVirtualNodei';
当然这些方法用到的类型都要声明一次.
下面是我用到的类型声明.都是从VirtualTree的源代码中抄过来的.还有我自己用到的声明.
Type
TCheckType = (
ctNone,
ctTriStateCheckBox,
ctCheckBox,
ctRadioButton,
ctButton
);
TCheckState = (
csUncheckedNormal, // unchecked and not pressed
csUncheckedPressed, // unchecked and pressed
csCheckedNormal, // checked and not pressed
csCheckedPressed, // checked and pressed
csMixedNormal, // 3-state check box and not pressed
csMixedPressed // 3-state check box and pressed
);
TVirtualNodeState = (
vsInitialized, // Set after the node has been initialized.
vsChecking, // Node's check state is changing, avoid propagation.
vsCutOrCopy, // Node is selected as cut or copy and paste source.
vsDisabled, // Set if node is disabled.
vsDeleting, // Set when the node is about to be freed.
vsExpanded, // Set if the node is expanded.
vsHasChildren, // Indicates the presence of child nodes without actually setting them.
vsVisible, // Indicate whether the node is visible or not (independant of the expand states of its parents).
vsSelected, // Set if the node is in the current selection.
vsInitialUserData, // Set if (via AddChild or InsertNode) initial user data has been set which requires OnFreeNode.
vsAllChildrenHidden, // Set if vsHasChildren is set and no child node has the vsVisible flag set.
vsClearing, // A node's children are being deleted. Don't register structure change event.
vsMultiline, // Node text is wrapped at the cell boundaries instead of being shorted.
vsHeightMeasured, // Node height has been determined and does not need a recalculation.
vsToggling // Set when a node is expanded/collapsed to prevent recursive calls.
);
TVirtualNodeStates = set of TVirtualNodeState;
PVirtualNode = ^TVirtualNode;
TVirtualNode = packed record
Index, // index of node with regard to its parent
ChildCount: Cardinal; // number of child nodes
NodeHeight: Word; // height in pixels
States: TVirtualNodeStates; // states describing various properties of the node (expanded, initialized etc.)
Align: Byte; // line/button alignment
CheckState: TCheckState; // indicates the current check state (e.g. checked, pressed etc.)
CheckType: TCheckType; // indicates which check type shall be used for this node
Dummy: Byte; // dummy value to fill DWORD boundary
TotalCount, // sum of this node, all of its child nodes and their child nodes etc.
TotalHeight: Cardinal; // height in pixels this node covers on screen including the height of all of its
// children
// Note: Some copy routines require that all pointers (as well as the data area) in a node are
// located at the end of the node! Hence if you want to add new member fields (except pointers to internal
// data) then put them before field Parent.
Parent, // reference to the node's parent (for the root this contains the treeview)
PrevSibling, // link to the node's previous sibling or nil if it is the first node
NextSibling, // link to the node's next sibling or nil if it is the last node
FirstChild, // link to the node's first child...
LastChild: PVirtualNode; // link to the node's last child...
Data: record end; // this is a placeholder, each node gets extra data determined by NodeDataSize
end;
TVTUpdateState = (
usBegin, // The tree just entered the update state (BeginUpdate call for the first time).
usBeginSynch, // The tree just entered the synch update state (BeginSynch call for the first time).
usSynch, // Begin/EndSynch has been called but the tree did not change the update state.
usUpdate, // Begin/EndUpdate has been called but the tree did not change the update state.
usEnd, // The tree just left the update state (EndUpdate called for the last level).
usEndSynch // The tree just left the synch update state (EndSynch called for the last level).
);
TVSTTextType = (
ttNormal, // normal label of the node, this is also the text which can be edited
ttStatic // static (non-editable) text after the normal text
);
TVirtualNodeInitState = (
ivsDisabled,
ivsExpanded,
ivsHasChildren,
ivsMultiline,
ivsSelected
);
TVirtualStringTree = class(TCustomControl)
private
FBorderStyle: TBorderStyle;
FHeader: TObject;
FRoot: PVirtualNode;
end;
TVirtualNodeInitStates = set of TVirtualNodeInitState;
TUpdating = procedure (Sender: TVirtualStringTree; State: TVTUpdateState) of object;
TExpanding = procedure (Sender: TVirtualStringTree; Node: PVirtualNode; var Allowed: Boolean) of object;
TInitNode = procedure(Sender: TVirtualStringTree; ParentNode, Node: PVirtualNode;
var InitialStates: TVirtualNodeInitStates) of Object;
TGetText = procedure(Sender: TVirtualStringTree; Node: PVirtualNode; Column: Cardinal; TextType: TVSTTextType;
var Text: WideString) of Object;
const
StructureViewFormClassName = 'TStructureViewForm';
StructureViewFormName = 'StructureViewForm';
VTreeClassName = 'TVirtualStringTree';
var
StructureViewForm : TCustomForm = nil;
procedure SetExpanded(this : TVirtualStringTree;
Node: PVirtualNode;
Value: Boolean);external 'vclide120.bpl' name '@Idevirtualtrees@TBaseVirtualTree@SetExpanded$qqrp28Idevirtualtrees@TVirtualNodeo';
function GetNodeAt(this : TVirtualStringTree;
X, Y: Integer): PVirtualNode;
external 'vclide120.bpl'
name '@Idevirtualtrees@TBaseVirtualTree@GetNodeAt$qqrii';
function GetText(this : TVirtualStringTree; Node: PVirtualNode; Column: Cardinal): WideString;
external 'vclide120.bpl' name '@Idevirtualtrees@TCustomVirtualStringTree@GetText$qqrp28Idevirtualtrees@TVirtualNodei';
|