Announcement

Collapse
No announcement yet.

Forward Deklaration

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Nee, Interfaces sind das Mittel zum Zweck, und COM kann ein Zweck
    sein.<br>
    Hier mal kurz angerissen wie einfach man ein Object mit zugehörigen Interfaces erzeugt:

    <pre>

    type
    TNode = class; <br>

    INodeAccess = interface
    function _Self: TNode;
    end;<br>

    TNode = class(TInterfacedObject, INode, INodeEnum, INodeAccess);
    private
    FParent: INode;
    FChilds: array of INode; // INodes damit autom. dealloziert wird
    // INode
    function INode.Count = GetChildCount; // Count für INode
    function GetChild(Index: Integer): INode;
    function Parent: INode;
    // INodeEnum
    function INodeEnum.Count = GetFullCount; // Count für INodeEnum
    function GetNode(Index: Integer): INode;
    // privates Interface INodeAccess
    function _Self: TNode;
    end;

    function TNode.GetChildCount: Integer;
    begin
    Result := Length(FChilds);
    end;<br>

    function TNode.GetChild(Index: Integer): INode;
    begin
    if (Index < 0) or (Index >= GetChildCount) then
    raise Exception.Create('Index out of Bounds');
    Result := FChilds[Index];
    end;<br>

    function TNode.Parent: INode;
    begin
    Result := FParent;
    end;<br>

    function TNode.GetFullCount: Integer;
    begin
    Result := GetChildCount;
    for I := 0 to GetChildCount -1 do
    Inc(Result, (GetChild(I) as INodeAccess)._Self.GetFullCount);
    end;<br>

    function TNode.GetNode(Index: Integer): INode;
    begin
    if Index < 0 then
    raise Exception.Create('Index out of Bounds');
    while Index >= 0 do
    begin
    // hier code zum zugriff per absoluten index
    end;
    end;<br>

    function TNode._Self: TNode;
    begin
    // Self in EAX --> Result in EAX
    end;<br>

    </pre>

    so das mal als Grundgerüst, ist aber ungetestet und "from my mind" gepostet.<br>
    Was noch fehlt ist INode.Attach(Index: Integer; const Node: INode); um eine Node in einen Tree einzufügen bzw. zu bewegen.<br>
    Dann noch INode.Detach; um sie aus einem Tree rauszulösen.<bR>

    Gruß Hage

    Comment


    • #17
      Werde mich damit auseinandersetzen. Danke für die Mühe, Hagen.
      Gruß, Tobia

      Comment

      Working...
      X