Autor Beitrag
ruhrpott-desire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 23



BeitragVerfasst: So 19.08.07 16:35 
Hallo,
Wir haben in der Schule angefangen etwas mit Delphi zumachne, jetzt hab ich zuhause auch mal ein bisschen rumgespielt und komme zu folgendem Ergebnis:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
unit Ampel;

interface

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

type
  TForm1 = class(TForm)
    draw: TButton;
    change: TButton;
    auto: TButton;
    red_part: TShape;
    yellow_part: TShape;
    green_part: TShape;
    ampel_case: TShape;
    procedure drawClick(Sender: TObject);
    procedure changeClick(Sender: TObject);



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

var
  Form1: TForm1;
  count: integer;

implementation

{$R *.dfm}


procedure TForm1.drawClick(Sender: TObject);
begin
   ampel_case.visible := true;
   red_part.visible := true;
   red_part.Brush.Color := RGB(255,127,127);
   yellow_part.visible := true;
   yellow_part.Brush.Color := RGB(255,255,224);
   green_part.visible := true;
   green_part.Brush.Color := RGB(152,251,152);

end;

procedure TForm1.changeClick(Sender: TObject);
begin
count :=0;
farbwechsel;
end;

procedure farbwechsel;
begin
 red_part.Brush.Color := clred;
 count := 1;
end;




end.


Es ist ein vollkommen einfaches Programm und ich habe auch nicht lange dafür gebraucht, allerdings check ich das mit den Prozeduren nicht so wirklich xD
Ich hatte schon, wie in einigen google Ergebnissen oben bei type was reingesetzt, aber der richtige Erfolg ist ausgeblieben :lol:

Ich denke mal, dass da ein kleiner Fehler drin ist den ich einfach nicht finde bzw. nicht kenne ^^
Die Fehlermeldung lautet:
Fehler Ampel.pas[58] Undefinierter Bezeichner: 'red_part'

Moderiert von user profile iconChristian S.: Quote- durch Delphi-Tags ersetzt
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: So 19.08.07 16:48 
Probier's mal so:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
unit Ampel; 

interface 

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

type 
  TForm1 = class(TForm) 
  draw: TButton; 
  change: TButton; 
  auto: TButton; 
  red_part: TShape; 
  yellow_part: TShape; 
  green_part: TShape; 
  ampel_case: TShape; 
  procedure drawClick(Sender: TObject); 
  procedure changeClick(Sender: TObject); 
  procedure farbwechsel;

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

var 
  Form1: TForm1; 
  count: integer; 

implementation 

{$R *.dfm} 

procedure TForm1.drawClick(Sender: TObject); 
begin 
  ampel_case.visible := true; 
  red_part.visible := true; 
  red_part.Brush.Color := RGB(255,127,127); 
  yellow_part.visible := true; 
  yellow_part.Brush.Color := RGB(255,255,224); 
  green_part.visible := true; 
  green_part.Brush.Color := RGB(152,251,152); 
end; 

procedure TForm1.changeClick(Sender: TObject); 
begin 
  count :=0; 
  farbwechsel; 
end; 

procedure TForm1.farbwechsel; 
begin 
  red_part.Brush.Color := clred; 
  count := 1; 
end; 

end.


Gruß

Calculon
--
ruhrpott-desire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 23



BeitragVerfasst: So 19.08.07 18:23 
Danke!!! Das läuft schonmal,
Jetzt stehe ich aber vor dem Problem, dass er die einzelnen Ampelschaltungen durchlaufen soll... Also von Rot auf Rot/Gelb dann auch Grün von da dann wieder auf Gelb und dann auf Rot.
Kann man es in eine if clause schreiben, dass er bei jedem Klick auf ein anderes Ereignis eingeht?!
also z.b

if btnclick
then
changecolor;

??

mfg
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: So 19.08.07 19:13 
Hi!
Was hälst du denn von Case? Mal ganz grob:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
 case Count of
    0: color = rot;
    1: begin
          color = gelb;
          // foo
       end;
    2: color = grün;
 end;

In der Farbwechsel-Prozedur Count erhöhen und bei Count = 2 auf Null zurückspringen. :)

grüße


€: Nebenbei: Neue Frage, neues Topic. ;)
hkk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 64

