Einzelnen Beitrag anzeigen

Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#2

Re: Array Eigenschaft mit record

  Alt 2. Dez 2006, 19:54
Delphi-Quellcode:
type
  TGame = record
    field: integer;
    anz: integer;
  end;

  TPlayer = class(TObject)
  private
    f_name: String;
    f_stand: integer;
    f_games: array of Tgame;
    f_fields: array of integer;
    f_points: array of integer;

    function GetGames(index: integer): TGame;
    procedure SetGames(index: integer; agame: TGame);
  public
    constructor Create(name : String);
    
    property games[index : integer]: TGame read GetGames write SetGames;
  end;
implementation

{ TPlayer }

constructor TPlayer.Create(name: String);
begin
  SetName(name);
  setLength(f_points,1);
  setlength(f_games,1);
end;

function TPlayer.GetGames(index: integer): TGame;
begin
  result := f_Games[index];
end;

procedure TPlayer.SetGames(index: integer; agame: TGame);
begin
  if (index > high(f_games)+1) or (index < 0) then
  begin
   showMessage ('Falscher Index bei Tplayer.SetGames');
   exit;
  end
  else if index = length(f_games) then
    setlength(f_games,length(f_games));
  f_games[index] := agame;
end;
muss eig. funzen.
  Mit Zitat antworten Zitat