Autor Beitrag
SignsOfCore
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Di 25.11.08 22:23 
Huhu,

ja ich mal wieder :P


So, also folgendes Problem:
Bei dem Script kann man Lose kaufen und bei jedem Kauf soll 5 Geld abgezogen werden. Das klappt aber nicht so ganz :/

Variablen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  Form1: TForm1;
  x : Integer;
  Geld : Integer = 500;
  Los : Integer;
  Gewinn : Integer;


Auszug aus dem Problemscript:
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:
procedure TForm1.loskaufClick(Sender: TObject);
begin
randomize;
Los := random(100) + 1;
Geld := Geld - 5;

if Los = 6 then
gewinnlos.Caption := 'Glückwunsch! Du hast 30€ gewonnen';
gewinnlos.Visible := true;
Gewinn := 30;

if Los =  30 then
gewinnlos.Caption := 'Glückwunsch! Du hast 20€ gewonnen';
gewinnlos.Visible := true;

if Los =  74 then
gewinnlos.Caption := 'Glückwunsch! Du hast 20€ gewonnen';
gewinnlos.Visible := true;

if Los =  52 then
gewinnlos.Caption := 'Glückwunsch! Du hast 50€ gewonnen';
gewinnlos.Visible := true;

if Los =  95 then
gewinnlos.Caption := 'Glückwunsch! Du hast 10€ gewonnen';
gewinnlos.Visible := true;

if Los =  15 then
gewinnlos.Caption := 'Jackpot!! 500 €! Herzlichen Glückwunsch!';
gewinnlos.Visible := true;

end;

end.



Nun kommt aber folgender Fehler: Operator ist auf diesen Operandentyp nicht anwendbar.




Gruß
Core
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Di 25.11.08 22:38 
Spontan fällt mir da ein anderer Fehler auf:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if Los = 6 then
   gewinnlos.Caption := 'Glückwunsch! Du hast 30€ gewonnen';
gewinnlos.Visible := true;
Gewinn := 30;

Du weißt, dass alle Zeilen ausser der Eingerückten Zeile bedingungslos ausgeführt werden? ;) Dir fehlen Begin-End blocks:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
if Los = 6 then
begin
   gewinnlos.Caption := 'Glückwunsch! Du hast 30€ gewonnen';
   gewinnlos.Visible := true;
   Gewinn := 30
end;

Aber in der markierten Zeile kommt Operator auf diesem Operandentyp nicht anwendbar? Hmm... :gruebel:

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Di 25.11.08 22:40 
Aus dem Codeteil ist für mich erstmal kein Fehler ersichtlich, vielleicht liegt der Fehler woanders?
Aber versuch mal
ausblenden Delphi-Quelltext
1:
dec (geld, 5);					

stattdessen.
freak4fun
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 604
Erhaltene Danke: 4

Win 7 Pro
VS 2013 Express, Delphi, C#, PHP, Java
BeitragVerfasst: Di 25.11.08 22:46 
Das "gewinnlos.Visible := true;" ist auch jedes mal drin, also redundant.

_________________
"Ich werde auf GAR KEINEN Fall…!" - "Keks?" - "Okay, ich tu's."
i++; // zaehler i um 1 erhoehen
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mi 26.11.08 16:14 
lade doch vielleicht mal alle Dateien (außer der exe) hoch, dann kann ichs mal testen.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 26.11.08 17:49 
Hat es einen Grund, weshalb du deine Variable so und nicht anders initialisierst? :gruebel:
SignsOfCore Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Mi 26.11.08 20:32 
ausblenden Delphi-Quelltext
1:
  dec (geld, 5);					

klappt leider auch nicht. "Inkompatible Typen"...

Boldar hochladen möchte ist es noch nicht, tut mir Leid. Die Codeschnipsel müssen reichen ;)



Sonst noch einer eine Idee?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 26.11.08 20:37 
Klar ist: Der Code ist so wie du ihn gepostet hast fehlerfrei kompilierbar. Der Fehler liegt woanders, ich vermute du hast die Variable Geld nochmal weiter oben in der Formulardeklaration als String oder so deklariert und da du dich innerhalb des Formulars befindest wird diese zuerst betrachtet.

user profile iconSignsOfCore hat folgendes geschrieben Zum zitierten Posting springen:
Boldar hochladen möchte ist es noch nicht, tut mir Leid. Die Codeschnipsel müssen reichen ;)
Glaubst du wirklich, dass du etwas in deinem Code hast was irgendwie interessant für jemanden ist, der etwas besser Delphi kann? :lol:
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Mi 26.11.08 20:40 
user profile iconSignsOfCore hat folgendes geschrieben Zum zitierten Posting springen:
Sonst noch einer eine Idee?
Massig - die hängen alle vom Rest deines Codes ab, wie jaenicke gesagt hat. Wenn du den unbedingt geheim halten willst, aus welchen unerfindlichen Gründen auch immer, dann kann ich dir leider nicht helfen, meine Kristallkugel hab ich für Studiengebühren versetzen müssen :cry:

Edit @jaenicke: Jaaaaaah so hab ich das jetzt nicht formulieren wollen :lol:

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



