Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This forum is the most helpful site I've ever used. I used to use Deja.com; but, this site is better - hands down!..."

Geography

Where in the world do Tek-Tips members come from?

Problem with "Variant" Data Type inside a Record

ddverne (Programmer)
8 Apr 12 15:13
Hi Guys,

I'm having some trouble when I'm trying to Initialize a constant record when one of the types is a "VARIANT" one.

For example:

This WORKS:

const
   myRec : array [0..1] of record Num : integer; Str : string; end =
   (
     (Num: 100; Str: 'ABC'),
     (Num: 200; Str: 'DEF')
   );


But this don't

const
   myRec : array [0..1] of record Num : integer; Str : string; Test : Variant end =
   (
     (Num: 100; Str: 'ABC'; Test : VarArrayCreate([0,1], varInteger)),
     (Num: 200; Str: 'DEF')
   );


In fact what I want to do is create an Array inside my Record for generic data type and length, it should be something like this:

const
   myRec : array [0..1] of record Num : integer; Str : string; Test : Variant end =
   (
     (Num: 100; Str: 'ABC'; Test : Array[0..2] of Variant = ('a', 100, 33.33)),
     (Num: 200; Str: 'DEF'; Test : Array[0..1] of Variant = ('b', 200))
   );

Is this possible?

Thanks,

ddVerne.
DjangMan (Programmer)
9 Apr 12 11:56
I don't think records can take complex data types like a Variant.

http://www.delphibasics.co.uk/RTL.asp?Name=Record

Could you use an object for this?  It wouldn't be much more code for the constructor, etc and gives you far more options.
ddverne (Programmer)
9 Apr 12 19:16
Hi DjangMan,

In fact I could create a class etc. But I would like to try this without using objects, since it will be a constant and everything is already done, my only concern is about to using a data type which could store (pre-determined) array length of some type of data.

Let's forget about 'Variant' and think about Integers:

There is a way to do something like this?

const
   myRec : array [0..1] of record Num : integer; Str : string; Test : SomeData end =
   (
     (Num: 100; Str: 'ABC'; Test : Array[0..2] of Integer = (1, 2, 3)),
     (Num: 200; Str: 'DEF'; Test : Array[0..1] of Integer = (4, 5))
   );

Or for example defining "Test as Pointer" and point to an array which was already initialized?

Like this:

const
   Array1 : Array[0..2] of Integer(0,1,2);
   Array2 : Array[0..1] of Integer(3,4);

   myRec : array [0..1] of record Num : integer; Str : PInteger; Test : SomeData end =
   (
     (Num: 100; Str: 'ABC'; Test : @Array1),
     (Num: 200; Str: 'DEF'; Test : @Array2)
   );


I really appreciate any any help.

Thanks,

ddverne.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close