unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
PNode = ^TNode;
TNode = record
Node: TTreeNode;
Next: PNode;
end;
type
TForm1 = class(TForm)
tvTree: TTreeView;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
HeadNode,TailNode: PNode;
function GetNode(cNode: TTreeNode): TTreeNode;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
sNode: TTreeNode;
cNode: PNode;
begin
for i := 0 to tvTree.Items.Count - 1do
begin
if tvTree.Items.Item.Selected then
begin
sNode := GetNode(tvTree.Items.Item);
if HeadNode = nil then
begin
New(HeadNode);
HeadNode^.Node := sNode;
HeadNode^.Next := nil;
TailNode := HeadNode;
end
else
begin
New(cNode);
cNode^.Node := sNode;
cNode^.Next := nil;
TailNode := cNode;
end;
end;
end;
end;
function TForm1.GetNode(cNode: TTreeNode): TTreeNode;
var
sNode, iNode: TTreeNode;
begin
Result := nil;
if cNode.Parent = nil then
exit;
if cNode.getFirstChild <> nil then
exit;
sNode := cNode.Parent;
iNode := sNode.getFirstChild;
while iNode <> nildo
begin
if not iNode.Selected then
exit;
iNode := sNode.GetNextChild(iNode);
end;
Result := iNode;
end;
end.
最后形成的链表就是满足条件的接点结合