Am 11.01.2011 14:49, schrieb Razvan Adrian Bogdan:
On Mon, Jan 10, 2011 at 9:48 PM, Sven Barth <[email protected]
<mailto:[email protected]>> wrote:
In Pascal all type declarations appear in blocks that are named
"type". This is the case in global unit scope, in local method scope
and in class scope as well. So I don't think one should brake with
the way Pascal works just to create code that looks more beautiful.
And this is also Delphi compatible.
Yes i agree this is indeed how it works, what i meant was: Why not do it
the same way the Records work.
You can nest records and you don't use the type keyword for the nested
records, the parser/compiler knows how to recognize a "subrecord". By
making the type keyword optional you don't break anything and the
compiler isn't confused and it is the way records work already and this
behavior is much older and cleaner than the way it's implemented now.
type
TMyStruct = record
NestedStruct = record
SimpleMember: string;
end;
end;
Just replace record with class and no type keyword is required, it's
simple, clean and not ambiguous in any way. For declaring other types
inside the class is would probably require the type keyword just not for
nested classes/records.
No, that doesn't work that way in records. You can only have a record
field that has a inline defined type, but you can't access that type by
its name anywhere (it's something like an anonymous type). You can do
that in classes as well by the way (but only with records).
E.g.
type
TMyStruct = record
SubStructField: record // <= note the colon
SimpleMember: String;
end;
end;
TMyClass = class
SubStructField: record
Foo: Integer;
end;
end;
Regards,
Sven
--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus