![]() |
Case of funktioniert nicht
Hallo zusammen!
ich bin neu hier und wollte mal nachfragen, ob hier jemand eine Lösung für mein Problem hat. Und zwar geht es um folgendes: Für mein Studium muss ich ein kleines Delphi-Projekt programmieren (in der Ausgestaltung sind wir frei). Ich habe nun mehrere Comboboxen. Ich möchte jeweils eine Combobox mit einer anderen Combobox durch eine Case of Struktur verbinden. Um es besser nachzuvollziehen habe ich den Quelltext eingefügt:
Delphi-Quellcode:
usw...
procedure TForm2.Button2Click(Sender: TObject);
begin case combobox2.ItemIndex of 0: begin case combobox3.ItemIndex of 0: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001 /9.87*0); 1: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001 /9.87*1); 2: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001 /9.87*2); 3: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001 /9.87*3); 4: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001 /9.87*4); 5: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001 /9.87*5); end; case combobox2.ItemIndex of 1: begin case combobox3.ItemIndex of 0: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073 /9.87*0); 1: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073 /9.87*1); 2: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073 /9.87*2); 3: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073 /9.87*3); 4: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073 /9.87*4); 5: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073 /9.87*5); end; Für den ersten Abschnitt, also case combobox2.itemindex of 0:... funktioniert alles. Für den Rest leider nicht. Es wird mir allerdings auch keine Fehlermeldung angezeigt. Was mache ich falsch? Bin noch blutiger Anfänger und hoffe, dass ihr mir helfen könnt :oops: Grüße |
AW: Case of funktioniert nicht
"Funktioniert nicht" ist keine nachvollziehbare Fehlermeldung. Bitte beschreibe doch genau, was du erwartest und was stattdessen eintritt.
|
AW: Case of funktioniert nicht
Liste der Anhänge anzeigen (Anzahl: 1)
Case in einem case? Bist du dir sicher dass du das wolltest? Siehe Bild im Anhang.
|
AW: Case of funktioniert nicht
.. ginge das nicht auch ohne case of
Delphi-Quellcode:
Grüße
edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073
/9.87*combobox3.ItemIndex); Klaus |
AW: Case of funktioniert nicht
Ohje, das ist ja mal ne ganze Spaghetti-Code-Mahlzeit, die mindestens für 8 Personen ausreicht, ohne das "usw." beachtet zu haben. Ich schätze mal, das kann man alles auf wenige Zeilen reduzieren. Versuch mal "Edit4.Text :=" nur ein einzigesmal in den Code zu bringen.
|
AW: Case of funktioniert nicht
Das Problem ist: der Fall combobox2.ItemIndex > 0 wird niemals abgearbeitet! Formatier das Ganze mal und und achte auf die Begin ... End Blöcke! Dann siehst Du, das alles im Fall combobox2.ItemIndex = 0 steht.
|
AW: Case of funktioniert nicht
So wie ich das sehe, verwendest du immer
Delphi-Quellcode:
Wobei sich die 0.4 abhängig von ComboBox2.ItemIndex ändert, die 0 abhängig von ComboBox3.ItemIndex (genauer gesagt entspricht sie die ItemIndex)
edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001/9.87*0);
Wieso also nicht:
Delphi-Quellcode:
procedure TForm2.Button2Click(Sender: TObject);
var MagicNumber1: Integer; MagicNumber2: Double; begin MagicNumber1 := ComboBox3.ItemIndex; case ComboBox2.ItemIndex of 0: MagicNumber2 := 0.4; 1: MagicNumber2 := 0.9; {was auch immer hier noch folgen kann} end; edit4.Text:= FloatToStr( MagicNumber2*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001/9.87*MagicNumber1); end; Wobei man das natürlich auch noch weiter optimieren kann... |
AW: Case of funktioniert nicht
@ baumina: ja ich bin mir da sogar ziemlich sicher, dass das viel kompakter geht. Nur habe ich nicht mehr allzuviel Zeit, mir da was zu überlegen..mit copy paste gehts dann doch relativ zügig..
@ULIK: Was meinst du mit formatieren? ich dachte ein begin hinter dem ersten itemindex und ein end nach den Anweisungen für den jeweiligen itemindex reicht aus? Vielen Dank für die schnellen Antworten! |
AW: Case of funktioniert nicht
Mit formatieren meint er vermutlich das:
Delphi-Quellcode:
case combobox2.ItemIndex of
0: begin case combobox3.ItemIndex of 0: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001/9.87*0); 1: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001/9.87*1); 2: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001/9.87*2); 3: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001/9.87*3); 4: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001/9.87*4); 5: edit4.Text:= FloatToStr(0.4*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000001/9.87*5); end; case combobox2.ItemIndex of //diese Zeile muss vermutlich einfach weg? 1: begin case combobox3.ItemIndex of 0: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073/9.87*0); 1: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073/9.87*1); 2: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073/9.87*2); 3: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073/9.87*3); 4: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073/9.87*4); 5: edit4.Text:= FloatToStr(0.9*StrToFloat(edit11.Text)*8*StrToFloat(edit1.Text)*StrToFloat(edit1.Text)/0.00000002073/9.87*5); end; end; end; end; end; |
AW: Case of funktioniert nicht
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:57 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