![]() |
Ordinaltyp bei case of
Hallo,
ich habe jetzt seit 2 Wochen Info und wir sollen eine Ampel programmieren. ich bin jetzt soweit: Problem: In der zeile case zustand of kommt die Meldung Ordinaltyp benötigt. keine Ahnung wie das geht. Hoffe auf eure Hilfe...
Delphi-Quellcode:
implementation
{$R *.dfm} procedure TForm1.Button2Click(Sender: TObject); begin halt; end; procedure TForm1.FormCreate(Sender: TObject); begin w:= 390; h:= 510; setbounds((screen.Width-w)div 2,(screen.Height-h)div 2,w,h) end; procedure TForm1.Button1Click(Sender: TObject); begin case 'zustand' of 1: begin Sh_red.Brush.Color :=clRed; Sh_yellow.Brush.Color :=clWhite; Sh_lime.Brush.Color:=clWhite; end; 2: begin Sh_red.Brush.Color :=clRed; Sh_yellow.Brush.Color :=clYellow; Sh_lime.Brush.Color:=clWhite; end; 3: begin Sh_red.Brush.Color :=clWhite; Sh_yellow.Brush.Color :=clWhite; Sh_lime.Brush.Color:=clLime; end; 4: begin Sh_red.Brush.Color :=clWhite; Sh_yellow.Brush.Color :=clYellow; Sh_lime.Brush.Color:=clLime; end; end; if zustand >4 then zustand := 1; end; end. |
Re: Ordinaltyp bei case of
Hallo,
ich vermute das "zustand" eine Integer-Variable ist. durch die zwei anführungszeichen machst du einen String richtig muss es heissen:
Delphi-Quellcode:
case zustand of
|
Re: Ordinaltyp bei case of
Hallo, nimm die '' raus, dann klappts, Case muß Ordinal sein, kein String.
Edit: Ups, da war einer schneller :wink: |
Re: Ordinaltyp bei case of
Nach case muss eine Integervariable oder eine Charvariable übergeben werden. Oder wie willst du sonst prüfen? ;)
Mach also einfach die '' von zustand weg. |
Re: Ordinaltyp bei case of
Zitat:
|
Re: Ordinaltyp bei case of
Vielen vielen Dank für die Hilfe.
Ich habe das ganze geändert, aber wenn ich das Projekt starte und auf Button 1 klickt passiert überhaupt nichts. :( |
Re: Ordinaltyp bei case of
Hi
Zitat:
Delphi-Quellcode:
if zustand > 4 then zustand := 1;
|
Re: Ordinaltyp bei case of
Wird zustand überhaupt irgendwo zugewiesen?
|
Re: Ordinaltyp bei case of
Du solltest im OnCreate der Form der Variable "zustand" einen bestimmten Wert zu weisen, z. B. 1
Die Abfrage:
Delphi-Quellcode:
wird dir nicht viel bringen, da deine Ampel nach Zustand = 4 wieder auf Zustand = 1 springen muss.
if zustand >4 then zustand := 1;
Bei deiner If-Abfrage würd dies erst bei Zustand = 5 oder höher passieren. du solltest:
Delphi-Quellcode:
schreiben.
if zustand = 4 then zustand := 1;
Wenn du diese Hinweise befolgst, dann dürf deine Ampel auch ampeln :-) |
Re: Ordinaltyp bei case of
Wow . das ist echt klasse hier :) So viele schnelle Hilfe. Vielen Danke ich probiers aus :)
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:59 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-2025 by Thomas Breitkreuz