2017-03-07 31 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'。精度的缺乏並不能解決問題。 –

相關問題