Thema: Delphi Vereinfachung/Verkürzen

Einzelnen Beitrag anzeigen

stexxy

Registriert seit: 12. Sep 2007
15 Beiträge
 
#1

Vereinfachung/Verkürzen

  Alt 12. Sep 2007, 14:51
HI bin neu hier und ich beschäftige mich seit gestern mit delphi.
ich hab ein kleines programm geschrieben.
der quelltext is jedoch ziemlich lang geworden und ich sehe da kaum noch durch.
ich wollte mal fragen welche möglichenkeiten es gibt quellcodes zu vereinfach oder zu verkürzen.
man kann bestimmt etliche sachen vereinfach.

Hier mal der code

Delphi-Quellcode:
unit Fahrstuhl;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Image1: TImage;
    Timer1: TTimer;
    Button7: TButton;
    Timer2: TTimer;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button14: TButton;
    Timer3: TTimer;
    Image2: TImage;
    Timer4: TTimer;
    Image3: TImage;
    Timer5: TTimer;
    Timer6: TTimer;
    Timer7: TTimer;
    Timer8: TTimer;
    Timer9: TTimer;
    Timer10: TTimer;
    Label1: TLabel;
    Image4: TImage;
    Timer11: TTimer;
    Button15: TButton;
    Button16: TButton;
    Timer12: TTimer;
    Image5: TImage;
    Timer13: TTimer;
    Timer14: TTimer;
    Timer15: TTimer;
    Timer16: TTimer;
    Timer17: TTimer;
    Timer18: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button14Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Timer3Timer(Sender: TObject);
    procedure Timer4Timer(Sender: TObject);
    procedure Timer5Timer(Sender: TObject);
    procedure Timer6Timer(Sender: TObject);
    procedure Timer7Timer(Sender: TObject);
    procedure Timer8Timer(Sender: TObject);
    procedure Timer9Timer(Sender: TObject);
    procedure Timer10Timer(Sender: TObject);
    procedure Timer11Timer(Sender: TObject);
    procedure Timer12Timer(Sender: TObject);
    procedure Timer13Timer(Sender: TObject);
    procedure Timer15Timer(Sender: TObject);
    procedure Timer16Timer(Sender: TObject);
    procedure Timer17Timer(Sender: TObject);
    procedure Timer18Timer(Sender: TObject);
    procedure Timer14Timer(Sender: TObject);







private
    { Private-Deklarationen }
public
    { Public-Deklarationen }
end;

var
  Form1: TForm1;

implementation

{$R *.DFM}









procedure TForm1.Timer1Timer(Sender: TObject);

var
  x : integer;

begin
  timer1.enabled:=true;

  x:=-2;
  Image1.top:=Image1.top+x; //verschiebt image1 um wert x
  Image4.top:=Image4.top+x;
  Image5.top:=Image5.top+x;

  if image1.top=480 then
   Label1.caption:=inttostr(5);

  if image1.top=0 then
   timer1.enabled:=false;

  if image1.top=0 then
   timer11.enabled:=true;


  button8.Enabled:=true;
  button11.Enabled:=true;
  button9.Enabled:=true;
  button10.Enabled:=true;
  button12.Enabled:=true;
  button13.Enabled:=false;

  if image1.top=120 then
   Label1.caption:=inttostr(4);

  if image1.top=0 then
   Label1.caption:=inttostr(5);

  if image1.top=240 then
   Label1.caption:=inttostr(3);

  if image1.top=360 then
   Label1.caption:=inttostr(2);

  if image1.top=480 then
   Label1.caption:=inttostr(1);

  if image1.top=600 then
   Label1.caption:=inttostr(0);
end;


procedure TForm1.Timer2Timer(Sender: TObject);

var
  x : integer;

