![]() |
Re: Kreuzung - Timer funktioniert nicht
Dein Problem lösen 2 zusätzliche "else". Das wurde bereits genannt und sogar von Deddy erklärt.
Was du machst, ist eine Ampel, wie man sie im Kindergarten malt: Rot - Gelb - Grün. Tatsächlich sind die Ampeln bei uns Rot - Rot/Gelb - Gelb - Grün (du scheinst Beiträge nur zu überfliegen, wenn überhaupt ...) Aber das war nur ein Hinweis. Wenn du es nicht an die Realität anlehnen willst, musst du das natürlich nicht. |
Re: Kreuzung - Timer funktioniert nicht
Das von DeddyH hatte ich eben nicht verstanden:
Zitat:
Ich weiß das die Ampeln so schalten: Rot - Rot/Gelb - Gelb - Grün und dazu habe ich auch schon geantwortet: Ich bin zu faul. Wieso sollte es mit einem weiteren Image besser klappen? Also lasse ich es raus! Danke für deine Antwort, ich werde es mal mit else probieren. |
Re: Kreuzung - Timer funktioniert nicht
Wofür denn ein weiteres Image? Es gibt doch nur 3 Lämpchen und somit 3 Images:
Delphi-Quellcode:
;)
if (ImgRot.Visible) and (ImgGelb.Visible) then
// Rot/Gelb else if ImgRot.Visible then // Rot else if ImgGelb.Visible then // Gelb else if ImgGruen.Visible then // Grün Naja das Problem ist nun geklärt. Viel Spaß noch. |
Re: Kreuzung - Timer funktioniert nicht
Liste der Anhänge anzeigen (Anzahl: 1)
Das geht übrigens auch ohne else, wenn man Logik und Darstellung trennt. Das Beispiel im Anhang besteht aus 3 Shapes, einem Timer und einer Unit mit 43 Zeilen (bei meiner Art der Codeformatierung).
|
Re: Kreuzung - Timer funktioniert nicht
Aha.. Würdest du mir auch den Text mal hochladen? Ich würde mal gerne sehen wie man das ohne else machen kann...
Mfg Ghost |
Re: Kreuzung - Timer funktioniert nicht
Rein theoretisch gibt's zig Möglichkeiten, eine könnte so aussehen:
Delphi-Quellcode:
In den If-Anweisungen kannst du dann deine Images entsprechend ein- bzw. ausblenden.
var
Ampelzustand: Integer; // ... // Rot if Ampelzustand = 1 then Ampelzustand := 2; // Rot Gelb if Ampelzustand = 2 then AmpelZustand := 3; // Gelb if Ampelzustand = 3 then AmpelZustand := 4; // Grün if AmpelZustand = 4 then AmpelZustand := 1; |
Re: Kreuzung - Timer funktioniert nicht
OK, ein "else" ist doch dabei hab ich gerade gesehen :lol:
Delphi-Quellcode:
unit AmpelMain;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls; type TAmpelzustand = (azRot, azGelbRot, azGruen, azGelb); TFormAmpel = class(TForm) shpRot: TShape; shpGelb: TShape; shpGruen: TShape; Timer1: TTimer; procedure Timer1Timer(Sender: TObject); private { Private-Deklarationen } FZustand: TAmpelzustand; public { Public-Deklarationen } end; var FormAmpel: TFormAmpel; implementation {$R *.dfm} procedure TFormAmpel.Timer1Timer(Sender: TObject); begin if FZustand < High(TAmpelzustand) then inc(FZustand) else //hier ist das einzige else FZustand := Low(TAmpelzustand); shpRot.Visible := FZustand in [azRot,azGelbRot]; shpGelb.Visible := FZustand in [azGelb,azGelbRot]; shpGruen.Visible := FZustand = azGruen; end; end. |
Re: Kreuzung - Timer funktioniert nicht
Oha das übersteigt jetzt aber meine Kentnisse. Naja danke für die Antworten jetzt werde ich mir das schon zurecht"schnibbeln" können.
Mit freundliochen Grüßen Ghostleader |
Re: Kreuzung - Timer funktioniert nicht
Habe auch einen:
Delphi-Quellcode:
:mrgreen:
var
at: array [0..3,0..3] of integer = ((1,0,0,5500),(1,1,0,500),(0,0,1,5000),(0,1,0,1000)); procedure TForm1.Timer1Timer(Sender: TObject); begin shape1.Visible := boolean(at[Timer1.Tag, 0]); shape2.Visible := boolean(at[Timer1.Tag, 1]); shape3.Visible := boolean(at[Timer1.Tag, 2]); Timer1.Interval := at[Timer1.Tag, 3]; if Timer1.Tag > 2 then Timer1.Tag := 0 else Timer1.Tag:= Timer1.Tag +1; end; |
Re: Kreuzung - Timer funktioniert nicht
Wird das jetzt wieder so ein "negative Zahlen"-Thread? :mrgreen: Zum besseren Verständnis hier mein Timer-Ereignis noch einmal in längerer Form:
Delphi-Quellcode:
Ist das so verständlicher?
procedure TFormAmpel.Timer1Timer(Sender: TObject);
begin case FZustand of azRot : FZustand := azGelbRot; azGelbRot: FZustand := azGruen; azGruen : FZustand := azGelb; azGelb : FZustand := azRot; end; if (FZustand = azRot) or (FZustand = azGelbRot) then shpRot.Visible := true else shpRot.Visible := false; if (FZustand = azGelb) or (FZustand = azGelbRot) then shpGelb.Visible := true else shpGelb.Visible := false; if FZustand = azGruen then shpGruen.Visible := true else shpGruen.Visible := false; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:20 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz