TTreeView OnClickwith Sender as TTreeView do begin if Selected.Count > 0 then //存在 else //不存在 end;
可否解释一下。 特别是with Sender as TTreeView do中的Sender是作什么用的。
不介意我贴帮助文件吧:PIn an event handler, the Sender parameter indicates which component received the event and therefore called the handler. Sometimes it is useful to have several components share an event handler that behaves differently depending on which component calls it. 上面的相当于procedure TForm1.TreeView1Click(Sender: TObject); begin with TreeView1 do begin if Selected.Count > 0 then //存在 else //不存在 end; end;
一般应该是 if Sender Is TTreeView then with TTreeView(Sender) do
procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode); begin if node.HasChildren then showmessage('有子节点!'); end;
begin
if Selected.Count > 0 then //存在
else //不存在
end;
特别是with Sender as TTreeView do中的Sender是作什么用的。
begin
with TreeView1 do
begin
if Selected.Count > 0 then //存在
else //不存在
end;
end;
if Sender Is TTreeView then
with TTreeView(Sender) do
begin
if node.HasChildren then
showmessage('有子节点!');
end;
呵呵、你说的没错、用TTreeView(Sender)执行效率会快一些:P