AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

8 Damen Problem

Ein Thema von Blackwolf96 · begonnen am 13. Jul 2014 · letzter Beitrag vom 14. Jul 2014
Antwort Antwort
Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.493 Beiträge
 
Delphi 12 Athens
 
#1

AW: 8 Damen Problem

  Alt 14. Jul 2014, 08:42
Oh das hätte ich machen sollen. Ich benutze Delphi 7.
Delphi 7 kennt noch keine Generics, da muss man dann mehr von Hand machen.
Delphi-Quellcode:
type
  TFeld = class;
  TFeldList = class;

  TFeldListEnumerator = record
    constructor Create(AList: TFeldList);
  private
    FIndex: Integer;
    FList: TFeldList;
    function GetCurrent: TFeld;
  public
    function MoveNext: Boolean;
    property Current: TFeld read GetCurrent;
  end;

  TFeldList = class(TObjectList)
  protected
    function GetItem(Index: Integer): TFeld;
    procedure SetItem(Index: Integer; AObject: TFeld);
  public
    function GetEnumerator: TFeldListEnumerator;
    property Items[AIndex: Integer]: TFeld read GetItem write SetItem; default;
  end;

implementation

{ TFeldList }

function TFeldList.GetEnumerator: TFeld;
begin
  Result := TFeldListEnumerator.Create(Self);
end;

function TFeldList.GetItem(Index: Integer): TFeld;
begin
  Result := TFeld(inherited GetItem(Index));
end;

procedure TFeldList.SetItem(Index: Integer; AObject: TFeld);
begin
  inherited SetItem(Index, AObject);
end;

{ TFeldListEnumerator }

constructor TFeldListEnumerator.Create(AList: TFeldList);
begin
  FList := AList;
  FIndex := -1;
end;

function TFeldListEnumerator.GetCurrent: TFeld;
begin
  Result := FList[FIndex];
end;

function TFeldListEnumerator.MoveNext: Boolean;
begin
  Result := (FIndex < FList.Count - 1);
  if Result then
    Inc(FIndex);
end;
Dann einfach TList<TFeld> durch TFeldList ersetzen.
  Mit Zitat antworten Zitat
Antwort Antwort


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 20:48 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