Re: [fpc-pascal] Pointers in Pascal!!

2008-04-29 Thread Mattias Gaertner
On Wed, 30 Apr 2008 01:22:47 +0200 Marc Weustink <[EMAIL PROTECTED]> wrote: > Alan Krause wrote: > > Hans MÃ¥rtensson wrote: > >> But that would not work after the pointer was used and then it's > >> memory freed. > >> So a better way might be: > >> > >> Always when declaring pointers do it this

Re: [fpc-pascal] Pointers in Pascal!!

2008-04-29 Thread Marc Weustink
Alan Krause wrote: Hans MÃ¥rtensson wrote: But that would not work after the pointer was used and then it's memory freed. So a better way might be: Always when declaring pointers do it this way: var p: ^sometype = nil; Then in stead of using the freemem, define your own procedure: procedur

Re: [fpc-pascal] Pointers in Pascal!!

2008-04-29 Thread Alan Krause
Hans MÃ¥rtensson wrote: But that would not work after the pointer was used and then it's memory freed. So a better way might be: Always when declaring pointers do it this way: var p: ^sometype = nil; Then in stead of using the freemem, define your own procedure: procedure myfreemem(var p: p

Re: [fpc-pascal] Pointers in Pascal!!

2008-04-29 Thread Hans MÃ¥rtensson
Joao Morais wrote: Jonas Maebe wrote: On 29 Apr 2008, at 15:35, Zaka E-Lab wrote: It's possible to give a default initialization value to a defined type? No, that is not possible. Except if your pointer is declared as a member of a class (which is always assigned to nil by default)

Re: [fpc-pascal] Pointers in Pascal!!

2008-04-29 Thread Joao Morais
Jonas Maebe wrote: On 29 Apr 2008, at 15:35, Zaka E-Lab wrote: It's possible to give a default initialization value to a defined type? No, that is not possible. Except if your pointer is declared as a member of a class (which is always assigned to nil by default) ___

Re: [fpc-pascal] Pointers in Pascal!!

2008-04-29 Thread Jonas Maebe
On 29 Apr 2008, at 15:35, Zaka E-Lab wrote: It's possible to give a default initialization value to a defined type? No, that is not possible. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/li

Re: [fpc-pascal] Pointers in Pascal!!

2008-04-29 Thread Zaka E-Lab
It's possible to give a default initialization value to a defined type? I suppose that it isn't, but it would be to easy to resolve that trouble that way. Anyway, I appreciate your help and support. Thanks. Zaka. Jonas Maebe escribió: It cannot know that without help. You have to do such book

Re: [fpc-pascal] Pointers in Pascal!!

2008-04-29 Thread Jonas Maebe
On 29 Apr 2008, at 14:48, Zaka E-Lab wrote: I don't create anything, the memory is allocated by the create procedure. How can the procedure know if the argument is a pointer already allocated or not? It cannot know that without help. You have to do such bookkeeping yourself (e.g., as mentio

Re: [fpc-pascal] Pointers in Pascal!!

2008-04-29 Thread Zaka E-Lab
Maybe I haven't explain it correctly. What I want is to construct a Unit that contains some procedures, one of them is create(var p : PStruct), and other is delete(var p : PStruct). I don't create anything, the memory is allocated by the create procedure. How can the procedure know if the argumen

Re: [fpc-pascal] Pointers in Pascal!!

2008-04-29 Thread Leonardo M. Ram�
You can assign "nil" to the pointer before using it, then check if PStruct = nil it wasn't created. Leonardo. --- Zaka E-Lab <[EMAIL PROTECTED]> wrote: > I have something like this: > > PStruct = ^Struct; > Struct = record > num: integer; > end; > > I have a unit to ha

[fpc-pascal] Pointers in Pascal!!

2008-04-29 Thread Zaka E-Lab
I have something like this: PStruct = ^Struct; Struct = record num: integer; end; I have a unit to handle that structure ( is a bit more complicated, but is a good example), in this unit I have a procedure that deletes ( disposes ) the pointer. How can I know if a pointer a