Re: Int and Str usage


[ Delphi Forum ] [ Delphi Tutorials -- by DelphiLand ]

Posted by webmaster Guido on June 16, 2003 at 18:15:03:

In Reply to: Re: Int and Str usage posted by Joey on June 12, 2003 at 19:51:40:

: The code up above generated the following errors:

: [Error] Unit1.pas(33): Incompatible types: 'String' and 'Boolean'
: ... and so on...
: i got rid of some of the errors by deleting certain things but i dont realy know if there relative to the solution:

: var
: P, ErrCode: integer;
: begin
: if 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;

: I just deleted the LowerCase statement (dint understand what it was making at).
: It would be realy helpful if you could help me ;) dont want to be a problem its just i was realy intrested in how this works.
-----------------------------------

Sorry... I'll never do that again, posting code without checking it in Delphi ;-)
So here we go again, this time with an example that was tested:

procedure TForm1.Button1Click(Sender: TObject);
var
  P, ErrCode: integer;
begin
  ErrCode := 1;
  // LowerCase is used so that the user can type "populate:"...
  // ...as well as "POPULATE:" or "Populate:"
  if LowerCase(Copy(Edit1.Text, 1, 10)) = 'populate: ' then
    Val(Copy(Edit1.Text, 11, Length(Edit1.Text)), P, ErrCode);
  if ErrCode = 0 then
    Spinedit1.Value := P
  else
    Label1.Caption := 'Cheat Unkown or...';
end;

Related Articles and Replies:


[ Delphi Forum ]
[ DelphiLand: free Delphi source code, tips, tutorials ]