unit odTournament;
interface
uses
Classes, SysUtils, od, odOlympicCustom, gOlympic, odPerson, odCourt
{$REGION 'USES'}, odMelee, odSwiss, odGroup, odKo, odGroupKo
{$ENDREGION 'USES'};
type
TodTournament =
class(TodOlympicCustom)
private
{$REGION ' PRIVAT'}
{$REGION ' name'}
FName:
String;
{$ENDREGION ' name'}
{$REGION ' activate'}
FActivate: Boolean;
{$ENDREGION ' activate'}
{$REGION ' excludecourts'}
FExcludeCourts:
String;
{$ENDREGION ' excludecourts'}
{$REGION ' data'}
FData: Tod;
{$ENDREGION ' data'}
{$ENDREGION ' PRIVAT'}
protected
{$REGION ' PROTECTED'}
{$REGION ' name'}
function get_Name:
String;
virtual;
procedure set_Name(
const Value:
String);
virtual;
{$ENDREGION ' name'}
{$REGION ' activate'}
function get_Activate: Boolean;
virtual;
procedure set_Activate(
const Value: Boolean);
virtual;
{$ENDREGION ' activate'}
{$REGION ' excludecourts'}
function get_ExcludeCourts:
String;
virtual;
procedure set_ExcludeCourts(
const Value:
String);
virtual;
{$ENDREGION ' excludecourts'}
{$ENDREGION ' PROTECTED'}
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
function ExistPerson(odPerson: TodPerson): Boolean;
function GetFreeCourtForTournament(DoubleFlag: Boolean): TodCourt;
function TournamentTypeName:
String;
{$REGION ' PUBLIC'}
{$REGION ' data_Melee'}
procedure Data_Create_Melee;
procedure Data_Free_Melee;
function Data_Is_Melee: Boolean;
function Melee: TodMelee;
{$ENDREGION ' data_Melee'}
{$REGION ' data_Swiss'}
procedure Data_Create_Swiss;
procedure Data_Free_Swiss;
function Data_Is_Swiss: Boolean;
function Swiss: TodSwiss;
{$ENDREGION ' data_Swiss'}
{$REGION ' data_Group'}
procedure Data_Create_Group;
procedure Data_Free_Group;
function Data_Is_Group: Boolean;
function Group: TodGroup;
{$ENDREGION ' data_Group'}
{$REGION ' data_Ko'}
procedure Data_Create_Ko;
procedure Data_Free_Ko;
function Data_Is_Ko: Boolean;
function Ko: TodKo;
{$ENDREGION ' data_Ko'}
{$REGION ' data_GroupKo'}
procedure Data_Create_GroupKo;
procedure Data_Free_GroupKo;
function Data_Is_GroupKo: Boolean;
function GroupKo: TodGroupKo;
{$ENDREGION ' data_GroupKo'}
{$REGION ' name'}
[AttrOd]
property Name:
String read get_Name
write set_Name;
{$ENDREGION ' name'}
{$REGION ' activate'}
[AttrOd]
property Activate: Boolean
read get_Activate
write set_Activate;
{$ENDREGION ' activate'}
{$REGION ' excludecourts'}
[AttrOd]
property ExcludeCourts:
String read get_ExcludeCourts
write set_ExcludeCourts;
{$ENDREGION ' excludecourts'}
{$REGION ' data'}
[AttrOd]
property Data: Tod
read FData;
{$ENDREGION ' data'}
{$ENDREGION ' PUBLIC'}
published
end;
implementation
uses
pOlympic, odTournamentEvent;
// TodTournament
constructor TodTournament.Create(AOwner: TComponent);
begin
inherited;
{$REGION ' CREATE'}
{$REGION ' data'}
FData :=
nil;
{$ENDREGION ' data'}
{$ENDREGION ' CREATE'}
end;
destructor TodTournament.Destroy;
begin
inherited;
end;
function TodTournament.ExistPerson(odPerson: TodPerson): Boolean;
begin
if Data_Is_Melee
then
Result := Melee.ExistPerson(odPerson)
else
Result := False;
end;
function TodTournament.GetFreeCourtForTournament(DoubleFlag: Boolean): TodCourt;
var
I: Integer;
C: TodCourt;
te: TodTournamentEvent;
begin
Result :=
nil;
te := OwnerTournamentEvent(Self);
for I := 0
to te.Place.CountCourts - 1
do
begin
C := te.Place.Court(I);
if (C.IsFree)
and (
not CourtInTournament(Self, C.odId))
and ((
not DoubleFlag)
or (C.CourtType <> ctSingle))
then
Exit(C);
end;
end;
function TodTournament.TournamentTypeName:
String;
begin
Result := Data.odClass;
if Result = '
Melee'
then
Result := '
Melee'
else
if Result = '
Swiss'
then
Result := '
Schweizer'
else
if Result = '
Group'
then
Result := '
Gruppen'
else
if Result = '
Ko'
then
Result := '
KO';
end;
{$REGION 'GETTER+SETTER'}
{$REGION 'data_Melee'}
procedure TodTournament.Data_Create_Melee;
begin
Data_Free_Melee;
FData := TodMelee.Create(Self);
FData.OdName := '
Data';
end;
procedure TodTournament.Data_Free_Melee;
begin
FreeAndNil(FData);
end;
function TodTournament.Data_Is_Melee: Boolean;
begin
Result := (Assigned(FData))
and (FData
is TodMelee);
end;
function TodTournament.Melee: TodMelee;
begin
if Data_Is_Melee
then
Result := (FData
as TodMelee)
else
Result :=
nil;
end;
{$ENDREGION 'data_Melee'}
{$REGION 'data_Swiss'}
procedure TodTournament.Data_Create_Swiss;
begin
Data_Free_Swiss;
FData := TodSwiss.Create(Self);
FData.OdName := '
Data';
end;
procedure TodTournament.Data_Free_Swiss;
begin
FreeAndNil(FData);
end;
function TodTournament.Data_Is_Swiss: Boolean;
begin
Result := (Assigned(FData))
and (FData
is TodSwiss);
end;
function TodTournament.Swiss: TodSwiss;
begin
if Data_Is_Swiss
then
Result := (FData
as TodSwiss)
else
Result :=
nil;
end;
{$ENDREGION 'data_Swiss'}
{$REGION 'data_Group'}
procedure TodTournament.Data_Create_Group;
begin
Data_Free_Group;
FData := TodGroup.Create(Self);
FData.OdName := '
Data';
end;
procedure TodTournament.Data_Free_Group;
begin
FreeAndNil(FData);
end;
function TodTournament.Data_Is_Group: Boolean;
begin
Result := (Assigned(FData))
and (FData
is TodGroup);
end;
function TodTournament.Group: TodGroup;
begin
if Data_Is_Group
then
Result := (FData
as TodGroup)
else
Result :=
nil;
end;
{$ENDREGION 'data_Group'}
{$REGION 'data_Ko'}
procedure TodTournament.Data_Create_Ko;
begin
Data_Free_Ko;
FData := TodKo.Create(Self);
FData.OdName := '
Data';
end;
procedure TodTournament.Data_Free_Ko;
begin
FreeAndNil(FData);
end;
function TodTournament.Data_Is_Ko: Boolean;
begin
Result := (Assigned(FData))
and (FData
is TodKo);
end;
function TodTournament.Ko: TodKo;
begin
if Data_Is_Ko
then
Result := (FData
as TodKo)
else
Result :=
nil;
end;
{$ENDREGION 'data_Ko'}
{$REGION 'data_GroupKo'}
procedure TodTournament.Data_Create_GroupKo;
begin
Data_Free_GroupKo;
FData := TodGroupKo.Create(Self);
FData.OdName := '
Data';
end;
procedure TodTournament.Data_Free_GroupKo;
begin
FreeAndNil(FData);
end;
function TodTournament.Data_Is_GroupKo: Boolean;
begin
Result := (Assigned(FData))
and (FData
is TodGroupKo);
end;
function TodTournament.GroupKo: TodGroupKo;
begin
if Data_Is_GroupKo
then
Result := (FData
as TodGroupKo)
else
Result :=
nil;
end;
{$ENDREGION 'data_GroupKo'}
{$REGION 'name'}
function TodTournament.get_Name:
String;
begin
Result := FName;
end;
procedure TodTournament.set_Name(
const Value:
String);
begin
if FName <> Value
then
begin
FName := Value;
Changed;
end;
end;
{$ENDREGION 'name'}
{$REGION 'activate'}
function TodTournament.get_Activate: Boolean;
begin
Result := FActivate;
end;
procedure TodTournament.set_Activate(
const Value: Boolean);
begin
if FActivate <> Value
then
begin
FActivate := Value;
Changed;
end;
end;
{$ENDREGION 'activate'}
{$REGION 'excludecourts'}
function TodTournament.get_ExcludeCourts:
String;
begin
Result := FExcludeCourts;
end;
procedure TodTournament.set_ExcludeCourts(
const Value:
String);
begin
if FExcludeCourts <> Value
then
begin
FExcludeCourts := Value;
Changed;
end;
end;
{$ENDREGION 'excludecourts'}
{$ENDREGION 'GETTER+SETTER'}
initialization
RegisterClasses([TodTournament]);
end.