Re: Delphi ORD FunctionPosted by webmaster Guido on June 11, 2003 In Reply to: Delphi ORD Function posted by Brett Kingston on June 09, 2003
: What data type is required for Delphi's ORD Function? If InputChar is a TEdit component, then there are two errors: * i := InputChar.Text; gives an error because InputChar.Text is of type "string", and you declared i as an "integer". * Ord(i) gives an error because ORD() only works on values of type "char" (character), and you declared i as an "integer". The following will return the ASCII-code of the first character of the Edit-box: var i : integer; S: string; begin S := inputChar.Text; if Length(S) > 0 then begin i := Ord(S[1]); // ASCII code of first character of S lblNum.Caption := IntToStr(i); end else lblNum.Caption := 'Please, type something in the Edit-box'; end;
[ DelphiLand: free Delphi source code, tips, tutorials ] |
|