AGB  ·  Datenschutz  ·  Impressum  







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

Design Problem (Shapes)

Ein Thema von Bjoerk · begonnen am 15. Apr 2014 · letzter Beitrag vom 15. Apr 2014
Antwort Antwort
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.655 Beiträge
 
Delphi 12 Athens
 
#1

AW: Design Problem (Shapes)

  Alt 15. Apr 2014, 16:16
Delphi-Quellcode:
procedure TShape.Paint;
begin
  case FTyp of
    Typ1:
      PaintTyp1;
    Typ2:
      PaintTyp2;
    Typ3:
      PaintTyp3;
    Typ4:
      PaintTyp4;
    Typ5:
      PaintTyp5;
    ..

    TypN:
  end;
end;

procedure TShape.PaintTyp1;
begin
  ...
end;

procedure TShape.PaintTyp2;
begin
  ...
end;

//usw. usf.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Bjoerk

Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: Design Problem (Shapes)

  Alt 15. Apr 2014, 16:19
Jenau.
  Mit Zitat antworten Zitat
Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#3

AW: Design Problem (Shapes)

  Alt 15. Apr 2014, 16:33
Wenn du das flexibel erweitern möchtest, dann nimm eine Shape-Klasse und eine ShapeStrategy-Klasse.
Hier mal skizziert, wie das geht:
Delphi-Quellcode:
type
  TShapeStrategy = class abstract
  protected
    procedure Paint( ACanvas : TCanvas ); virtual; abstract;
  end;

  TShapeStrategyClass = class of TShapeStrategy;

  TShape = class( TGraphicControl )
  private
    FStrategyName : string;
    FStrategy : TShapeStrategy;
    procedure SetStrategyName( const Value : string );
  protected
    procedure Paint; override;
  public
    class procedure RegisterStrategy( const AName : string; AStrategy : TShapeStrategyClass );
  published
    property StrategyName : string read FStrategyName write SetStrategyName;
  end;

procedure TShape.Paint;
begin
  if Assigned( FStrategy ) then
    FStrategy.Paint( Canvas );
end;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  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 05:22 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 by Thomas Breitkreuz