delphi: what the purpose of the icontent?

loki

What exactly the purpose of the icontent ? i know it's used in TContent that is the container of all the controls of a scrollbox (for exemple) but i can't really understand why use it ? whats it's purpose ? when to use it and to not use it ?

i see these function in the delphi source that use icontent but don't understand what it's will change for the scrollbox (for exemple)

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;
Johan

IContent is the interface to TContent.

TContent = class(TControl, IContent)

This simply provides you access to the content of a control.
Because it's an interface that's being passed you only have access to the methods that IContent exposes and nothing else.

Here's a list of the methods IContent provides: http://docwiki.embarcadero.com/Libraries/Seattle/en/FMX.Types.IContent_Methods

This is a subset of the methods TControl provides.
If FMX were to pass a TControl it would give you too much access.

Interfaces are heavily used in FMX, but rarely in VCL.
This is because VCL predates the introduction of interfaces in Delphi 3.

You can read up on the purpose of interfaces in Wikipedia.

Your example
In the code shown, GetChildern enumerates all the child controls contained in a control and passes a reference to those children to a user-supplied function.
Same with the Parent except that a control can only have one parent, so no enumeration is needed.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related