ghkweon / dwscript

Automatically exported from code.google.com/p/dwscript
0 stars 0 forks source link

Forward Declarations? #307

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I figured out after trial and error that every type declared in a script must 
begin with "type". I would like to do something like this:

type
  TSomeClass = class;
  TOtherClass = class;

  TSomeClass = class
  private
    FOtherClass: TOtherClass;
  end;

  TOtherClass = class
  private
    FOwner: TSomeClass;
  public
    constructor Create(AOwner: TSomeClass);
  end;

I'd like to cross-reference between the objects, however the compiler seems to 
always want "type" in front of each and every class (and other types). Can I 
overcome this? Or is this just the way the script works?

It expects me to define my types like this:

type
  TMyRec = record
    Dummy: String;
  end;

type
  TMyEnum = (enOne, enTwo, enThree);

type
  TMyClass = class
  private
    FDummy: String;
  public
    constructor Create;
  end;

Original issue reported on code.google.com by djjd47...@gmail.com on 4 Nov 2012 at 12:52

GoogleCodeExporter commented 8 years ago
Yes, this is mentionned there

http://code.google.com/p/dwscript/wiki/SourceStructure

and is the case in script/mixed mode, as implementation & variable/type 
declaration can be mixed together, so it's a syntax requirement (otherwise some 
code becomes ambigous)

If you have a classic unit structure (with interface/implementation), then the 
same limitations as in classic Pascal/Delphi apply, and type declaration blocks 
are allowed.

Original comment by zar...@gmail.com on 5 Nov 2012 at 7:33

GoogleCodeExporter commented 8 years ago
The "Unit / Program" section of that article is missing...

Original comment by djjd47...@gmail.com on 6 Nov 2012 at 12:11

GoogleCodeExporter commented 8 years ago
Yeah, not written yet.

It's the same as classic Pascal/Delphi though, there are a few extensions (like 
being able to have multiple "uses" clauses or being able to declare variables 
in the initialization section), but you don't have to use them.

Original comment by zar...@gmail.com on 6 Nov 2012 at 8:37