Autor Beitrag
Bäääm
Hält's aus hier
Beiträge: 13

WIN XP
Delphi 7 Enterprises, Delphi 2005 Prof.
BeitragVerfasst: Di 05.02.08 19:21 
Mein Problem:

Ich möchte ein Label.Caption, dass sich im Laufe des Spiels verändert, in einen Integerwert umwandeln. Am Ende soll überprüft werden, ob Label.Caption höher als das Limit 100 ist.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Pot_lbl.Caption := StrToInt(hv{Hilfsvariable});
Application.ProcessMessages;

// Zuweisen der Werte in die Variablen Limit A

If u_Spieleinstellungen.Spieleinstellungen_Form.Limit_combo.Text = '100' then
 begin
  LimitA := 100;
 end;

If Pot_lbl.Caption > LimitA then
 begin
  showmessage('Gewonnen');
 end;


Fehlermeldung: String und Integer inkompatible typen!

Ich hoffe ihr versteht mein problem!

Danke schonmal für eure Hilfe;


Zuletzt bearbeitet von Bäääm am Di 05.02.08 19:23, insgesamt 1-mal bearbeitet
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Di 05.02.08 19:22 
strtoint()
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 05.02.08 20:40 
Was für eine Typ hat hv?
Sollte es nicht IntToStr() heißen?

_________________
Markus Kinzler.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Di 05.02.08 20:42 
user profile iconBäääm hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
If Pot_lbl.Caption > LimitA then {...}					

Da brauchst du eindeutig StrToInt. Also:

ausblenden Delphi-Quelltext
1:
If StrToInt(Pot_lbl.Caption) > LimitA then {...}					
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 05.02.08 20:46 
Warum nicht hv heranziehen?

_________________
Markus Kinzler.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Di 05.02.08 22:06 
user profile iconmkinzler hat folgendes geschrieben:
Warum nicht hv heranziehen?


Was ist hv?
strToInt ist eindeutig das einfachste.
Wenn du nicht sicher bist, ob ein integerwert drinsteht nimm tryStrToInt(siehe dazu bitte die Delphi-Hilfe oder das Internet)

Kann es auch eine Kommazahl sein entsprechend strToFloat und tryStrToFloat.

Edit:
user profile iconBäääm hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
Pot_lbl.Caption := StrToInt(hv{Hilfsvariable});
{...}


Aso... bitte gebe Variablen selbsterklärende Namen! Hilfsvariable wäre besser.
Du brauchst den Wert nicht zwischenzuspeichern.

mfG,
Daniel

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
DrRzf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 260

Win XP Prof
D7 Enterprise
BeitragVerfasst: Mi 06.02.08 03:27 
ausblenden Delphi-Quelltext
1:
Pot_lbl.Caption := IntToStr(hv{Hilfsvariable}); //hier ist StrToInt am falsche platz					

_________________
rein statistisch gesehen darf man keiner statistik trauen die man nicht selbst gefälscht hat.