StrtoInt64Def convert error in delphi

628 Views Asked by At

I am having small program having ConvertFunction which converts the string data to other formats. The return type of function is Variant. When i use StrToIntDef to convert integer value then it does without any error.

But now my number is very large so I want to use int64 instead of integer. When i use StrToInt64def function to convert its giving me error, Incompatiable types:Variant and int64.

Below are the both codes. Any idea whats wrong in this?

Working:

function Convertfunction(sTest:String):Variant;
begin
  result:= StrtoIntDef(sTest,0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  sString: string;
  value:variant;
begin
  sString:= '123456';
  value:= Convertfunction(sString);
  showMessage(value);
end;

Not Working:

function Convertfunction(sTest:String):Variant;
begin
  result:= StrtoInt64Def(sTest,0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  sString: string;
  value:variant;
begin
  sString:= '12345678901';
  value:= Convertfunction(sString);
  showMessage(value);
end;
1

There are 1 best solutions below

0
On BEST ANSWER

Delphi 5 doesn't seem to have stock converter between int64 and variant. If you need it in your app you can

  • implement it (see manual on "custom variant types")
  • switch to more recent Delphi
  • switch to CodeTyphon or other Lazarus/FPC distro