unit Player_Classes;
interface
type
// Forward
TPlayerList =
class;
// Der ShowMode definiert, wie der Name des Spielers ausgegeben wird
TShowNameMode = (snm_FullName,
// Vorname und Name anzeigen
snm_Name,
// nur Nachname anzeigen
snm_ShortFirstName
// Vorname abgekürzt, Nachname voll
);
(*
Klasse eines einzelnen Spielers. Der Member PlayerList gibt die übergeordnete Liste
an, die den Spieler hält.
*)
TPlayerClass =
class(TObject)
private
FBirthday: TDateTime;
FFirstName:
String;
FName:
String;
FPlayerList: TPlayerList;
FShowNameMode: TShowNameMode;
function GetFullName:
String;
procedure SetBirthday(
const Value: TDateTime);
procedure SetFirstName(
const Value:
String);
procedure SetName(
const Value:
String);
procedure SetShowNameMode(
const Value: TShowNameMode);
public
property PlayerList : TPlayerList
read FPlayerList
write FPlayerList;
property Birthday : TDateTime
read FBirthday
write SetBirthday;
property FirstName :
String read FFirstName
write SetFirstName;
property Name :
String read FName
write SetName;
property ShowNameMode : TShowNameMode
read FShowNameMode
write SetShowNameMode;
property FullName :
String read GetFullName;
end;
TPlayerList =
class(TObjectList)
private
protected
function GetItem(
Index: Integer): TPlayerClass;
procedure SetItem(
Index: Integer; AObject: TPlayerClass);
public
function Add(AObject: TPlayerClass): Integer;
function Extract(Item: TPlayerClass): TPlayerClass;
function Remove(AObject: TPlayerClass): Integer;
function IndexOf(AObject: TPlayerClass): Integer;
procedure Insert(
Index: Integer; AObject: TPlayerClass);
function First: TPlayerClass;
function Last: TPlayerClass;
procedure PlayerChanged;
property Items[
Index: Integer]: TPlayerClass
read GetItem
write SetItem;
default;
end;
implementation
{ TPlayerClass }
function TPlayerClass.GetFullName:
String;
begin
case FShowNameMode
of
snm_FullName: Result := Format('
%s %s', [FFirstName, FName]);
snm_Name: Result := FName;
snm_ShortFirstName: Result := Format('
%s. %s', [FFirstName[1], FName]);
end;
end;
procedure TPlayerClass.SetBirthday(
const Value: TDateTime);
begin
if FBirthday = Value
then
Exit;
FBirthday := Value;
if Assigned(FPlayerList)
then
FPlayerList.PlayerChanged;
end;
procedure TPlayerClass.SetFirstName(
const Value:
String);
begin
if FFirstName = Value
then
Exit;
FFirstName := Value;
if Assigned(FPlayerList)
then
FPlayerList.PlayerChanged;
end;
procedure TPlayerClass.SetName(
const Value:
String);
begin
if FName = Value
then
Exit;
FName := Value;
if Assigned(FPlayerList)
then
FPlayerList.PlayerChanged;
end;
procedure TPlayerClass.SetShowNameMode(
const Value: TShowNameMode);
begin
if FShowNameMode = Value
then
Exit;
FShowNameMode := Value;
if Assigned(FPlayerList)
then
FPlayerList.PlayerChanged;
end;
{ TPlayerList }
function TPlayerList.Add(AObject: TPlayerClass): Integer;
begin
AObject.FPlayerList := self;
Result :=
inherited Add(AObject);
end;
function TPlayerList.Extract(Item: TPlayerClass): TPlayerClass;
begin
Result := TPlayerClass(
inherited Extract(Item));
result.FPlayerList :=
nil;
end;
function TPlayerList.First: TPlayerClass;
begin
Result := TPlayerClass(
inherited First);
end;
function TPlayerList.GetItem(
Index: Integer): TPlayerClass;
begin
Result := TPlayerClass(
inherited GetItem(
Index));
end;
function TPlayerList.IndexOf(AObject: TPlayerClass): Integer;
begin
Result :=
inherited IndexOf(AObject);
end;
procedure TPlayerList.Insert(
Index: Integer; AObject: TPlayerClass);
begin
AObject.FPlayerList := self;
inherited Insert(
Index, AObject);
end;
function TPlayerList.Last: TPlayerClass;
begin
Result := TPlayerClass(
inherited Last);
end;
{-----------------------------------------------------------------------------
Procedure: PlayerChanged
Author: Dipl. Ing. Olaf Keitsch
Date: 05-Jun-2009
Arguments: None
Result: None
Describtion: Diese Methode wird von den Settern der Player aufgerufen. An dieser
Stelle kann die Aktualisierung des anzeigenden Controls aufgerufen werden.
-----------------------------------------------------------------------------}
procedure TPlayerList.PlayerChanged;
begin
// do it
end;
function TPlayerList.Remove(AObject: TPlayerClass): Integer;
begin
AObject.FPlayerList :=
nil;
Result :=
inherited Remove(AObject);
end;
procedure TPlayerList.SetItem(
Index: Integer; AObject: TPlayerClass);
begin
AObject.FPlayerList := self;
inherited SetItem(
Index, AObject);
end;
end.