Board index » delphi » How to assign Variant ?

How to assign Variant ?

Hi !

I would like to know how to assign a variant to a variant.
In this example, I want to keep the record values in an array:

var
    intCounter: integer;
    vntRecord: array of Variant;
begin
   try
       SetLength(vntRecord, Fields.Count -1);
       for intCounter := 0 to (Fields.Count -1) do
           vntRecord[intCounter] := Fields[intCounter].Value;
       Insert;
   finally
       SetLength(m_vntRecord, 0); <---I get an Invalid pointer, because I
think that it is a pointer to Fields...
   end;
end;

Thanks

Alex

 

Re:How to assign Variant ?


Quote
> I would like to know how to assign a variant to a variant.
> In this example, I want to keep the record values in an array:

> var
>     intCounter: integer;
>     vntRecord: array of Variant;
> begin
>    try
>        SetLength(vntRecord, Fields.Count -1);

  Off by one error here, should be Fields.Count.
Quote
>        for intCounter := 0 to (Fields.Count -1) do

            vntRecord[intCounter] := Fields[intCounter].AsVariant;
Quote
>        Insert;
>    finally
>        SetLength(m_vntRecord, 0); <---I get an Invalid pointer, because I

  Is the m_ a typo, should this refer to the the local vntRecord variable
or to what?

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Re:How to assign Variant ?


I am sorry for the m_ , it is part of my unit, it is a member variable...
Consider this is vntRecord.

When I do
vntRecord[intCounter] := Fields[intCounter].AsVariant;
vntRecord[x] is a pointer on Fields[x], so I can't set vntRecord to nil nor
I can do SetLength.
So I need to copy Fields into vntVariant.

Thanks for your answer.

Alex

Peter Below <100113.1...@compuserve.com> a crit dans le message ...

Quote

>> I would like to know how to assign a variant to a variant.
>> In this example, I want to keep the record values in an array:

>> var
>>     intCounter: integer;
>>     vntRecord: array of Variant;
>> begin
>>    try
>>        SetLength(vntRecord, Fields.Count -1);
>  Off by one error here, should be Fields.Count.
>>        for intCounter := 0 to (Fields.Count -1) do
>            vntRecord[intCounter] := Fields[intCounter].AsVariant;
>>        Insert;
>>    finally
>>        SetLength(m_vntRecord, 0); <---I get an Invalid pointer, because I
>  Is the m_ a typo, should this refer to the the local vntRecord variable
>or to what?

>Peter Below (TeamB)  100113.1...@compuserve.com)
>No e-mail responses, please, unless explicitely requested!

Re:How to assign Variant ?


Quote
In article <72e98i$b...@forums.borland.com>, Alexandre DANVY wrote:
> When I do
> vntRecord[intCounter] := Fields[intCounter].AsVariant;
> vntRecord[x] is a pointer on Fields[x], so I can't set vntRecord to nil nor
> I can do SetLength.

How do you get this opinion? AsVariant returns the *value* of the field in a
variant, this is what you want, no?

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!

Other Threads