我只是想知道
之间可能有什么区别 TControl.Hide
和TControl.Visible := False
和分别
TControl.Show
和TControl.Visible := True
如果有区别,哪个是最佳实践?
,取决于...您使用的是VCL还是FireMonKey?Blanc向您展示了VCL代码...但是FireMonKey做了很大的不同:
procedure TControl.SetVisible(const Value: Boolean);
var
AlignRoot: IAlignRoot;
begin
if FVisible <> Value then
try
if FVisible then
Repaint;
FVisible := Value;
VisibleChanged;
finally
if FVisible then
Show
else
Hide;
// We notify all child controls, that parent changed visibility
AncestorVisibleChanged(FVisible);
if not (csLoading in ComponentState) and (Align <> TAlignLayout.None) then
begin
if FParentControl <> nil then
FParentControl.Realign
else
if not(csLoading in ComponentState) and Supports(Parent, IAlignRoot, AlignRoot) then
AlignRoot.Realign;
end;
if ParentContent <> nil then
ParentContent.Changed;
if FVisible then
begin
RecalcUpdateRect;
Repaint;
TAnimator.StartTriggerAnimation(Self, Self, 'IsVisible');
end
else
ResetFocus;
end;
end;
在这种情况下,更改可见属性会做许多不同的事情,包括调用表演或隐藏方法。另请注意,在Firemonkey中,默认显示和隐藏TCONTROL的实现实际上是空的。
所以我会说,对于VCL,您应该使用show/hide ...而使用firemonkey,您应该使用可见的:= true/fals/false
根据文档,调用show/hide方法将可见属性设置为true/false,所以我认为没有区别...
tcontrol.visible
tcontrol.hide
tcontrol.show
这是VCL代码:
procedure TControl.Hide;
begin
Visible := False;
end;
procedure TControl.Show;
begin
if Parent <> nil then Parent.ShowControl(Self);
if not (csDesigning in ComponentState) or
(csNoDesignVisible in ControlStyle) then Visible := True;
end;