Thema: Delphi Problem mit Label

Einzelnen Beitrag anzeigen

stoermi

Registriert seit: 1. Dez 2004
Ort: im Wald von Thüringen
75 Beiträge
 
Delphi 6 Enterprise
 
#11

Re: Problem mit Label

  Alt 1. Dez 2004, 15:58
Es geht um ein Hotelverwaltungsprogramm für die Uni. Bin aber naoch am Anfang...

Hier die Formular-Klasse in der 2 Beispielzimmer erstellt werden:

Code:
unit main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, Menus, ExtCtrls, StdCtrls, Types;

type
  THotelForm = class(TForm)
    MainMenu1: TMainMenu;
    PageControl1: TPageControl;
    Programm1: TMenuItem;
    Anicht1: TMenuItem;
    Beenden1: TMenuItem;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    PaintBox1: TPaintBox;
    procedure HotelFormCreate (Sender : TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  HotelForm: THotelForm;

implementation

{$R *.dfm}

uses zimmer, einzelzimmer, doppelzimmer, appartment, suite;

procedure THotelForm.HotelFormCreate(Sender: TObject);
var xy, yz : array[0..8] of ShortString;
    vRand, hRand : Integer;
    myZimmer, myZimmer2 : TZimmer;
begin
  {Plan-Fläche zeichnen - Hindergrund: Weiß}
  PaintBox1.Canvas.Brush.Color := clWhite;
  PaintBox1.Canvas.Rectangle(3,3,PaintBox1.Width-6,PaintBox1.Height-6);

  xy[0] := '101';
  xy[1] := '100';
  xy[2] := '100';
  xy[3] := '200';
  xy[4] := '100';
  xy[5] := '200';
  xy[6] := '200';
  xy[7] := '100';
  xy[8] := '200';

  yz[0] := '102';
  yz[1] := '300';
  yz[2] := '100';
  yz[3] := '400';
  yz[4] := '100';
  yz[5] := '400';
  yz[6] := '200';
  yz[7] := '300';
  yz[8] := '200';

  vRand := 30;
  hRand := 30;

  myZimmer := TSuite.Create(xy);
  myZimmer.einzeichnen(hRand, vRand);

  myZimmer2 := TDoppelzimmer.Create(yz);
  myZimmer2.einzeichnen(hRand, vRand);

end;

end.

Hier die Klasse Zimmer

Code:
unit zimmer;

interface

uses Classes, Graphics, SysUtils, StdCtrls, Types;

type
  TZimmer = class (TComponent)
  private
  protected
    x1,y1,x2,y2,x3,y3,x4,y4 : Integer;         //Positionspunkte des Zimmers
    grundpreis : Currency;                     //Zimmergrundpreis
    bettPreis : Currency;                      //Preis pro Bett;
  public
    zimmerNummer : ShortString;
    constructor Create (werte : array of ShortString); virtual;  //Konstrucktor
    function betten : Integer; virtual;                             //Bettenanzahl
    function preis : Currency; virtual;                             //Zimmerpreis
    function hindergrund : TColor; virtual;                        //Hindergundfarbe für Plan
    procedure einzeichnen (hRand, vRand : Integer); virtual;
  published
  end;

implementation

uses main;

constructor TZimmer.Create(werte : array of ShortString);
begin
  inherited create(NIL);
  zimmerNummer := werte[0];    //Zimmernummer
  x1 := StrToInt (werte[1]);   //Punkte aus Array auslesen
  y1 := StrToInt (werte[2]);
  x2 := StrToInt (werte[3]);
  y2 := StrToInt (werte[4]);
  x3 := StrToInt (werte[5]);
  y3 := StrToInt (werte[6]);
  x4 := StrToInt (werte[7]);
  y4 := StrToInt (werte[8]);
  grundpreis := 50.0;          //Zimmergrundpreis
  bettPreis := 25.0;           //Bettpreis
end;

function TZimmer.betten : Integer;
begin
  result := 1;
end;

function TZimmer.preis : Currency;
begin
  result := grundpreis + (betten * bettPreis);
end;

function TZimmer.hindergrund : TColor;
begin
  result := $FFFFFF;
end;

procedure TZimmer.einzeichnen (hRand, vRand : Integer);
var zimmerEcken : array[1..4] of TPoint;
    i : Integer;
    ok : boolean;
    newLabel : TLabel;
begin
  zimmerEcken[1] := point(x1 + hRand, y1 + vRand);
  zimmerEcken[2] := point(x2 + hRand, y2 + vRand);
  zimmerEcken[3] := point(x3 + hRand, y3 + vRand);
  zimmerEcken[4] := point(x4 + hRand, y4 + vRand);

  HotelForm.PaintBox1.Canvas.Brush.Color := hindergrund;
  HotelForm.PaintBox1.Canvas.Polygon(zimmerEcken);


  newLabel := TLabel.Create(nil);
  with newLabel as TLabel do
  begin
    Parent := HotelForm.TabSheet2;
    Name := 'Label_'+zimmerNummer;
    Caption := zimmerNummer;
    Left := round((x1+x3)/2)+hRand-round(Width/2);
    Top := round((y1+y3)/2)+hRand-round(Height/2);
    Alignment := taCenter;
    Layout := tlCenter;
    Transparent := True;
    Visible := True;
  end;

end;

end.
  Mit Zitat antworten Zitat