2016-08-22 1 views
3

아이콘의 목적은 정확히 무엇입니까? 스크롤 박스 (예를 들어)의 모든 컨트롤의 컨테이너 인 TContent에서 사용되는 것을 알고 있지만 실제로 사용하는 이유를 이해할 수 없습니까? 그것은 무엇을 목적으로합니까? 언제 그것을 사용하고 그것을 사용하지?델파이 : 아이콘의 목적은 무엇입니까?

은 내가

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의 경우) 스크롤 박스에 대한 변경됩니다 무엇을 이해하지 못하는 델파이 소스에서 이러한 기능을 참조하십시오.

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는 제어에 포함 된 모든 하위 제어를 열거하고 사용자가 제공하는 기능에 해당 어린이에 대한 참조를 전달한다.
컨트롤이 부모를 하나만 가질 수 있다는 것을 제외하고는 Parent과 동일하므로 열거 할 필요가 없습니다.

관련 문제