IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Haim on July 02, 2006, 07:39:59 AM

Title: New() pointer question
Post by: Haim on July 02, 2006, 07:39:59 AM
I am confused about the usage of New(..) in Aurora.
I saw in several samples that poiners to UDT's are declared, and the members of the UDT are then assigned and the UDT passed to some function. (without using New)
In other cases I noted that New(UDT,1) is used first.

When should I use New and when can the pointer to the UDT be used directly?

Can someone explain this to me?
Title: Re: New() pointer question
Post by: Ionic Wind Support Team on July 02, 2006, 09:39:45 AM
New in Aurora is no different then in IBasic.  With the exception that it works for classes as well.

Show me what your confused about, what example code?
Title: Re: New() pointer question
Post by: Haim on July 02, 2006, 11:16:09 PM
I was looking at 'advanced listview sample' - the code for OnNotify, that has a pointer to an NMHDR structure as an argument.
This argument is then used to retrieve data. It is never explicitly allocated with new(), but it works fine.

On the other hand when I tried to use SendMessageA(m_hwnd,Lvm_subitemhittest,0,pinfo) (pinfo being a pointer to LVHittestinfo, It worked properly only after assigning the pointer with pinfo=new(LVhittestinfo,1);

It seems as if sometimes the called function takes care of allocating the pointer, but not always.
What are the rules?








Title: Re: New() pointer question
Post by: Ionic Wind Support Team on July 03, 2006, 06:45:04 AM
In that instance Windows is doing the allocation and sending the pointer in a message (WM_NOTIFY).



Title: Re: New() pointer question
Post by: Haim on July 03, 2006, 07:16:55 AM
Thanks.
If I understand correctly there is no rule. Every function may behave differently. I will have to look up the documentation...   :-\
Title: Re: New() pointer question
Post by: Ionic Wind Support Team on July 03, 2006, 07:23:11 AM
Well of course there are rules.

All of the the OnXXX handlers are windows messages.  If Windows sends you a pointer then you can be sure it is safe to access.

You can't just define a pointer and access it without initializing it first.  Address of a variable, memory allocated with NEW, etc.  An unitialized pointer, also known as a NULL pointer, will make your program crash.

If your using sendmessage and sending some window a pointer through a message then you are responisible for the memory.

With all pointers you should test for NULL first before acessing though. 

Paul.
Title: Re: New() pointer question
Post by: Haim on July 03, 2006, 10:37:39 PM
Thanks for the explanation.