• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2510
  • Last Modified:

How to change an Variant to Int64 or vice versa

Tell me please! How to change a Variant to Int64 or vice versa
0
liyuncheng
Asked:
liyuncheng
  • 2
1 Solution
 
xiaomin8184Commented:
change??
if you mean convert:
var
  a:variant;
  i:integer;
  b:int64;
begin
  a:=123;
  i:=a;
  b:=i;
end;
0
 
liyunchengAuthor Commented:
>>xiaomin8184

if a int64 is larger than max_int, your code above may result in data loss!
0
 
geobulCommented:
Hi,

Try this:

function VariantToInt64(v: Variant): Int64;
begin
  result := StrToInt64(Format('%20s',[v]));
end;

function Int64ToVariant(v: Int64): Variant;
begin
  result := Variant(Format('%20d',[v]));
end;

// test:
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Int64;
  v: Variant;
begin
  i := Int64(MAXINT) + 100;
  v := Int64ToVariant(i);
  ShowMessage(IntToStr(MAXINT) + ' ' + Format('%20d',[VariantToInt64(v)]));
end;

Regards, Geo
0
 
xiaomin8184Commented:
sorry,my mistake
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now