Thema: Delphi Array, aber wie ?

Einzelnen Beitrag anzeigen

Specialradio

Registriert seit: 25. Okt 2006
4 Beiträge
 
#1

Array, aber wie ?

  Alt 25. Okt 2006, 13:19
Huhu, das ist mein Quelltext

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  tmylabel = class (TLabel)
   procedure WMPaint(var Message : TMessage); message wm_Paint;
  end;
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
    lastclickedlabel: TMyLabel;
  public
    procedure Labelclick(Sender: TObject);
    procedure MouseM(Sender : TObject; Shift : TShiftState; x, y : Integer);
    procedure KleinLabelMouseDown(Sender: TObject; Button : TMouseButton; Shift : TShiftstate; x,y : Integer);
    procedure PanelMouseDown(Sender: TObject; Button : TMouseButton; Shift : TShiftstate; x,y : Integer);


    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Zahl : integer;



implementation

uses Unit2;

{$R *.DFM}



procedure TForm1.Labelclick(Sender: TObject);
var
 ZahlenPanel: TPanel;
 j, i, pg: integer;
 p : TPanel;
 l : TMyLabel;
begin
 with TLabel(Sender) do
 begin
  if assigned (focuscontrol) then focuscontrol.visible := true else
  begin
   p := TPanel.Create(Application);
   FocusControl := p;
   with p do
   begin
    parent := self;
    height := TLabel(Sender).height;
    width := TLabel(Sender).width;
    left := TLabel(Sender).left;
    top := Tlabel(Sender).top;
    OnMouseDown := PanelMouseDown;
   end;
   pg := Round(p.height -2);
   for j := 1 to 3 do
   begin
    for i := 1 to 3 do
    begin
     l := TMyLabel.Create(self);
     with l do
     begin
      Focuscontrol:= Pointer(Sender);
      parent := p;
      autosize := false;
      height := Round(p.height / 3);
      width := height;
      left := (j-1) * width ;
      top := (i-1) * height;
      caption := IntToStr((i - 1) * 3 + j);
      Alignment:= tacenter;
      Canvas.Brush.Color := clBtnFace;
      //OnDBLClick := kleinLabelDBLKlick;
      OnMouseDown := kleinLabelMouseDown;
     end;
    end;
   end;
  end;
 end;
 Repaint;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
 s,
 i, // Zeilenzähler
 j, // Spaltenzähler
 lg, // Labelgröße
 bg :Integer; // Boxgröße
 l : TMyLabel;
 lb : TLabel;
begin
 lastclickedLabel:= nil;
 Zahl := 0;
 ClientHeight := round(screen.height*0.8);
 ClientWidth := ClientHeight;
 lg := Round((ClientHeight-20)/9);
 ClientHeight := 9*lg+20;
 ClientWidth := ClientHeight;
  for i:=1 to 9 do
  begin
   for j:= 1 to 9 do
   begin
     l :=TMyLabel.Create(Application);
     with l do
     begin
       OnMouseMove := MouseM;
       Top := ((i-1)* lg)+13;
       Parent:= self;
       AutoSize := false;
       Font.Size := 12;
       Left := 10 + lg * (j-1) ;
       Height:= lg;
       Width:=lg;
       Caption:= IntToStr(i)+','+(IntToStr(j));
       Alignment := tacenter;
       onclick := labelclick;
       Canvas.Brush.Color := clBtnFace;
       //OnDBLClick := kleinLabelDBLKlick;
     end;
   end;
  end;
  l := TMyLabel.Create(nil);
  l.parent := self;
end;


procedure TForm1.FormPaint(Sender: TObject);
var i : integer;
 bg :Integer; // boxgröße
begin
 inherited;
 bg := Round((ClientHeight-20)/9)*3;
 for i := 1 to 2 do
 begin
  Canvas.MoveTo(10, bg*i+10);
  Canvas.LineTo(Clientwidth-10, bg*i+10);
  Canvas.MoveTo(bg*i+10, 10);
  Canvas.LineTo(bg*i+10, Clientheight-10);
 end;
end;

{ tmylabel }

procedure tmylabel.WMPaint(var Message: TMessage);
begin

 Canvas.TextOut((width shr 1) - (Canvas.TextWidth(Caption) shr 1), (height shr 1) - (Canvas.TextHeight(Caption) shr 1), caption);
 TForm(GetParentForm(self)).OnPaint(self);
end;


procedure TForm1.MouseM(Sender: TObject; Shift: TShiftState; x,
  y: Integer);
begin
 //Canvas.DrawFocusRect(TLabel(Sender).BoundsRect);
end;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
 timer1.enabled := false;
 If Zahl = 1 then
 begin
 lastclickedlabel.Visible := not lastclickedlabel.visible;
 end else if Zahl > 1 then
 begin
  with lastclickedlabel do
  begin
   TLabel(Focuscontrol).Caption := Caption;
   TLabel(Focuscontrol).focuscontrol.visible := false;
   Zahl := 0;
  end;
 end;
 Zahl := 0;
 lastclickedlabel := nil;
end;

procedure TForm1.KleinLabelMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftstate; x, y: Integer);
begin
 If TMyLabel(Sender) = lastclickedlabel then
 begin
  inc(zahl);
 end else
 begin
  zahl := 1;
  Lastclickedlabel := TMyLabel(Sender);
 end;
 If not Timer1.Enabled then timer1.enabled := true;
end;

procedure TForm1.PanelMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftstate; x, y: Integer);
var
 Control : TControl;
 i: integer;
begin
 for i := 0 to TPanel(Sender).ControlCount-1 do
 begin
  with TPanel(Sender).Controls[i] do
  begin
   If ((x < left) or (x > Left+Width)) or ((y < top) or (y > Top+Height)) then else visible := true;

  end;
 end;
end;

end.
Jetzt muss ich im bereich "TForm1.FormCreate" zum beispiel dem dynamischen Label 34 eine Caption zuweißen.
Das müsste ich mit einer Arrayliste machen oder ? Wie könnte ich das am besten machen ?

MfG Chris
Chris
  Mit Zitat antworten Zitat