我有两个 VirtualStringTree,第一个 VST 已经填充了数据,我想检查第二个 VST 并添加第一个 VST 中还没有的节点。或者我想从第二个 VST 添加那些不与第一个 VST 重复的节点。
procedure Tcreatevtform.copy2tosimvt(vt: Tvirtualstringtree);
var
data: PMyRec;
simvtdata: PMyRectF;
rootnode, simvtnode: PVirtualNode;
ty: string;
begin
rootnode := vt.GetFirst; //vt is second virtualstringtree
while Assigned(rootnode) do
begin
data := vt.GetNodeData(rootnode);
ty := data^.caption;
if checksimduplicate(ty)=false then
begin
simvtnode := similarvt.AddChild(nil); //similarvt is the first virtualstringtree
simvtdata := similarvt.GetNodeData(simvtnode);
simvtdata^.caption := data^.caption;
end;
rootnode := vt.GetNext(rootnode,false);
end;
end;
function Tcreatevtform.checksimduplicate(t: string): boolean;
var
data: PMyRectf;
rootnode: PVirtualNode;
typew: string;
begin
Result := False;
rootnode := similarvt.GetFirst;
while Assigned(rootnode) do
begin
data := similarvt.GetNodeData(rootnode);
typew := data^.caption; // problem here, typew is always a constant or it is always the first
if t=typew then
begin
// node's caption of vt (letter 'a' is the first node's caption in my
// app. So this function is always false.
Result := True;
Break;
end;
similarvt.GetNext(rootnode, False);
end;
end;
我正在使用 D7。