procedure TForm1.SpeedButtonDelNodeClick(Sender: TObject);
var
n,enm,fn,ln: PVirtualNode;
begin
n := nil;
fn := nil;
ln := nil;
// get the first and last selected node
for enm in StudyStringTree.SelectedNodes do
begin
if not assigned(fn) then fn := enm;
ln := enm;
end;
// find the node to focus after the delete
if assigned(fn) then
if assigned(fn^.PrevSibling) then
n := fn^.prevSibling
else
if assigned(ln^.NextSibling) then
n := ln^.NextSibling
else
n := fn^.Parent;
StudyStringTree.DeleteSelectedNodes;
// restore the focus
if assigned(n) then
FocusNode(StudyStringTree,n);
end;