begin

  timer2.enabled:=true;

  x:=2;
  Image1.top:=Image1.top+x; //verschiebt image1 um wert x
  Image4.top:=Image4.top+x;
  Image5.top:=Image5.top+x;

  if image1.top=600 then
   timer2.enabled:=false;

  if image1.top=120 then
   Label1.caption:=inttostr(4);

  if image1.top=0 then
   Label1.caption:=inttostr(5);

  if image1.top=240 then
   Label1.caption:=inttostr(3);

  if image1.top=360 then
   Label1.caption:=inttostr(2);

  if image1.top=480 then
   Label1.caption:=inttostr(1);

  if image1.top=600 then
   Label1.caption:=inttostr(0);

  if image1.top=600 then
   timer11.enabled:=true;

  button8.Enabled:=false;
  button11.Enabled:=true;
  button9.Enabled:=true;
  button10.Enabled:=true;
  button12.Enabled:=true;
 button13.Enabled:=true;

end;




procedure TForm1.Button7Click(Sender: TObject); // NOtaus

begin
  timer1.enabled:=false;
  timer2.enabled:=false;
  timer3.enabled:=false; // stoppt den timer
  timer4.enabled:=false;
  timer5.enabled:=false;
  timer6.enabled:=false;
  timer7.enabled:=false;
  timer8.enabled:=false;
  timer9.enabled:=false;
  timer10.enabled:=false;
  timer11.enabled:=false;
  timer12.enabled:=false;

  button8.Enabled:=true;
  button9.Enabled:=true;
  button10.Enabled:=true; // macht tasten wieder funtionstüchtig
  button11.Enabled:=true;
  button12.Enabled:=true;
  button13.Enabled:=true;
end;




procedure TForm1.Button14Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.Button8Click(Sender: TObject); // Fahrstuhlknopf innen EG
begin

  if image1.top=600 then
   timer2.enabled:=false;

end;

procedure TForm1.Timer3Timer(Sender: TObject);

var
  x : integer;

begin

  timer3.enabled:=true;

  x:=-2;
  Image1.top:=Image1.top+x; //verschiebt image1 um wert x
  Image4.top:=Image4.top+x;
  Image5.top:=Image5.top+x;

  if image1.top<480 then
   timer3.enabled:=false;

  if image1.top<480 then
   timer7.enabled:=true;

  if image1.top=480 then
   timer3.enabled:=false;

  if image1.top=480 then
   timer11.enabled:=true;

  if image1.top=120 then
   Label1.caption:=inttostr(4);

  if image1.top=0 then
   Label1.caption:=inttostr(5);

  if image1.top=240 then
   Label1.caption:=inttostr(3);

  if image1.top=360 then
   Label1.caption:=inttostr(2);

  if image1.top=480 then
   Label1.caption:=inttostr(1);

  if image1.top=600 then
   Label1.caption:=inttostr(0);

  button11.Enabled:=true;
  button8.Enabled:=true;
  button10.Enabled:=true;
  button12.Enabled:=true;
  button13.Enabled:=true;
  button9.Enabled:=false;

end;


procedure TForm1.Timer4Timer(Sender: TObject);

var
  x : integer;

  begin
  timer4.enabled:=true;

  x:=-2;
  Image1.top:=Image1.top+x; //verschiebt image1 um wert x
  Image4.top:=Image4.top+x;
  Image5.top:=Image5.top+x;

  if image1.top=360 then
   timer4.enabled:=false;

  if image1.top<360 then
   timer4.enabled:=false;

  if image1.top<360 then
   timer8.enabled:=true;

  if image1.top=360 then
  timer11.enabled:=true;

  if image1.top=120 then
   Label1.caption:=inttostr(4);

  if image1.top=0 then
   Label1.caption:=inttostr(5);

  if image1.top=240 then
   Label1.caption:=inttostr(3);

  if image1.top=360 then
   Label1.caption:=inttostr(2);

  if image1.top=480 then
   Label1.caption:=inttostr(1);

  if image1.top=600 then
   Label1.caption:=inttostr(0);

  button11.Enabled:=true;
  button8.Enabled:=true;
  button9.Enabled:=true;
  button12.Enabled:=true;
  button13.Enabled:=true;
  button10.Enabled:=false;

end;



procedure TForm1.Timer5Timer(Sender: TObject);
var
  x : integer;

