DelphiBasics
StrToInt64
Function
Convert an integer string into an Int64 value SysUtils unit
 function StrToInt64 ( IntegerString : string ) : Int64;
Description
The StrToInt64 function converts an Integer string, IntegerString such as '123' into an Int64 return value.
 
It supports +ve and -ve numbers, and hexadecimal numbers, as prefixed by $ or 0x.
Notes
The EConvertError exception is thrown if there are errors in IntegerString, such as trailing blanks, decimal points, invalid decimal or hexadecimal characters.
Related commands
Int64 A 64 bit sized integer - the largest in Delphi
IntToStr Convert an integer into a string
StrToInt Convert an integer string into an Integer value
StrToInt64Def Convert a string into an Int64 value with default
StrToIntDef Convert a string into an Integer value with default
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.




 
Example code : Converting decimal and hexadecimal numbers
var
  A, B, C, D, E, F : Int64;

begin
  A := 32;
  B := StrToInt64('100');    // '100' string converted to 100 integer
  C := StrToInt64('  -12');  // Leading blanks are ignored
  D := StrToInt64('$1E');    // Hexadecimal values start with a '$'
  E := StrToInt64('-0x1E');  // ... or with a '0x'
  F := A + B + C + D + E;  // Lets add up all these integers

  ShowMessage('A : '+IntToStr(A));
  ShowMessage('B : '+IntToStr(B));
  ShowMessage('C : '+IntToStr(C));
  ShowMessage('D : '+IntToStr(D));
  ShowMessage('E : '+IntToStr(E));
  ShowMessage('F : '+IntToStr(F));
end;
Show full unit code
   A :  32
   B : 100
   C : -12
   D :  30
   E : -30
   F : 120
 
Example code : Catching string to integer conversion errors
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  SysUtils,   // Unit containing the StrToInt64 command
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  A : Int64;

begin
  // We will catch conversion errors
  try
    A := StrToInt64('100 ');    // Trailing blanks are not supported
  except
    on Exception : EConvertError do
      ShowMessage(Exception.Message);
  end;

  try
    A := StrToInt64('$FG');    // 'G' is an invalid hexadecimal digit
  except
    on Exception : EConvertError do
      ShowMessage(Exception.Message);
  end;
end;
 
end.
Hide full unit code
   '100 ' is not a valid integer value
   '$FG' is not a valid integer value
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page