Autor Beitrag
Tjeri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46



BeitragVerfasst: Fr 04.09.09 13:57 
Ich habe für mein Programm 2 funtions geschrieben, wobei die eine die andere benutzen soll:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
function TPokertisch.isPossible(var x:integer):boolean;
begin
  if (SpielerDabei[x]) AND (SpielerChips[x]>0)
    then result:=true
    else result:=false;
end;


Die Fehlermeldung kommt in der 2. function überall dort wo ich auf die erste zugreifen will:
ausblenden volle Höhe 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:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
function TPokertisch.naechsterSpieler(var aktuellerSpieler:integer):integer;
  var ende:boolean;
begin
  ende:=false;
  repeat
    Case aktuellerSpieler of
      1begin
           if isPossible(4)
             then
               begin
                 result:=4;
                 ende:=true;
               end
             else aktuellerSpieler:=4;
         end;
      2begin
           if isPossible(5)
             then
               begin
                 result:=5;
                 ende:=true;
               end
             else aktuellerSpieler:=5;
         end;
      3begin
           if isPossible(6)
             then
               begin
                 result:=6;
                 ende:=true;
               end
             else aktuellerSpieler:=6;
         end;
      4begin
           if isPossible(2)
             then
               begin
                 result:=2;
                 ende:=true;
               end
             else aktuellerSpieler:=2;
         end;
      5begin
           if isPossible(3)
             then
               begin
                 result:=3;
                 ende:=true;
               end
             else aktuellerSpieler:=3;
         end;
      6begin
           if isPossible(1)
             then
               begin
                 result:=1;
                 ende:=true;
               end
             else aktuellerSpieler:=1;
         end;
    end;
  until ende=true;
end;
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 04.09.09 14:01 
Moin!

Mach das mal so, dann passt das:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
function TPokertisch.isPossible(const x: Integer): Boolean;
begin
  Result := SpielerDabei[x] and (SpielerChips[x] > 0);
end;
Grund: Du hast einen Referenz-Parameter verlangt, aber eine Konstante übergeben. :idea:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.


Zuletzt bearbeitet von Narses am Fr 04.09.09 14:02, insgesamt 1-mal bearbeitet
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 04.09.09 14:01 
Du hast den Parameter als Var deklariert, übergibst aber eine Konstante (4). Ändere die erste Methode mal ab:
ausblenden Delphi-Quelltext
1:
function TPokertisch.isPossible(x:integer):boolean;					
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: Fr 04.09.09 14:02 
Hast du's schonmal ohne var probiert? Also so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
function TPokertisch.isPossible(x:integer):boolean;
begin
  if (SpielerDabei[x]) AND (SpielerChips[x]>0)
    then result:=true
    else result:=false;
end;


Desweiteren würde ich dir folgende Schreibweise empfehlen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
function TPokertisch.isPossible(var x:integer):boolean;
begin
  Result := (SpielerDabei[x]) AND (SpielerChips[x]>0);
end;


EDIT: Hab gar nicht gemerkt, dass so viele schneller waren als ich. :shock:


Zuletzt bearbeitet von Jakob_Ullmann am Fr 04.09.09 14:13, insgesamt 1-mal bearbeitet
Tjeri Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46



BeitragVerfasst: Fr 04.09.09 14:04 
Okay danke, hab keine Fehlermeldung mehr :-)