Re: Int and Str usage
Posted by webmaster Guido on June 11, 2003 at 22:27:12:
In Reply to: Int and Str usage posted by Joey on June 10, 2003 at 22:08:14:
: How do i use an interger in a string?
: What i mean is that; i'm making a kinda game where you fiddle with a population of people and control things they do! So that you can use cheats i want to use a string then an integer... So it would be like this (what would be typed to cheat):
: Populate: 7889
: This setting the population to 7889 (if you need to know it sets a hidden spinedit.value to this number) i want to check it says 'populate: ' then if thats there it checks the int after it and sets the spinedit.value to that!
: At the momment i have but i dont know what to do with anything about the int:
: procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
: Please could you help me set spinedit1.value to a number following 'populate: '?
: Thanks ;), Joey
From the top of my head, so you'll have to check if the syntax is really correct ;-) ...
var P, ErrCode: integer; begin if LowerCase(Copy(Edit1.Text, 1, 10) = 'populate: ' then begin Val(Copy(Copy(Edit1.Text, 11, Length(Edit1.Text), P, ErrorCode); if ErrCode := 0 then Spinedit1.Value := P; end else Label1.Caption := 'Cheat Unkown or...'; end;
[ DelphiLand: free Delphi source code, tips, tutorials ]