Autor Beitrag
WeBsPaCe
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 29.01.05 14:46 
Hallole!! :D

Hab' folgenden Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
case Edit1.Text of
'StringderimEdit1steht': Form1.Close;
else
//Mach was anderes
end;


Jetzt sagt Delphi aber:
ausblenden Error Messages:
1:
2:
[Error] Unit1.pas(47): Ordinal type required
[Error] Unit1.pas(48): Incompatible types: 'Integer' and 'String'

Warum denn das?? Wie muss das richtig heißen??

Danke schonmal, gell??


Moderiert von user profile iconGausi: Topic aus Sonstiges verschoben am Sa 29.01.2005 um 13:54

_________________
Steht der Bauer im Gemüse, hat er später grüne Füße.


Zuletzt bearbeitet von WeBsPaCe am Sa 29.01.05 14:55, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 29.01.05 14:48 
Moin!

Das sagt doch der Compiler:
ausblenden Quelltext
1:
Ordinal type required					

Strings sind so schlecht "aufzählbar"... :wink: (-> geht nur z.B. mit Integer).

Für Strings mußt du if-then-else nehmen.

cu
Narses

//EDIT: meine "Beeindruckung" verliert sich aber grade wieder leicht... :lol: :wink:
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 29.01.05 14:53 
Ehrlich nicht?? :D

Ich such eigentlich nur ne Möglichkeit, wie ich verschiedene Strings abfragen kann, also wenn Edit1 Hanswurst ist dann mach das, wenn's Wienerwust ist dann mach das und wenn's keins von beidem ist, dann mach das... :D

PS.: Ne StringList muss es nicht sein, soviele Abfragen sind's nich.. Da ist if-else besser..

//EDIT: @Narses Die muss nich verfliegen, ich kenn das nur vom C++:switch

_________________
Steht der Bauer im Gemüse, hat er später grüne Füße.
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Sa 29.01.05 15:00 
Hi,

Sieh dir dochmal diesen FAQ-Beitrag an.

raziel

_________________
JSXGraph
WeBsPaCe Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2322
Erhaltene Danke: 1

FireFox 3, Internet Explorer 6 SP1
D1, D3Prof, D6Pers, D7Pers+Indy, VisualStudio Express
BeitragVerfasst: Sa 29.01.05 15:07 
Alles klar, vielen Dank!!! Ich nehm aber wahrscheinlich doch if-else... ;)

_________________
Steht der Bauer im Gemüse, hat er später grüne Füße.
MitschL
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 211

Win 98 SE, Win 2000
D5 Pers, D6 Pers und D7 Pro
BeitragVerfasst: Mo 31.01.05 11:54 
Ähm,

@raziel: Die String-Case-Lösung ist aber so nicht uneingeschränkt nutzbar.
Der Eintrag muß vorhanden sein, weil es sonst zu einer falschen Lösung kommt, weil es zu einer 'Lösung' kommt. Somit wird der Case-zweig auch gar nicht genutzt.

ich würd sowas machen:
ausblenden 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:
Function CaseStr( Value: String; Args: Array of String; Sensitive: Boolean ): Integer;  
var found: Boolean;
Begin  
  found := false;
  
  If Sensitive Then
    For Result := High( Args ) DownTo 0 Do  
      If CompareStr( Value, Args[ Result ] ) = 0 Then 
      begin
        found := true;
        Break;
      end
  Else 
    For Result := High( Args ) DownTo 0 Do  
      If CompareText( Value, Args[ Result ] ) = 0 Then 
      begin
        found := true;
        Break;
      end;

  if not found then
    Result := -1;

End;


gegrüßt!

PS.: Paßt zwar nur mittelbar hier hin, stach mir aber nur durch den Link von Dir im Auge rum und sollte IMHO nicht unbeachtet bleiben.

_________________
"Bloßes Ignorieren ist noch keine Toleranz." (Theodor Fontane)