March 2000
Intermediate to advanced
576 pages
18h 13m
English
Ord Function
function Ord(A: AnsiChar): Integer;
function Ord(C: Char): Integer;
function Ord(W: WideChar): Integer;
function Ord(E: Enumerated type): Integer;
function Ord(I: Integer): Integer;
function Ord(I: Int64): Int64;The Ord function returns the ordinal value of a
character or enumeration as a non-negative integer. Calling
Ord on an integer argument is a no-op, returning
its argument. Ord is not a real
function.
You can cast an ordinal variable to an integer type to get its
ordinal value. Calling the Ord function is better
because it states clearly and directly what the code is doing.
// The TypInfo unit provides the GetEnumName function that returns
// the name of an enumerated value, given its TypeInfo pointer and
// its ordinal value. Using GetEnumName, you can write functions
// such as the following, which converts a Boolean to a string.
function BoolToStr(B: Boolean): string;
begin
Result := GetEnumName(TypeInfo(Boolean), Ord(B));
end;| AnsiChar Type, Char Type, Chr Function, Type Keyword, WideChar Type |
Read now
Unlock full access