?
Solved

How to change an Variant to Int64 or vice versa

Posted on 2003-03-18
4
Medium Priority
?
2,434 Views
Last Modified: 2010-05-19
Tell me please! How to change a Variant to Int64 or vice versa
0
Comment
Question by:liyuncheng
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Expert Comment

by:xiaomin8184
ID: 8158122
change??
if you mean convert:
var
  a:variant;
  i:integer;
  b:int64;
begin
  a:=123;
  i:=a;
  b:=i;
end;
0
 

Author Comment

by:liyuncheng
ID: 8158209
>>xiaomin8184

if a int64 is larger than max_int, your code above may result in data loss!
0
 
LVL 17

Accepted Solution

by:
geobul earned 150 total points
ID: 8158299
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
 

Expert Comment

by:xiaomin8184
ID: 8158483
sorry,my mistake
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question