Autor Beitrag
rizor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: So 24.09.06 18:23 
Hi,

habe ein Problem mit meinem case.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
case sb.String[i] of
   'd': d:=d+1;
   'h': h:=h+1;
   's': s:=s+1;
   'c': c:=c+1;
end;


er erwartet einen bezeichner ?!

Wo ist da der fehler?
Falls es am string liegt, wie kann ich das prob beheben?
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 24.09.06 18:26 
Eine Case-Anweisung mit strings klappt nicht. Du musst mit if-else-if Schleifen arbeiten. Allerdings hab ich irgendwo in der Library mal ne Routine gesehen, die das konnte, kannst ja mal nachforschen. ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 24.09.06 18:35 
du könntest über den ASCII-Code des Zeichens gehen.

_________________
Markus Kinzler.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: So 24.09.06 18:40 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
if sb.Strings[i]='d' then
          d:=d+1
        else
          begin
            if sb.Strings[i]='h' then
            h:=h+1
            else
            begin
              if sb.Strings[i]='s' then
              s:=s+1
              else
              c:=c+1;
            end;
          end;
Ldiamond.caption:='Karo '+IntToStr(d);


habe das prob jetzt so gelöst.
Nun habe ich aber das problem, dass er mir a,h,s,c nicht ausgibt.
habe natürlich die labels erstellt.

Woran liegt das?
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 24.09.06 18:51 
hallo rizor,

kannst mal ein wenig mehr code bringen (z.b. wie SB definiert ist). danke.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 24.09.06 18:56 
user profile iconGrenzgaenger hat folgendes geschrieben:
hallo rizor,

kannst mal ein wenig mehr code bringen (z.b. wie SB definiert ist). danke.

Ich nehme mal an, es sind StringListen
Aber die Frage ist was in .Strings[i] drinnsteht wirklich nur 'd' oder mehr?

_________________
Markus Kinzler.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 24.09.06 18:56 
Hilft das vielleicht weiter?
www.delphi-library.d...ighlight=case+string

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: So 24.09.06 18:58 
stimmt, es sind stringlisten.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
 
i:=0;
    b:=TStringList.Create;
    b.Delimiter:= ' ';
    b.DelimitedText := Eboard.Text;
    while i<>b.count do
      begin
        sb:=TStringList.Create;
        sb.Delimiter:= '.';
        sb.DelimitedText := b.Strings[i];
        i:=i+1;
      end;

so sieht der text aus, der für die erstellung zuständig ist.

also können in sb nur d,h,s,c stehen, da es ein programm für poker werden soll.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 24.09.06 19:00 
Steht da 'd' oder 'dp'( Dame Pik) oder so was drin?

_________________
Markus Kinzler.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: So 24.09.06 19:03 
nein, da steht nur d
dame pik würde so aussehen d.p und dann würde er die einelnen teile ja in einzelnen string-arrays speichern.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 24.09.06 19:07 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
case ord(sb.String[i]) of
   ord('d'): d:=d+1;
   ord('h'): h:=h+1;
   ord('s'): s:=s+1;
   ord('c'): c:=c+1;
end;

Hiermit müsste es gehn: ord wandelt ein Char in seinen Ansi-Code um, der eine Zahl ist (Byte glaub ich) => case klappt.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 24.09.06 19:07 
Du erzeugst viele unnötigen Instanzen von sb. Eine reicht.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
   b:=TStringList.Create;
    sb:=TStringList.Create;
    ...
    b.Delimiter:= ' ';
    b.DelimitedText := Eboard.Text;
    for i := 0 to b.count-1 do
      begin
        sb.Delimiter:= '.';
        sb.DelimitedText := b.Strings[i];
        case ord( sb.Strings[i][1]) of
          Ord('d'):
...
      end;

_________________
Markus Kinzler.
Grenzgaenger
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 24.09.06 19:10 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button1Click(Sender: TObject);
var
 sl: tstringlist;
begin
 sl := tstringlist.create;
 try
  sl.add('test');
  case char(sl.Strings[0][1]) of
   't': sb.SimpleText := 'test';
   else sb.SimpleText := 'fehler im case';
  end;
 finally
  sl.free;
 end;
end;


@marco d: also bei mir funktioniert der case.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: So 24.09.06 19:41 
das mit ord funktioniert nicht.
er gibt mir den fehler, dass ein bezeichner fehlt, aber string gefunden wurde.
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: So 24.09.06 19:43 
Code?

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 24.09.06 19:44 
Zitat:
das mit ord funktioniert nicht.
er gibt mir den fehler, dass ein bezeichner fehlt, aber string gefunden wurde.

Auf welche Lösung beziehst du dich jetzt?

_________________
Markus Kinzler.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: So 24.09.06 19:48 
auf deine.
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 24.09.06 19:49 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
case ord(sb.String[i][1]) of
   ord('d'): d:=d+1;
   ord('h'): h:=h+1;
   ord('s'): s:=s+1;
   ord('c'): c:=c+1;
end;

Mein Fehler, TStringlist[1] ist ja ein String, also muss man ein [1] anfügen um das erste zeichen zu nehmen.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: So 24.09.06 19:52 
wieso 1?
muss es nicht zwei sein?
es wird ja für dame pik d.s eingegeben.
da muss ich doch 2 nehmen damit ich die kartenart ermitteln kann, oder?

@mkinzler geht doch, habe einen fehler gemacht.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 24.09.06 19:53 
Deshalb habe ich nachgefragt ;-)

_________________
Markus Kinzler.