AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi Objekt komplett mit enthaltenden Objekten kopieren
Thema durchsuchen
Ansicht
Themen-Optionen

Objekt komplett mit enthaltenden Objekten kopieren

Ein Thema von dizzy · begonnen am 2. Dez 2005 · letzter Beitrag vom 2. Dez 2005
 
Dax
(Gast)

n/a Beiträge
 
#5

Re: Objekt komplett mit enthaltenden Objekten kopieren

  Alt 2. Dez 2005, 18:10
So, ich bin auf das hier gekommen:

Delphi-Quellcode:
  TGridPoint = class(TObject)
  private
    FPos: TVector;
    FAbove,
    FUnder,
    FLeft,
    FRight: TGridPoint;



    constructor CreateOnNil;
  public
    constructor Create(aPosX, aPosY: Single; aAbove, aUnder, aLeft, aRight: TGridPoint);
    property Position : TVector read FPos write FPos;
    property PointAbove: TGridPoint read FAbove write FAbove;
    property PointUnder: TGridPoint read FUnder write FUnder;
    property PointLeft : TGridPoint read FLeft write FLeft;
    property PointRight: TGridPoint read FRight write FRight;


    function Replicate: TGridPoint;

  end;

{ TGridPoint }

function TGridPoint.Replicate: TGridPoint;
type
  TCloneGridPoint = record
    Point,
    FGridPoint: TGridPoint;
  end;

var
  Cells: array of TCloneGridPoint;

  function CellsIndex(Point: TGridPoint): Integer;
  var i: Integer;
  begin
    Result := -1;
    for i := 0 to High(Cells) do
      if Cells[i].FGridPoint = Point then
      begin
        Result := i;
        Exit;
      end;
  end;

  function CellsContain(Point: TGridPoint): Boolean;
  begin
    Result := CellsIndex(Point) <> -1;
  end;

  function CloneSingleCell(Cell: TGridPoint): TGridPoint;
  begin
    if Cell = nil then
    begin
      Result := nil;
      Exit;
    end;
    if not CellsContain(Cell) then
    begin
      Result := TGridPoint.CreateOnNil;
      Result.Position := Cell.Position;

      SetLength(Cells, Length(Cells)+1);
      Cells[High(Cells)].Point := Result;
      Cells[High(Cells)].FGridPoint := Cell;

      Result.PointAbove := CloneSingleCell(Cell.PointAbove);
      Result.PointUnder := CloneSingleCell(Cell.PointUnder);
      Result.PointLeft := CloneSingleCell(Cell.PointLeft);
      Result.PointRight := CloneSingleCell(Cell.PointRight);
    end
    else
      Result := Cells[CellsIndex(Cell)].Point;
  end;

begin
  Result := CloneSingleCell(Self);
end;

constructor TGridPoint.Create(aPosX, aPosY: Single; aAbove, aUnder, aLeft,
  aRight: TGridPoint);
begin
  FAbove := aAbove;
  FUnder := aUnder;
  FLeft := aLeft;
  FRight := aRight;
  FPos.x := aPosX;
  FPos.y := aPosY;
end;

constructor TGridPoint.CreateOnNil;
begin

end;
dizzy, bitte mal austesten
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:03 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz