Sign in Join

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

Mailing lists / fpc-pascal / 2007-05

Constant members within class

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Christos Chryssochoidis

Hi,

Is there a way to define const members for a class, as for example in

TClass = class
    public
       const i : integer;    // and hopping to be able to set it within
the constructor…
end;

?

Thank you in advance

Marco van de Voort
to Christos Chryssochoidis
Show quoted text 6 lines
Is there a way to define const members for a class, as for example in TClass = class public const i : integer; // and hopping to be able to set it within the constructor?

It's already there

   taclass = class
		fi:integer;
		public
		 property i write fi;
                end;
Christos Chryssochoidis
to Marco van de Voort

Thanks a lot for the prompt response. I 'm a total novice in Object Pascal. I will have a look to the classes' properties…

Marco van de Voort wrote 22 lines
> Is there a way to define const members for a class, as for example in > > TClass = class > public > const i : integer; // and hopping to be able to set it within > the constructor? > It's already there taclass = class fi:integer; public property i write fi; end; _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Marco van de Voort
to Christos Chryssochoidis
Thanks a lot for the prompt response. I 'm a total novice in Object Pascal. I will have a look to the classes' properties?

Yes. Properties can be read-only. Moreover, it is Delphi and FPC compat in all recent, and even not so recent versions.

Christos Chryssochoidis
to Matt Emson
Matt Emson wrote 19 lines
> taclass = class > fi:integer; > public > property i write fi; > end; Not to pick on little details, but shouldn't that be: property i: interger read fi; as the OP wanted a read only member? What you gave them was write only. Maybe I misunderstood their request, if so sorry. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Yes, I think so too, it should be

property i: interger read fi;

and furthermore fi be private (I think that the default visibility is public...).
I 'm not sure, please correct me if I 'm mistaken.