BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

pointer assignment not happening..

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Jeff Kish
Guest





PostPosted: Fri Jul 28, 2006 9:00 pm    Post subject: pointer assignment not happening.. Reply with quote



HI.

I have a dll with this method in it:


long getFormImageFromId(long lId, TFormImage * pForm)
{
for (vFormImageId_Iter iter = vFormImageIds.begin();
iter != vFormImageIds.end();
iter++)
{
FormImageId pImage = *iter;
if ((pImage.pForm != NULL) && (pImage.lId == lId))
// && (::IsWindow(pImage.pForm->Handle) != 0))
{
pForm = pImage.pForm; //this gets executed with a proper
//value assigned to pForm.
return myResultOK;
}
return myResultBAD;
}

I call it like this from inside another method in the dll:

TFormImage *pForm = NULL;
long lResult = getFormImageFromId(lId, pForm);



after the call, pForm is NULL, even though the pointer got assigned
inside the getFormImageFromId call.

shouldn't it of been assigned? I must be exhausted to miss the
obvious?

Thanks

Jeff Kish
Back to top
Clayton Arends
Guest





PostPosted: Fri Jul 28, 2006 9:20 pm    Post subject: Re: pointer assignment not happening.. Reply with quote



When pForm is set in the function the local pointer is changed and not the
caller. If you want to change the caller then the declaration of your
function needs to change. You either need a pointer to a pointer or a
reference to a pointer:

long getFormImageFromId(long lId, TFormImage ** pForm)
long getFormImageFromId(long lId, TFormImage *& pForm)

If you use the second one then you won't have to make any other changes to
your code. If you use the first one then you will have to dereference the
pointer in the function (*pForm = pImage.pForm) and change the call to the
function to pass a pointer to a pointer (&pForm).

HTH,
- Clayton
Back to top
Ed Mulroy
Guest





PostPosted: Fri Jul 28, 2006 9:20 pm    Post subject: Re: pointer assignment not happening.. Reply with quote



Quote:
long getFormImageFromId(long lId, TFormImage * pForm)
:
pForm = pImage.pForm; //this gets executed ...
:
after the call, pForm is NULL...

Shouldn't that be:
*pForm = pImage.pForm;
instead of
pForm = pImage.pForm;

Welcome to the 2+2=5 club. I've visited it many times.

.. Ed

Quote:
Jeff Kish wrote in message
news:vsckc2lqd124eacted88lk1l2o1hbopdfl (AT) 4ax (DOT) com...

I have a dll with this method in it:


long getFormImageFromId(long lId, TFormImage * pForm)
{
for (vFormImageId_Iter iter = vFormImageIds.begin();
iter != vFormImageIds.end();
iter++)
{
FormImageId pImage = *iter;
if ((pImage.pForm != NULL) && (pImage.lId == lId))
// && (::IsWindow(pImage.pForm->Handle) != 0))
{
pForm = pImage.pForm; //this gets executed with a proper
//value assigned to pForm.
return myResultOK;
}
return myResultBAD;
}

I call it like this from inside another method in the dll:

TFormImage *pForm = NULL;
long lResult = getFormImageFromId(lId, pForm);



after the call, pForm is NULL, even though the pointer got assigned
inside the getFormImageFromId call.

shouldn't it of been assigned? I must be exhausted to miss the
obvious?
Back to top
Jeff Kish
Guest





PostPosted: Fri Jul 28, 2006 9:42 pm    Post subject: Re: pointer assignment not happening.. Reply with quote

On Fri, 28 Jul 2006 09:20:01 -0700, "Clayton Arends"
<nospam_claytonarends (AT) hotmail (DOT) com> wrote:

Quote:
When pForm is set in the function the local pointer is changed and not the
caller. If you want to change the caller then the declaration of your
function needs to change. You either need a pointer to a pointer or a
reference to a pointer:

long getFormImageFromId(long lId, TFormImage ** pForm)
long getFormImageFromId(long lId, TFormImage *& pForm)

If you use the second one then you won't have to make any other changes to
your code. If you use the first one then you will have to dereference the
pointer in the function (*pForm = pImage.pForm) and change the call to the
function to pass a pointer to a pointer (&pForm).

HTH,
- Clayton
Thanks, yes it does.


Quote:

Shouldn't that be:
*pForm = pImage.pForm;
instead of
pForm = pImage.pForm;

Welcome to the 2+2=5 club. I've visited it many times.

. Ed
getting old is entirely overrated.


Thanks

I guess I should of remembered I could change things dereferenced by
the pointer, but not the pointer value itself.... sigh.
Jeff Kish
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.