Registriert seit: 19. Aug 2004
Ort: Hof/Saale
1.746 Beiträge
Delphi 2007 Professional
|
AW: Properites mit Enums zusammenfassen
26. Jan 2023, 14:02
Sowas?
Delphi-Quellcode:
type
TBla = (a, b, c);
TBlaSet = set of TBla;
TBlub = (l, m, o, p);
TBlubSet = set of TBlub;
TPropGroup<E, S >= class
strict protected
FActive: E;
function GetActive: E; virtual; abstract;
procedure SetActive(Value: E); virtual; abstract;
function GetAvailable: S; virtual; abstract;
function GetSupported: S; virtual; abstract;
public
property Active: E read GetActive write SetActive;
property Supported: S read GetSupported;
property Available: S read GetAvailable;
end;
TBlaGroup = class(TPropGroup<TBla, TBlaSet>)
strict protected
function GetActive: TBla; override;
procedure SetActive(Value: TBla); override;
function GetAvailable: TBlaSet; override;
function GetSupported: TBlaSet; override;
end;
TBlubGroup = class(TPropGroup<TBlub, TBlubSet>)
strict protected
function GetActive: TBlub; override;
procedure SetActive(Value: TBlub); override;
function GetAvailable: TBlubSet; override;
function GetSupported: TBlubSet; override;
end;
TForm1 = class(TForm)
ButtonTest: TButton;
procedure ButtonTestClick(Sender: TObject);
strict private
FBlaGroup: TBlaGroup;
FBlubGroup: TBlubGroup;
public
property BlaGroup: TBlaGroup read FBlaGroup;
property BlubGroup: TBlubGroup read FBlubGroup;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
Delphi-Quellcode:
{ TForm1 }
constructor TForm1.Create(AOwner: TComponent);
begin
inherited;
FBlaGroup := TBlaGroup.Create;
FBlubGroup := TBlubGroup.Create;
end;
destructor TForm1.Destroy;
begin
FBlaGroup.Free;
FBlubGroup.Free;
inherited;
end;
procedure TForm1.ButtonTestClick(Sender: TObject);
var
bla: TBla;
blas: TBlaSet;
blub: TBlub;
blubs: TBlubSet;
begin
bla := BlaGroup.Active;
blas := BlaGroup.Available;
blub := BlubGroup.Active;
blubs := BlubGroup.Available;
end;
{ TBlaGroup }
function TBlaGroup.GetActive: TBla;
begin
Result := FActive;
end;
procedure TBlaGroup.SetActive(Value: TBla);
begin
FActive := Value;
end;
function TBlaGroup.GetAvailable: TBlaSet;
begin
Result := [a, b];
end;
function TBlaGroup.GetSupported: TBlaSet;
begin
Result := [b, c];
end;
{ TBlubGroup }
function TBlubGroup.GetActive: TBlub;
begin
Result := FActive;
end;
procedure TBlubGroup.SetActive(Value: TBlub);
begin
FActive := Value;
end;
function TBlubGroup.GetAvailable: TBlubSet;
begin
Result := [l, m];
end;
function TBlubGroup.GetSupported: TBlubSet;
begin
Result := [o, p];
end;
Du bezahlst halt mit dynamischer Speicherallozierung und virtuellen Funktionsaufrufen.
Uli Gerhardt
|
|
Zitat
|