Win XP Pro, Win ME, openSUSE 10.2, Ubuntu 7.xx; Firefox 2 (en-US)
D7 Pers, D3 Prof
BeitragVerfasst: So 19.08.07 19:37 
ich werde marc.'s beispiel ein wenig auszuweiten, um es dir verständlicher zu machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.changeClick(Sender: TObject); 
begin 
  farbwechsel;
end; 

procedure TForm1.farbwechsel; 
begin 
  case Count of
    0: color = rot;
    1: begin
          color = gelb;
          [...]
       end;
    2: color = grün;
  end; 
  count := count + 1; 
end;


~HKK

PS: wie marc. gesagt hat, bei sowas lieber ein neues topic ^^
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 20.08.07 18:00 
Moin und :welcome: im Forum!

Die Ampel-Aufgabe hatten wir hier schon öfter, schonmal nach Suche in: Delphi-Forum, Delphi-Library AMPEL gesucht? :idea: Liefert u.A. auch diesen Beitrag. :les: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
ruhrpott-desire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 23



BeitragVerfasst: Mo 20.08.07 18:16 
Also ich ahbe das ganze jetzt soweit bekommen, ich musste noch etwas ändern, da imemr ein Fehler kam... Jetzt kommt noch ein Fehler:
Konstantenausdruck erwartet bei "count := count+1;"
Hier der Code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
unit Ampel;

interface

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

type
  TForm1 = class(TForm)
    draw: TButton;
    change: TButton;
    auto: TButton;
    red_part: TShape;
    yellow_part: TShape;
    green_part: TShape;
    ampel_case: TShape;
    procedure drawClick(Sender: TObject);
    procedure changeClick(Sender: TObject);
    procedure farbwechsel;
    procedure rot;
    procedure rotgelb;
    procedure gruen;
    procedure gelb;
    

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

var
  Form1: TForm1;
  count: integer;

implementation

{$R *.dfm}


procedure TForm1.drawClick(Sender: TObject);
begin
   ampel_case.visible := true;
   red_part.visible := true;
   red_part.Brush.Color := RGB(255,127,127);
   yellow_part.visible := true;
   yellow_part.Brush.Color := RGB(255,255,224);
   green_part.visible := true;
   green_part.Brush.Color := RGB(152,251,152);

end;

procedure TForm1.changeClick(Sender: TObject);
begin
farbwechsel;

end;

procedure TForm1.farbwechsel;
begin 
  case Count of
    0: rot;
    1: begin
          rotgelb;

       end;
    2: begin
    gruen;

       end;
       3:
       begin
       gelb;
       end;
      count := count+1;

     end;
  end;
procedure TForm1.rot;
begin
 red_part.Brush.Color := clred;
end;


  procedure TForm1.rotgelb;
  begin
  red_part.Brush.Color := clred;
  yellow_part.Brush.Color := clyellow;

  end;


   procedure TForm1.gruen;
   begin
   red_part.Brush.Color := RGB(255,127,127);
   yellow_part.Brush.Color := RGB(255,255,224);
   green_part.Brush.Color := clgreen
   end;

  procedure TForm1.gelb;
  begin
  yellow_part.Brush.Color := clyellow;
  green_part.Brush.Color := RGB(152,251,152);
  red_part.Brush.Color := RGB(255,127,127);
   end;





end.


Danke für die Hilfe!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 20.08.07 18:27 
Moin!

user profile iconruhrpott-desire hat folgendes geschrieben:
Jetzt kommt noch ein Fehler:
Konstantenausdruck erwartet bei "count := count+1;"

Wenn du den Code vernünftig einrücktest, dann fiele es dir vielleicht auch selbst auf: :mahn: ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm1.farbwechsel;
begin 
  case Count of
    0: rot;
    1: rotgelb;
    2: gruen;
    3: gelb;
  end;
  count := count +1;
end;

Du mußt die case-Anweisung erst abschließen, dann die Variable verändern! :idea: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
ruhrpott-desire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 23



BeitragVerfasst: Mo 20.08.07 18:39 
Hi,
Vielen Dank für die Hilfe, wie gesagt, hab grad erst angefangen ich glaub das Anspruchvollste Programm bis jetzt war ein Formular wo man auf Klick geschriebenes Hizufügen kann lol
Das war mehr aus ehrgeiz.
Vielen Dank an alle!!!