Solved

Variant String Problems

Posted on 2002-03-17
4
387 Views
Last Modified: 2010-04-02
Hi,

I am using Borland C Builder 5. I am trying to create a custom collection class, but I am having
problems with strings and variants. My add method takes in a TVariant*
which I then copy into a global TVariant using the VariantCopy method
(after using the VariantInit method on the global TVariant). When I
return it, I simply return a pointer to the global TVariant. The problem
is when the variant contains a string. Supposedly the VariantCopy method
copies the string however this does not appear to be happening. From a
VB client, if I access the value from the same function as I added it, I
get the right string, but if I access it from another function, where
the string is out of scope, I get a different string. What am I doing
wrong??

Thanks,

Zaphod.
0
Comment
Question by:Z_Beeblebrox
[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
4 Comments
 

Expert Comment

by:assermark
ID: 6876380
First, COM-support in BCB5 suffering from some serious bugs. If you intend do do some COM-programming in in BCB, and particular if your clients is not written in BCB, you should upgrade to ver.6, where (among other things) TVariant is exchanged to the VARIANT-structure.

In COM a client always should deallocate a returned string, and that is what your VB-client is doing. For that reason your server should return a copy, not a pointer to your local storage.

If you post some sourcecode it´s maby easyer to solve your problem.
0
 
LVL 7

Author Comment

by:Z_Beeblebrox
ID: 6878994
I figured it out, I was passing a pointer to the global variant and VB was changing it. So now I pass it a new variant.

Zaphod.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7085365
Hi Z_Beeblebrox,
You've requested to delete this question, but its status remains as 'Pending Delete' because one or more comments have been added.  Normally, the only way to fully delete such a Question is to post a message to Community Support and ask for assistance.

EE is making a one-time database sweep to purge the Pending Delete Questions automatically.  During this sweep:

    Z_Beeblebrox -- To allow the deletion to proceed:  Do nothing.
    EXPERTS -- Please DON'T POST a comment except to contest this deletion.

In the future, please refer to http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp#8 for instruction on deleting questions.

DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Accepted Solution

by:
Moondancer earned 0 total points
ID: 7104565
100 points refunded, moved to the PAQ and closed rather than deleted, since you added the solution and it may help others.
Moondancer - EE Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

752 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