begin
  timer5.enabled:=true;

  x:=-2;
  Image1.top:=Image1.top+x; //verschiebt image1 um wert x
  Image4.top:=Image4.top+x;
  Image5.top:=Image5.top+x;

  if image1.top=240 then
   timer5.enabled:=false;

  if image1.top<240 then
   timer5.enabled:=false;

  if image1.top<240 then
   timer9.enabled:=true;

  if image1.top=240 then
   timer11.enabled:=true;

  if image1.top=120 then
   Label1.caption:=inttostr(4);

  if image1.top=0 then
   Label1.caption:=inttostr(5);

  if image1.top=240 then
   Label1.caption:=inttostr(3);

  if image1.top=360 then
   Label1.caption:=inttostr(2);

  if image1.top=480 then
   Label1.caption:=inttostr(1);

  if image1.top=600 then
  Label1.caption:=inttostr(0);

  button11.Enabled:=false;
  button8.Enabled:=true;
  button9.Enabled:=true;
  button10.Enabled:=true;
  button12.Enabled:=true;
  button13.Enabled:=true;

end;


procedure TForm1.Timer6Timer(Sender: TObject);
var
  x : integer;

  begin
  timer6.enabled:=true;

  x:=-2;
  Image1.top:=Image1.top+x; //verschiebt image1 um wert x
  Image4.top:=Image4.top+x;
  Image5.top:=Image5.top+x;

  if image1.top=120 then
   timer6.enabled:=false;

  if image1.top<120 then
   timer6.enabled:=false;

  if image1.top<120 then
   timer10.enabled:=true;

  if image1.top=120 then
   timer11.enabled:=true;

  if image1.top=120 then
   Label1.caption:=inttostr(4);

  if image1.top=0 then
   Label1.caption:=inttostr(5);

  if image1.top=240 then
   Label1.caption:=inttostr(3);

  if image1.top=360 then
   Label1.caption:=inttostr(2);

  if image1.top=480 then
   Label1.caption:=inttostr(1);

  if image1.top=600 then
   Label1.caption:=inttostr(0);

  button11.Enabled:=true;
  button8.Enabled:=true;
  button9.Enabled:=true;
  button10.Enabled:=true;
  button12.Enabled:=false;
  button13.Enabled:=true;

end;

procedure TForm1.Timer7Timer(Sender: TObject);

var

  x : integer;

begin
  timer7.enabled:=true;

  x:=2;
  Image1.top:=Image1.top+x;
  Image4.top:=Image4.top+x;
  Image5.top:=Image5.top+x;

  if image1.top=480 then
   timer7.enabled:=false;

  if image1.top=480 then
   timer11.enabled:=true;

  if image1.top=120 then
   Label1.caption:=inttostr(4);

  if image1.top=0 then
   Label1.caption:=inttostr(5);

  if image1.top=240 then
   Label1.caption:=inttostr(3);

  if image1.top=360 then
   Label1.caption:=inttostr(2);

  if image1.top=480 then
   Label1.caption:=inttostr(1);

  if image1.top=600 then
   Label1.caption:=inttostr(0);

end;

procedure TForm1.Timer8Timer(Sender: TObject);
var

   x : integer;

begin
  timer8.enabled:=true;

  x:=2;
  Image1.top:=Image1.top+x;
  Image4.top:=Image4.top+x;
  Image5.top:=Image5.top+x;

  if image1.top=360 then
   timer8.enabled:=false;

  if image1.top=360 then
   timer11.enabled:=true;

  if image1.top=120 then
   Label1.caption:=inttostr(4);

  if image1.top=0 then
   Label1.caption:=inttostr(5);

  if image1.top=240 then
   Label1.caption:=inttostr(3);

  if image1.top=360 then
   Label1.caption:=inttostr(2);

  if image1.top=480 then
   Label1.caption:=inttostr(1);

  if image1.top=600 then
   Label1.caption:=inttostr(0);

end;


procedure TForm1.Timer9Timer(Sender: TObject);
var

 x : integer;