BeitragVerfasst: Mi 26.11.08 21:35 
Da habters :P

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:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
unit fertig;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Image2: TImage;
    Image1: TImage;
    Image3: TImage;
    Image4: TImage;
    Timer1: TTimer;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Geld: TLabel;
    roulette: TButton;
    stehlen: TButton;
    spielend: TButton;
    new: TButton;
    GroupBox1: TGroupBox;
    lose: TButton;
    Label1: TLabel;
    ueberschrift: TLabel;
    text: TLabel;
    text1: TLabel;
    text2: TLabel;
    text3: TLabel;
    text4: TLabel;
    loskauf: TButton;
    uebersicht: TButton;
    gewinnlos: TLabel;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure loseClick(Sender: TObject);
    procedure loskaufClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  x : Integer;
  Geld : Integer = 500;
  Los : Integer;
  Gewinn : Integer;
implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  inc(x);
  case x of
    1:
    begin
      Image1.Visible := true;
     end;
    2:
    begin
      Image3.Visible := true;
    end;
    3:
    begin
      Image4.Visible := true;
           end;
    4:
    begin
      Label1.Visible := true;
    end;
    5:
    begin
      Button3.Visible := true;
      Timer1.Enabled := false;
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     x:= Integer  (0);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled := true;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Label1.Visible := false;
Image1.Visible := false;
Image3.Visible := false;
Image4.Visible := false;
Button3.Visible := false;

uebersicht.Visible := true;
lose.Visible := true;
GroupBox1.Visible := true;
new.Visible := true;
stehlen.Visible := true;
roulette.Visible := true;
spielend.Visible := true;
Geld.Visible := true;


end;

procedure TForm1.loseClick(Sender: TObject);
begin
ueberschrift.caption := '>> Übersicht';
text.caption := 'Du hast Geld.' ;
text1.caption := 'Und hast:'  ;
text2.caption := ' mal Lotto gespielt';
text2.caption := ' mal gestohlen';
text4.caption := ' mal Roulette gespielt...';
ueberschrift.visible := true;
text.visible := true;
text1.visible := true;
text2.visible := true;
text3.visible := true;
text4.visible := true;
loskauf.visible := true;

end;

procedure TForm1.loskaufClick(Sender: TObject);
begin
randomize;
Los := random(100) + 1;
  dec (geld, 5);

if Los = 6 then
gewinnlos.Caption := 'Glückwunsch! Du hast 30€ gewonnen';
gewinnlos.Visible := true;
Gewinn := 30;

if Los =  30 then
gewinnlos.Caption := 'Glückwunsch! Du hast 20€ gewonnen';
gewinnlos.Visible := true;
Gewinn := 20;

if Los =  74 then
gewinnlos.Caption := 'Glückwunsch! Du hast 20€ gewonnen';
gewinnlos.Visible := true;
Gewinn := 20;

if Los =  52 then
gewinnlos.Caption := 'Glückwunsch! Du hast 50€ gewonnen';
gewinnlos.Visible := true;
Gewinn := 50;

if Los =  95 then
gewinnlos.Caption := 'Glückwunsch! Du hast 10€ gewonnen';
gewinnlos.Visible := true;
Gewinn := 10;

if Los =  15 then
gewinnlos.Caption := 'Jackpot!! 500 €! Herzlichen Glückwunsch!';
gewinnlos.Visible := true;
Gewinn := 500;

end;

end.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 26.11.08 21:43 
Und daran liegts. ;)
user profile iconSignsOfCore hat folgendes geschrieben Zum zitierten Posting springen:
Da habters :P

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
[...]
type
  TForm1 = class(TForm)
    [...]
    Geld: TLabel;
    [...]
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  x : Integer;
  Geld : Integer = 500;
  Los : Integer;
  Gewinn : Integer;

Nenne eines von beidem um, um eindeutig auf das Label oder auf die Variable zuzugreifen. :zwinker:
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mi 26.11.08 21:44 
Naja, du hast Geld einmal als Tlabel definiert und einmal als integer, kein wunder das da was schief läuft.
Benenne das Lable einfach in Label_geld um...

Edith sagt: mist, zu spät...
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: Mi 26.11.08 21:46 
Tja, wie schon vermutet wurde, hast Du Deine Integer-Variable genau wie ein TLabel genannt. TLabel wird in diesem Fall bevorzugt behandelt, und dekrementieren kann man ein Label halt nicht.

Gewöhn Dir an sogenannte Prefixe vor die Varaiblen- und Komponentennamen zu schreiben. In Deinem Fall würde sich für das TLabel z.B. lblGeld anbieten; das Prefix lbl steht dabei für Label (ohne Vokale halt). Und schon kann sowas nicht mehr so schnell passieren. Ausserdem ist so auf einem Blick sichtbar um was es sich bei der Variable handelt.

_________________
Ich streite einsam mich mit dieser Oberflächenwelt
Gutes sei ein löblich Brot von dem ich zehre - bis zum Tod [Das Ich - Im Ich]
SignsOfCore Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Do 27.11.08 14:38 
Dankeschön! Klappt wunderbar nur hab ich jetzt noch eine Frage.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
if Los =  61 then
begin
Geld := Geld + 500;
gewinnlos.Caption := 'Jackpot!! 500 €! Herzlichen Glückwunsch!';
  end;


Er schreibt zwar die 500 "Geld" gut, aber er ändert die Caption von "gewinnlos" nicht.
Wenn ich beide vertausche macht er immer das erste. Idee?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 27.11.08 14:42 
Bist du sicher, dass du überall begin..end stehen hast? Vielleicht wird die Caption später einfach erneut geändert.