Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Variant String Problems

Posted on 2002-03-17
4
Medium Priority
?
391 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

705 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