begin
  timer9.enabled:=true;
  x:=2;
  Image1.top:=Image1.top+x;
  Image4.top:=Image4.top+x;
  Image5.top:=Image5.top+x;

  if image1.top=240 then
   timer9.enabled:=false;

  if image1.top=240 then
   timer11.enabled:=true;

  if image1.top=120 then
   Label1.caption:=inttostr(4);

  if image1.top=0 then
   Label1.caption:=inttostr(5);

  if image1.top=240 then
   Label1.caption:=inttostr(3);

  if image1.top=360 then
   Label1.caption:=inttostr(2);

  if image1.top=480 then
   Label1.caption:=inttostr(1);

  if image1.top=600 then
   Label1.caption:=inttostr(0);

end;


procedure TForm1.Timer10Timer(Sender: TObject);
var

  x : integer;

begin
  timer10.enabled:=true;

  x:=2;
  Image1.top:=Image1.top+x;
  Image4.top:=Image4.top+x;
  Image5.top:=Image5.top+x;

  if image1.top=120 then
   timer10.enabled:=false;

  if image1.top=120 then
   timer11.enabled:=true;

  if image1.top=120 then
   Label1.caption:=inttostr(4);

  if image1.top=0 then
   Label1.caption:=inttostr(5);

  if image1.top=240 then
   Label1.caption:=inttostr(3);

  if image1.top=360 then
   Label1.caption:=inttostr(2);

  if image1.top=480 then
   Label1.caption:=inttostr(1);

  if image1.top=600 then
   Label1.caption:=inttostr(0);

end;


procedure TForm1.Timer11Timer(Sender: TObject); // tür auf
var

  y : integer;

begin
  timer11.enabled:=true;

  y:=2;
  Image4.left:=Image4.left-y;

  if image4.left=30 then
   timer11.enabled:=false;

end;



procedure TForm1.Timer12Timer(Sender: TObject); // tür zu
var
   y : integer;

begin
  timer12.enabled:=true;

  y:=2;
  Image4.left:=Image4.left+y;

  if image4.left=100 then
    timer12.enabled:=false;

end;



procedure TForm1.Timer13Timer(Sender: TObject);

  var
   y : integer;

begin
  timer13.enabled:=true;

  y:=2;
  Image4.left:=Image4.left+y;

  if image4.left=100 then
    timer13.enabled:=false;
  if not timer13.enabled then
    timer2.enabled:=true;
end;

procedure TForm1.Timer15Timer(Sender: TObject);
var
   y : integer;

begin
  timer15.enabled:=true;

  y:=2;
  Image4.left:=Image4.left+y;

  if image4.left=100 then
    timer15.enabled:=false;
  if not timer15.enabled then
    timer4.enabled:=true;
end;

procedure TForm1.Timer16Timer(Sender: TObject);
var
   y : integer;

begin
  timer16.enabled:=true;

  y:=2;
  Image4.left:=Image4.left+y;

  if image4.left=100 then
    timer16.enabled:=false;
  if not timer16.enabled then
    timer5.enabled:=true;
end;

procedure TForm1.Timer17Timer(Sender: TObject);
var
   y : integer;

begin
  timer17.enabled:=true;

  y:=2;
  Image4.left:=Image4.left+y;

  if image4.left=100 then
    timer17.enabled:=false;
  if not timer17.enabled then
    timer6.enabled:=true;
end;

procedure TForm1.Timer18Timer(Sender: TObject);
var
   y : integer;

begin
  timer18.enabled:=true;

  y:=2;
  Image4.left:=Image4.left+y;

  if image4.left=100 then
    timer18.enabled:=false;
  if not timer18.enabled then
    timer1.enabled:=true;
end;



procedure TForm1.Timer14Timer(Sender: TObject);
var
   y : integer;

begin
  timer14.enabled:=true;

  y:=2;
  Image4.left:=Image4.left+y;

  if image4.left=100 then
    timer14.enabled:=false;
  if not timer14.enabled then
    timer3.enabled:=true;

end;

end.

würde mich freuen wenn es einige vorschläge gibt das programm funktioniert einwandfrei .
  Mit Zitat antworten Zitat