[fpc-devel] Parameters must match exactly?

Graeme Geldenhuys graemeg.lists at gmail.com
Mon May 17 10:27:24 CEST 2010

Michael Van Canneyt het geskryf:
> You only need var/out when you want to change the instance pointer, i.e. 
> switch to another instance. And I count FreeAndNil() among this. (.Free
> on the other hand is still possible, but not recommended).
> If  you just want to set properties or call methods on an existing instance,
> there is no need to use out or var.

Thank you Michael, I understand it much better now. Could you please add
this information into the FPC Language Reference document? I re-read
Chapter 11 in ref.pdf and there is no mention of what you said, and the
documentation doesn't cover what happens if a Class is passed as a
parameter. It only mentions simple types and arrays as parameters. Maybe
adding a extra section in that chapter explaining when to use what?

This brings me to another question. What is supposed to happen if you pass
a Class instance as a const parameter? Does that even make sense? If not,
why does the compiler allow that? Again, the documentation doesn't cover
this scenario. Same question applies to passing a record structure.

procedure ProcessPerson(const APerson: TPerson);
  ...  // Am I allowed to change APerson.Name property?
  ...  // Am I allowed to assign a new instance to APerson?

  lPerson := TPerson.Create;
  lPerson.Name := 'Graeme Geldenhuys';


* I see I can't assign a new instance to APerson - this makes sense.
* I can assign new values to APerson.Name - am I supposed to be
  allowed to do that?

  - Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal

More information about the fpc-devel mailing list