[fpc-pascal]When to use pointers with win32
peter at freepascal.org
Mon Nov 25 07:21:01 CET 2002
>> 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).
>> course it is possible to pass the pointer, but then you have to know
>> when calling the procedure. Your program line must be someproc(&data)'
>> passing the pointer.
>> When I read the documentation of the windows API, for each parameter in
>> function it tells me whether I should pass the value or the pointer. So
>> 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.
> We also fell for this trap, but in general it is wisest to keep the
> This because many win32 (and also POSIX) routines accept a NIL pointer as
> value (often meaning something like use default for this parameter).
>> 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
>> that sometimes the address operator @ is used in a call to a procedure
>> the win32 unit.
>> So my question is: How can I know when to use the data identifier and
>> to use an address or pointer in a call to a procedure in the win32 unit?
> Check the source of the definition. Most are pointers, but some are not
> because Delphi decided to use const and var.
> If you really hate the C specifications of the win32 api, try to find the
> (somewhat old) win32 helpfile on the Borland site. I don't have an URL
> they frequently reorder things.
The header files are translated from C. Where Delphi defined a definition
with const or var parameters then that version is added as an overloaded
definition. So you can use both the C calling with passing the address. Or
use the Delphi way with passing a value to a var parameter
More information about the fpc-pascal