Re: ASCII Codes

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

Posted by webmaster Guido on June 11, 2003 at 21:56:34:

In Reply to: Re: ASCII Codes posted by Brett Kingston on June 09, 2003 at 15:14:20:

: What data type is required for this?
: I have this working if I use a static value in the code (i.e. s := IntToStr(Ord('#'));), but if I want # to be replaced by the value of an input box, I keep getting errors. I have tried converting the input to a string, real, integer, but I have had no luck. Can someone help me with an example piece of code?

Ord(C) needs a parameter C of type "char" (character). So, this will work:

  AsciiVal: integer;
  C: Char;
  S: string;
  C := 'B';
  AsciiVal := Ord(C); // gives ASCII-code of 'B'
  AsciiVal := Ord(Edit1.Text[1]); // ASCII-code of first character of text in Edit1 
  S := 'Test';
  AsciiVal := Ord(S[2]); // ASCII-code of 'e'

But the following will not work:

  AsciiVal := Ord(Edit1.Text); // error because Edit1.Text is of type "string"

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