2016-08-22 12 views
3

アイコンの目的はなんですか?私はそれがスクロールボックスのすべてのコントロールのコンテナであるTContentで使用されていることを知っていますが(私は実際にそれを使用する理由を理解できません)?それは何の目的ですか?いつそれを使用し、それを使用しない?デルファイ:icontentの目的は何ですか?

iは

function TControl.GetAbsoluteClipRect: TRectF; 
var 
    R: TRectF; 
    LControl: TControl; 
    LContent: IContent; 
begin 
    Result := TRectF.Empty; 
    R := AbsoluteRect; 
    if (Root = nil) or not (Root.GetObject is TCommonCustomForm and IntersectRect(R, R, 
    TCommonCustomForm(Root.GetObject).ClientRect)) then 
    begin 
    LControl := ParentControl; 
    while LControl <> nil do 
    begin 
     if LControl.ClipChildren and not (LControl.GetInterface(IContent, LContent) or IntersectRect(R, R, 
     LControl.AbsoluteRect)) then 
     Exit; 
     LControl := LControl.ParentControl; 
    end; 
    Result := R; 
    end; 
end; 


procedure TFmxObject.GetChildren(Proc: TGetChildProc; Root: TComponent); 
var 
    I, J: Integer; 
    Content: IContent; 
begin 
    inherited; 
    if Supports(Self, IContent) then 
    Exit; 
    if FChildren <> nil then 
    for I := 0 to FChildren.Count - 1 do 
    begin 
     if Supports(FChildren[I], IContent, Content) and (Content.ChildrenCount > 0) then 
     begin 
     for J := 0 to Content.ChildrenCount - 1 do 
      if Content.GetObject.Children[J].Stored then 
      Proc(Content.GetObject.Children[J]); 
     end; 
     if FChildren[I].Stored then 
     Proc(FChildren[I]); 
    end; 
end; 


function TFmxObject.GetParentComponent: TComponent; 
var 
    Content: IContent; 
begin 
    if (FParent <> nil) and Supports(FParent, IContent, Content) then 
    Result := Content.Parent 
    else 
    Result := FParent; 
    if (Result = nil) and (FRoot <> nil) then 
    Result := FRoot.GetObject; 
end; 

答えて

4

IContentTContentinterfaceあるicontentを使用しますが、それは(exemple用)スクロールボックスのために変更されます何を理解していないDelphiソースでこれらの関数を参照してください。

TContent = class(TControl, IContent)

これは単にあなたがコントロールのコンテンツへのアクセスを提供します。
渡されているインターフェイスなので、IContentが公開するメソッドにのみアクセスできます。 http://docwiki.embarcadero.com/Libraries/Seattle/en/FMX.Types.IContent_Methods

これはTControlが提供するメソッドのサブセットである:

はここIContentが提供するメソッドの一覧です。
FMXがTControlを渡すと、あまりにも多くのアクセス権が与えられます。

インターフェイスはFMXでは頻繁に使用されますが、VCLではほとんど使用されません。
これは、VCLがDelphi 3でのインターフェイスの導入に先立っているためです。

the purpose of interfaces in Wikipediaで読むことができます。示すコードで

あなたの例、GetChildernコントロールに含まれるすべての子コントロールを列挙し、ユーザ提供の関数にそれらの子供への参照を渡します。
コントロールが親を1つしか持てないことを除けば、Parentと同じです。したがって、列挙は必要ありません。

関連する問題