Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help with variant and time datatypes Posted by csbrmg on 30 Jun 2003 at 8:07 AM
Question 1
How can you create a variable that can be changed from one data type to another during run time.Which data type would be better variant or a byte array

Question 2
I need help in converting the entire byte array into a specific data type .At the moment i can only know how to convert a specific byte into some value

Question 3
Are there any datatype variables in delphi that allow you to store a time calue without a date at the moment i can only find a data type TTimeField which i think is supposed to be used as a form component but i only want to store the time not display or store it on a form

Report
Re: Help with variant and time datatypes Posted by zibadian on 30 Jun 2003 at 8:32 AM
: Question 1
: How can you create a variable that can be changed from one data type to another during run time.Which data type would be better variant or a byte array
:
A byte array can hold all types, while a variant is automatically converted. So either type has its pros and cons. If memory is an issue, I would suggest a byte array, since that is somewhat smaller, but otherwise are variants shorter to code.

: Question 2
: I need help in converting the entire byte array into a specific data type .At the moment i can only know how to convert a specific byte into some value
:
You can use the Move() routine for that. Here is an example to copy a float into a byte array, and back again.
  SetLength(ByteArray, SizeOf(myFloat));
  Move(MyFloat, ByteArray, Length(ByteArray));
  ... { code using the ByteArray }
  Move(ByteArray, MyFloat, Length(ByteArray));

Obviously this method has a huge inherent danger: you can easily type-cast the bytearray into a variable, which is too small. This might lead to loss of data.

: Question 3
: Are there any datatype variables in delphi that allow you to store a time calue without a date at the moment i can only find a data type TTimeField which i think is supposed to be used as a form component but i only want to store the time not display or store it on a form
:
There are no purely time types. You can always use a TDateTime typed variable, and just ignore the date part.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.