2017-03-07 30 views
0

我只是想知道什么可能是control.hide/show和control.visible之间是否有区别:= false/true?

TControl.HideTControl.Visible := False

分别

TControl.ShowTControl.Visible := True

之间的区别,如果是有区别的,哪一个是最好的做法?

+0

你为什么不使用调试器跟踪到两个检查? –

+0

我这样做,只是为了找到在'.Show'过程中似乎什么都不做(或者至少我不明白它在做什么)的代码: 'if Parent <> nil then Parent.ShowControl(Self) ;'只是通过所有父母提出而不改变任何东西? –

回答

2

这取决于...你使用的是VCL还是FireMonkey?布兰克已经显示出你的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; 

在这种情况下,改变Visible属性做了很多不同的东西,包括调用显示或隐藏方法。另请注意,在FireMonkey中,TControl的默认显示和隐藏实现实际上是空的。

所以我想说的是与VCL你应该使用显示/隐藏......而与FireMonkey你应该使用可见:=真/假

+0

这有什么不同? VCL还调用SetVisible(通过将属性Visible设置为true)。 – GolezTrol

+0

如果您检查代码,差异是显而易见的。在VCL隐藏/显示中,不仅仅是切换可见...在FireMonkey切换过程中可视化不仅仅是调用隐藏/显示。 – Frazz

2

根据该文件,调用显示/隐藏方法将Visible属性设置为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; 
+0

好吧,这绝对不仅仅是设置'可见:=真',不是吗? –

+0

是的,我在第一次回答之前没有检查VCL代码。所以你应该使用VCL中的Show/Hide作为Frazz说 –

+0

@Jan问题的标题询问关于调用'Hide',但是正文询问关于调用'Show'。精度的缺乏并不能解决问题。 –

相关问题