 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jeff Kish Guest
|
Posted: Fri Jul 28, 2006 9:00 pm Post subject: pointer assignment not happening.. |
|
|
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
|
Posted: Fri Jul 28, 2006 9:20 pm Post subject: Re: pointer assignment not happening.. |
|
|
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
|
Posted: Fri Jul 28, 2006 9:20 pm Post subject: Re: pointer assignment not happening.. |
|
|
| 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
|
Posted: Fri Jul 28, 2006 9:42 pm Post subject: Re: pointer assignment not happening.. |
|
|
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 |
|
 |
|
|
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
|
|