Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-01

passing a class parameter as a const

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi

Does passing a class parameter as a const make any difference?

eg:

  Add(const AObject: TtiObject);
      vs
  Add(AObject: TtiObject);
From what I can see it shouldn't. Most Delphi code and Free Pascal

FCL code doesn't use 'const' for class parameters.

Graeme Geldenhuys There's no place like S34° 03.168' E018° 49.342'

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 15 lines
Hi Does passing a class parameter as a const make any difference? eg: Add(const AObject: TtiObject); vs Add(AObject: TtiObject); >From what I can see it shouldn't. Most Delphi code and Free Pascal FCL code doesn't use 'const' for class parameters.

It makes no difference, except that you cannot do

AObject:=SomeOtherObject;

in the first case.

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote 5 lines
It makes no difference, except that you cannot do AObject:=SomeOtherObject; in the first case.

Does Free Pascal work the same as Delphi 7 and earlier when you pass interfaces around (and perhaps other auto reference counted types - strings, dynamic arrays?). Without a classifier (const, var, out), an interface argument reference count gets inc'd on the way in to the function and dec'd on way out, resulting in calls to _AddRef and _Release respectively on the interfaced argument.

Graeme Geldenhuys There's no place like S34° 03.168' E018° 49.342'

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 13 lines
On 1/12/07, Michael Van Canneyt wrote: > It makes no difference, except that you cannot do > > AObject:=SomeOtherObject; > > in the first case. Does Free Pascal work the same as Delphi 7 and earlier when you pass interfaces around (and perhaps other auto reference counted types - strings, dynamic arrays?). Without a classifier (const, var, out), an interface argument reference count gets inc'd on the way in to the function and dec'd on way out, resulting in calls to _AddRef and _Release respectively on the interfaced argument.

As far as I know: yes.

But Florian Klaempfl should confirm this.

Michael.

Reply by email

Florian Klaempfl
to Michael Van Canneyt
Show quoted text 19 lines
On Tue, 16 Jan 2007, Graeme Geldenhuys wrote: > On 1/12/07, Michael Van Canneyt wrote: >> It makes no difference, except that you cannot do >> >> AObject:=SomeOtherObject; >> >> in the first case. > Does Free Pascal work the same as Delphi 7 and earlier when you pass > interfaces around (and perhaps other auto reference counted types - > strings, dynamic arrays?). Without a classifier (const, var, out), an > interface argument reference count gets inc'd on the way in to the > function and dec'd on way out, resulting in calls to _AddRef and > _Release respectively on the interfaced argument. As far as I know: yes. But Florian Klaempfl should confirm this.

It does of course.

Reply by email