[fpc-pascal] FPC class syntax was extended to support delphi code

David Emerson dle3ab at angelbase.com
Wed Jan 13 19:13:23 CET 2010


Thank you for this message! This stuff sounds really cool. In 
particular, I have been itching for class constants.

A few questions come to mind:

a. 'var' sections -- I assume that 'var' is optional when declaring 
fields that occur first (i.e. directly after "private", "public", etc)

b. What does "strict private" mean, as opposed to private without 
strict? (My best guess is that it would be accessible only within the 
methods+properties of that class within the unit, as opposed to being 
available anywhere in the same unit where the class is declared...???)

c. What is the purpose of a class method? It would seem to me that 
methods should do the same thing whether they are class methods or not. 
Traditional variables change from instance to instance, but methods do 
not vary between instances, as far as I know-- right?

d. What happens with inheritance?

d.1. wrt class constants and class vars-- are there separate "instances" 
(for lack of a better word) of these, one instance for each descendant? 
Or is the class var/const only stored once for the ancestor that 
declares it, and all descendants share that?

d.2. wrt class methods, can they be virtual? (This strikes me as being 
closely related to d.1)

I guess an example is in order for d:

type
  t_parent = class
  private
    class var
      x : integer;
    const
      c = 5;
  end;

  t_child = class (t_parent)
  private
    const
      c = 7;  // can I do this?
  end;

If I change t_child.x will it change t_parent.x?

e. Is it available in {$mode objfpc}? (I hope I hope I hope)?

I'd love to test this stuff out, though I usually stick with release 
versions... perhaps this is what is needed for me to take the plunge! 
Either way, I'm looking forward to this being released. Great work.

Cheers,
David

On Wed 13 Jan 2010, Paul Ishenin wrote:
> Hello, FPC-Pascal users discussions
> 
> I want to notify you that fpc trunk has extensions for the class 
syntax.
> 
> Class can have now the next sections:
> 
> 1. 'var' sections to start regular fields declaration. 'var' can be 
used 
> after other sections and after methods
> 2. 'class var' sections to start static fields declaration. Fields 
> delcared in the 'class var' section are static fields
> 3. 'type' sections to declare types local to a class. It is allowed 
now 
> to declare nested classes too.
> 4. 'const' section to declare constants local to a class.
> 5. 'class property' - similar to regular property but works with 
static 
> fields and methods
> 
> Some examples:
> http://wiki.lazarus.freepascal.org/class_extensions_examples
> 
> Please test and report bugs found.
> 
> Best regards,
> Paul Ishenin.
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> 






More information about the fpc-pascal mailing list