Einzelnen Beitrag anzeigen

omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#13

Re: Saubere Programmierung mit Delphi

  Alt 15. Mär 2008, 22:19
Hier mal ein Vorschlag...

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(AForm: TForm; AColor1, AColor2: TColor; ADistance: Byte);
    procedure Horizontal;
    procedure Vertical;
  end;

implementation

constructor TBackground.Create(AForm: TForm; AColor1, AColor2: TColor; ADistance: Byte);
begin
  FForm:=AForm;
  FColor[0]:=AColor1;
  FColor[1]:=AColor2;
  FDistance:=ADistance;
end;

procedure TBackground.Horizontal;
var i : Integer; // Schleifenvariable
begin
  if assigned(FForm) then 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;
end;

procedure TBackground.Vertical;
var i : Integer; // Schleifenvariable
begin
  if assigned(FForm) then 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;
end;

end.
Gruss
Thorsten
  Mit Zitat antworten Zitat