我只是想知道什麼可能是control.hide/show和control.visible之間是否有區別:= false/true?
TControl.Hide
和TControl.Visible := False
分別
TControl.Show
和TControl.Visible := True
之間的區別,如果是有區別的,哪一個是最好的做法?
我只是想知道什麼可能是control.hide/show和control.visible之間是否有區別:= false/true?
TControl.Hide
和TControl.Visible := False
分別
TControl.Show
和TControl.Visible := True
之間的區別,如果是有區別的,哪一個是最好的做法?
這取決於...你使用的是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你應該使用可見:=真/假
根據該文件,調用顯示/隱藏方法將Visible屬性設置爲True/false,所以我認爲沒有什麼區別...
這是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;
好吧,這絕對不僅僅是設置'可見:=真',不是嗎? –
是的,我在第一次回答之前沒有檢查VCL代碼。所以你應該使用VCL中的Show/Hide作爲Frazz說 –
@Jan問題的標題詢問關於調用'Hide',但是正文詢問關於調用'Show'。精度的缺乏並不能解決問題。 –
你爲什麼不使用調試器跟蹤到兩個檢查? –
我這樣做,只是爲了找到在'.Show'過程中似乎什麼都不做(或者至少我不明白它在做什麼)的代碼: 'if Parent <> nil then Parent.ShowControl(Self) ;'只是通過所有父母提出而不改變任何東西? –