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
Solved

Variant String Problems

Posted on 2002-03-17
4
383 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

808 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