[fpc-pascal]help with pointers?

Ivan Montes senbei at terra.es
Sat Oct 20 01:35:25 CEST 2001


> ok - i can handle that... but i was using the result of assigned to decide
> if i should free the memory when i was finished with it, i.e. if p<>nil
then
> freemem(p);  what should i do instead?
>
> ron.

Hi,

Let me explain this with an example. In a program you implement a function
called InitPointers that initializes your variables. Then you create another
function called ClosePointers that frees your variables. If you call first
InitPointers and after ClosePointers everything should be fine. But not if
you do in the opposite way (first ClosePointers).

So every time you want to free a pointer you have to be sure that the
pointer was initialized. If you don't want to assign any memory to the
pointer, just declare ptrvar:=NIL. And then you will be sure that
Freemem(ptrvar); will not give problems, even if ptrvar is NIL.

bye, Ivan






More information about the fpc-pascal mailing list