function compare(tree1, tree2): boolean;
var i : integer;
begin
result := true;
if tree1.childCount <> tree2.childCount then
begin
result := false;
exit;
end;
for i:= 0 to tree1.childCount - 1 do
begin
if tree1.child[i].value <> tree2.child[i].value then
result := false
else
result := compare(tree1.child[i], tree2.child[i]);
if result = false then break;
end;
end;