Einzelnen Beitrag anzeigen

Christian18

Registriert seit: 9. Dez 2003
Ort: Hamburg
1.279 Beiträge
 
#1

Saubere Programmierung mit Delphi

  Alt 15. Mär 2008, 20:25
Hallo,

da ich sehr viel Wert auf saubere Programmierung lege, habe ich mir folgendes gedacht. Vieleicht könntet ihr euch mal eine Klasse von mir anschauen und mir ein paar Tips geben, was ich vieleicht besser machen kann.

Delphi-Quellcode:
unit UBackground;

interface

uses
  Forms, Graphics;

type
  TBackground = class
  private
    FForm : TForm;
    FColor : Array[0..1] of TColor;
    FDistance : Byte;
  public
    constructor Create(Form: TForm; Color1, Color2: TColor; Distance: Byte);
    procedure Horizontal();
    procedure Vertical();
    destructor Destroy();
  end;

implementation

constructor TBackground.Create(Form: TForm; Color1, Color2: TColor; Distance: Byte);
begin
  FForm:=Form;
  FColor[0]:=Color1;
  FColor[1]:=Color2;
  FDistance:=Distance;
end;

procedure TBackground.Horizontal();
  var i : Integer; // Schleifenvariable
begin
  FForm.Color:=FColor[0];
  FForm.Canvas.Pen.Color:=FColor[1];
  i:=0;
  while i <= FForm.ClientHeight do
    begin
      FForm.Canvas.MoveTo(0, i);
      FForm.Canvas.LineTo(FForm.ClientWidth, i);
      Inc(i, FDistance);
    end;
end;

procedure TBackground.Vertical();
  var i : Integer; // Schleifenvariable
begin
  FForm.Color:=FColor[0];
  FForm.Canvas.Pen.Color:=FColor[1];
  i:=0;
  while i <= FForm.ClientWidth do
    begin
      FForm.Canvas.MoveTo(i, 0);
      FForm.Canvas.LineTo(i, FForm.ClientHeight);
      Inc(i, FDistance);
    end;
end;

destructor TBackground.Destroy();
begin
  FForm.Free();
end;

end.
MFG Christian18
  Mit Zitat antworten Zitat