[fpc-pascal]When to use pointers with win32

Hans MÃ¥rtensson hm at os.dk
Sun Nov 24 20:35:52 CET 2002

Currently I am trying to learn windows programming with Free Pascal, but
I've got a problem with how to use the win32 unit and the (mmsystem unit as
well). The Free Pascal web site informs that the win32 unit implements all
the windows APIs, and refers to Microsoft or Delphi for further
documentation. But the documentation found there is written for C
programming. My problem is translating this into Pascal, due to the
difference between C and Pascal in using parameters in procedure calls.

Here is an example to explain what I mean:

In Pascal a procedure call like ‘someproc(data)' will pass either the value
of data OR the pointer to the data to the procedure, depending of how the
procedure is declared.

If the procedure is declared as:
‘Procedure someproc(data: sometype)'
then the value of the data will be passed

but if the procedure is declared as:
‘Procedure someproc(var data: sometype)'
the the pointer to the data will be passed.

Whereas in C, you can only pass values to the procedure (or function). Of
course it is possible to pass the pointer, but then you have to know this,
when calling the procedure. Your program line must be ‘someproc(&data)' for
passing the pointer.

When I read the documentation of the windows API, for each parameter in any
function it tells me whether I should pass the value or the pointer. So in
case of writing a C-program, there is no problem. But when using Pascal
with the win32 unit, I think it must be different. It would be a little
weird and agaist the beauty of Pascal to define a lot of pointers to be
used with this unit. So my guess is that the win32 unit has been
constructed as to use Pascal style procedure calls, so that
‘someproc(data)' sometimes pass the pointer to the data, namely when the
API wants the pointer. But does that always hold?
In the examples that comes with the Free Pascal installation, I have seen
that sometimes the address operator @ is used in a call to a procedure in
the win32 unit.

So my question is: How can I know when to use the data identifier and when
to use an address or pointer in a call to a procedure in the win32 unit?

Hans Maartensson

More information about the fpc-pascal mailing list