partial class in D2007?

41 views
Skip to first unread message

Troy Wolbrink

unread,
Sep 16, 2007, 4:23:59 PM9/16/07
to
Does Delphi for .NET support partial classes in RAD Studio 2007?

--Troy


Nick Hodges (CodeGear)

unread,
Sep 16, 2007, 5:44:15 PM9/16/07
to
Troy Wolbrink wrote:

> Does Delphi for .NET support partial classes in RAD Studio 2007?

No.

--
Nick Hodges
Delphi Product Manager - CodeGear
http://blogs.codegear.com/nickhodges

Bill Bonde

unread,
Sep 16, 2007, 9:04:43 PM9/16/07
to

"Troy Wolbrink" <troy.w...@ccci.org> wrote in message news:46ed90cf$1...@newsgroups.borland.com...

> Does Delphi for .NET support partial classes in RAD Studio 2007?

Depending on what you need the partial classes for, class helpers maybe
what will work for you. However, as far as I know, usage of class helpers
was never officially encouraged.


m. Th.

unread,
Sep 17, 2007, 1:33:08 AM9/17/07
to
Nick Hodges (CodeGear) wrote:
> Troy Wolbrink wrote:
>
>> Does Delphi for .NET support partial classes in RAD Studio 2007?
>
> No.
>

Do you plan to? (at least on 'native' side)

(Imho, it will be a neat feature for code generators like MDD/OPF/ORM etc. The
modeling tool will generate for you the 'standard' one and you (or another developer)
will do the 'customization' ie. adapt it to different needs).

But, imho, perhaps mixins it's a better approach. Do you consider them?

Also, do you plan to 'fix'/enhance the class helpers? (see
http://excastle.com/blog/archive/2007/08/29/48170.aspx for more 'info')

--

m. th.

Robin

unread,
Sep 17, 2007, 1:47:00 AM9/17/07
to
Troy Wolbrink wrote:
> Does Delphi for .NET support partial classes in RAD Studio 2007?

Hi Troy,

If you don't mind me asking, why do you want these?

I never understood what good comes from partial classes.

--
Robin.

Australian Bridal Accessories := http://www.bridalbuzz.com.au

Nick Hodges (CodeGear)

unread,
Sep 17, 2007, 1:52:16 AM9/17/07
to
m. Th. wrote:

> Do you plan to? (at least on 'native' side)

I'm not convinced we need to do anything. I always say that partial
classes is the worlds first language feature to result from a crappy
component persistence model. ;-)


> But, imho, perhaps mixins it's a better approach. Do you consider
> them?

Yes -- I think they are a much better approach.



> Also, do you plan to 'fix'/enhance the class helpers? (see
> http://excastle.com/blog/archive/2007/08/29/48170.aspx for more
> 'info')

Class helpers were never really meant to be used in that way. In their
original design, they were generally meant to be used for framework
adaption -- i.e. rarely, and mostly by us.

However, I realize that once you put something, uhm "interesting" into
the language like that, then folks are going to, well, do "interesting"
things with them. ;-)

Bill Bonde

unread,
Sep 17, 2007, 2:16:48 AM9/17/07
to

"Robin" <Robin@.com> wrote in message news:46ee14a8$1...@newsgroups.borland.com...

> I never understood what good comes from partial classes.

Further separation of code. For example, separation of machine
generated code from code manually entered by a programmer.


Dmitry Arefiev [da-soft.com]

unread,
Sep 17, 2007, 2:27:19 AM9/17/07
to
> However, I realize that once you put something, uhm "interesting" into
> the language like that, then folks are going to, well, do
> "interesting" things with them. ;-)

Following code really helped us a lot. And many thanks for
that to class helpers !

TStreamHelperGS = class helper for TStream
public
procedure WriteVar(const AVar: Byte); overload;
procedure WriteByte(const AVar: Byte); // allows to specify the exact
type
procedure WriteVar(const AVar: AnsiString); overload;
procedure WriteAnsiString(const AVar: AnsiString); // allows to specify
the exact type
procedure WriteVar(const AVar: Integer); overload;
procedure WriteInteger(const AVar: Integer); // allows to specify the
exact type
.........
end;

--
Dmitry Arefiev - www.da-soft.com
AnyDAC - Oracle, MySQL, MSSQL, MSAccess, IBM DB2, Sybase
ASA, DbExpress, ODBC freeware data access engine
ThinDAC - multitier data access engine

David Clegg

unread,
Sep 17, 2007, 2:39:52 AM9/17/07
to
Robin wrote:

> I never understood what good comes from partial classes.

I take it you've never done WinForms development then ;-)

--
Cheers,
David Clegg
dcl...@gmail.com
http://cc.borland.com/Author.aspx?ID=72299

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"Are you sure this is the Sci-Fi Convention? It's full of nerds!" -
Homer Simpson

Robert Giesecke

unread,
Sep 17, 2007, 4:04:13 AM9/17/07
to
David Clegg wrote:
> Robin wrote:
>
>> I never understood what good comes from partial classes.
>
> I take it you've never done WinForms development then ;-)
>

In .Net you also get these kinds for almost all code generators. Be it wsdl.exe, xsd.exe or what-not
(I can't of one code gen that doesn't use partial classes?).
They were *not* a direct result from the way SWF persists settings in code, this was only yet another
factor.
It is very neat to be able to add properties/methods to wsdl-imported classes w/o redoing it every
time you run wsdl.exe.

m. Th.

unread,
Sep 17, 2007, 3:56:54 AM9/17/07
to
Nick Hodges (CodeGear) wrote:
> m. Th. wrote:
>
>> Do you plan to? (at least on 'native' side)
>
> I'm not convinced we need to do anything. I always say that partial
> classes is the worlds first language feature to result from a crappy
> component persistence model. ;-)
>

Neither do I. But I just try the BTN (Better Than Nothing) approach but if you are
willing to implement mixins :-) then...

>
>> But, imho, perhaps mixins it's a better approach. Do you consider
>> them?
>
> Yes -- I think they are a much better approach.
>

...go ahead! go ahead!
Also, perhaps you have time to look at multiple inheritance (<Yuck!>), but in the way
in which Eiffel implemented it (<Whoah!> :-) ) and take from there what' usefull

For this, perhaps is nice to have a look at

http://en.wikipedia.org/wiki/Object-Oriented_Software_Construction

and/or

http://archive.eiffel.com/doc/oosc/

and especially

http://archive.eiffel.com/doc/online/eiffel50/intro/language/tutorial-10.html#pgfId-515052


also, a nice discussion on language features are to be found at

http://www.jvoegele.com/software/langcomp.html

...among others there are very nice things about "Lexical Closures" (hint, hint, hint
- we have also a QC for it - #49996 ;-) ), Feature Renaming, Design by Contract...
(also here some QC entries) - very nice things, imho.

>> Also, do you plan to 'fix'/enhance the class helpers? (see
>> http://excastle.com/blog/archive/2007/08/29/48170.aspx for more
>> 'info')
>
> Class helpers were never really meant to be used in that way. In their
> original design, they were generally meant to be used for framework
> adaption -- i.e. rarely, and mostly by us.
>
> However, I realize that once you put something, uhm "interesting" into
> the language like that, then folks are going to, well, do "interesting"
> things with them. ;-)
>

...hehehe... My dear son... :-) Point taken. But too late. Imho, nothing is so liquid
as a community. A community will use _everything_ which can be used in _unimaginable_
ways. (Un)fortunately, I humbly think that both have a small experience on this. So,
if you (I mean here CG) think that it's worth to do something, do it good. You have,
in fact, no choice. Steve McConnell said that if you're glad that you did a 'tricky'
code, a quick fix, a you're tempted to made a wink and a smile, then go back to your
code and refactor it.

I was really impressed by Chris Bensen's
http://chrisbensen.blogspot.com/2007/08/com-is-hard.html

...not because of the (rather known) technical details from there, but because,
behind the scenes, he emphasizes the need of beauty. And imho, this is crucial. No
one will like a thing (even a code) if isn't 'beautiful' - especially one from Delphi
community which have the experience of a beautiful environment. (For ex. many times I
found TDataModule so simple and beautiful) So, IOW, to speak in Chris's language,
don't take something out until you can take a photo on it. And if you're pressed to
do it, at least the interface to be pictural, in order to allow you to refactor the
core later. Imho, (especially for Delphi) remaining at BTN approach simply doesn't fit.

just my 2c,

--

m. th.

HeartWare

unread,
Sep 17, 2007, 4:36:31 AM9/17/07
to
On Sep 17, 7:52 am, "Nick Hodges (CodeGear)"
<nick.hod...@codegear.com> wrote:

> However, I realize that once you put something, uhm "interesting" into
> the language like that, then folks are going to, well, do "interesting"
> things with them. ;-)

Don't you *dare* remove support for them :-).

I use it a lot. I think's it's the most exciting addition to the
Object Pascal language in a long, long time...

Take f.ex. this one (yes, you can make RECORD HELPERs as well!):

TRectHelper = RECORD HELPER FOR TRect
PRIVATE
FUNCTION GetWidth : CpuInt;
PROCEDURE SetWidth(NewWidth : CpuInt);
FUNCTION GetHeight : CpuInt;
PROCEDURE SetHeight(NewHeight : CpuInt);
PUBLIC
PROPERTY Width : CpuInt Read GetWidth
Write SetWidth;
PROPERTY Height : CpuInt Read GetHeight
Write SetHeight;
END;

Now I can use both Left/Right/Top/Bottom *and* Width/Height.

I use it extensively to implement features that I miss in the VCL like
the above. I have also - like Dmitry - extended the TStream class to
be able to easily read and write standard types as well as more
complex types. It's so much cleaner to write

StreamVar.Write('This is a string');

than

Write(StreamVar,'This is a string');

Perhaps you should take advantage of this and allow people to post
their custom extensions to the VCL classes and then implement the best
of them in new versions of the VCL.

Rudy Velthuis [TeamB]

unread,
Sep 17, 2007, 7:42:37 AM9/17/07
to
Troy Wolbrink wrote:

> Does Delphi for .NET support partial classes in RAD Studio 2007?

No. Not that I miss them, actually.

--
Rudy Velthuis [TeamB]

"I am ready to meet my Maker. Whether my Maker is prepared for
the great ordeal of meeting me is another matter."
-- Sir Winston Churchill (1874-1965)

Rudy Velthuis [TeamB]

unread,
Sep 17, 2007, 7:45:44 AM9/17/07
to
Bill Bonde wrote:

It was even officially discouraged, AFAIK. <g>

But they exist, even in Win32, where they are not really needed (they
were designed to make .NET classes and Delphi classes compatible), so
why not use them?

--
Rudy Velthuis [TeamB]

"We don't make mistakes, we just have happy little accidents."
-- Bob Ross, "The Joy of Painting"

Rudy Velthuis [TeamB]

unread,
Sep 17, 2007, 7:43:34 AM9/17/07
to
m. Th. wrote:

> (Imho, it will be a neat feature for code generators like MDD/OPF/ORM
> etc. The modeling tool will generate for you the 'standard' one and
> you (or another developer) will do the 'customization' ie. adapt it
> to different needs).
>
> But, imho, perhaps mixins it's a better approach. Do you consider
> them?

What about class helpers? Not entirely the same, but often good enough.

--
Rudy Velthuis [TeamB]

"I'm fed up to the ears with old men dreaming up wars for
young men to die in." -- George McGovern

Dean Hill

unread,
Sep 17, 2007, 10:06:54 AM9/17/07
to
Nick Hodges (CodeGear) wrote:

> Troy Wolbrink wrote:
>
> > Does Delphi for .NET support partial classes in RAD Studio 2007?
>
> No.

Thank you :)

--
Dean

Troy Wolbrink

unread,
Sep 17, 2007, 10:33:51 AM9/17/07
to
> If you don't mind me asking, why do you want these?
> I never understood what good comes from partial classes.

I'm not necessarily a huge fan of partial classes. But I recently upgraded
a Delphi.NET application to RAD Studio 2007, and I updated the "Web
References". My web service passes back an array of a
"FinancialTransaction" type. In the generated proxy code Delphi generated
this:

FinancialTransaction = class {fragment}
...
Amount: Decimal
TrxDate: DateTime
...

When I saw {fragment} I started thinking, wouldn't it be great if I could
add methods to "FinancialTransaction" that don't get wiped out everytime I
regenerate the proxy code. Then I realized that partial classes are used in
.NET 2.0 for other auto-generated code such as typed datasets, etc.
(including WinForms designer support which is, of course, irrelevant to
D2007).

Also, I saw an article on Dr. Bob's website that talked about this upcoming
feature in Highlander. But I couldn't find it documented and I couldn't
compile Bob's code. That's the long story of why I asked about partial
classes in Delphi! :)

--Troy


Troy Wolbrink

unread,
Sep 17, 2007, 10:49:07 AM9/17/07
to

> I'm not convinced we need to do anything. I always say that partial
> classes is the worlds first language feature to result from a crappy
> component persistence model. ;-)

As a Delphi developer, I'm pretty happy with component persistence in a
resource (ala DFM) as opposed to auto-generated code. But I wouldn't reject
partial classes just because the WinForms 2.0 designer uses them.

--Troy


Nick Hodges (CodeGear)

unread,
Sep 17, 2007, 11:00:40 AM9/17/07
to
Troy Wolbrink wrote:

> When I saw {fragment} I started thinking, wouldn't it be great if I
> could add methods to "FinancialTransaction" that don't get wiped out
> everytime I regenerate the proxy code. Then I realized that partial
> classes are used in .NET 2.0 for other auto-generated code such as
> typed datasets, etc. (including WinForms designer support which is,
> of course, irrelevant to D2007).

The thing is you don't /need/ partial classes for this -- a mixin class
will work just as well, and it won't leave chunks of classes all over
the place.

Robin

unread,
Sep 17, 2007, 7:06:08 PM9/17/07
to
David Clegg wrote:
> I take it you've never done WinForms development then ;-)

Well, very little. I used it a few times in BDS to make quick-n-dirty
database apps and some .net remoting, as well as some small web service
consumers in VS2005 out of desperation when Delphi wouldn't play ball.

To the most part I kept to VCL and VCL.NET. In hind sight, that has
turned out for the best!

Robin

unread,
Sep 17, 2007, 7:02:20 PM9/17/07
to
Thanks Troy!

David Clegg

unread,
Sep 17, 2007, 7:12:47 PM9/17/07
to
Robin wrote:

> Well, very little.

If you did, you'd understand a little why partial classes are a well
received feature by .NET developers. WinForms places all control
creation and initialisation code inline, which meant that prior to
partial class support in C#, all this code was mixed in with the
developers code. This also explains Nicks comment about partial classes
being the worlds first language feature to result from a crappy
component persistence model.

While he does have a point WRT WinForms, I think partial classes do
have their place, especially if used by other frameworks which may
auto-generate code. In addition to the examples Robert listed, I think
ECO could make great use of partial classes, to greatly simplify the
maintenance of any user code in the ECO generated classes.

--
Cheers,
David Clegg
dcl...@gmail.com

http://cc.codegear.com/Author/72299

QualityCentral. The best way to bug CodeGear about bugs.
http://qc.codegear.com

m. Th.

unread,
Sep 18, 2007, 2:58:20 AM9/18/07
to
Nick Hodges (CodeGear) wrote:

>
> The thing is you don't /need/ partial classes for this -- a mixin class
> will work just as well, and it won't leave chunks of classes all over
> the place.
>

Yes, and more. Imho, because you already have on .NET (and you will have on Win32) a
parametrized type (ie. generics) engine, which of course, works for classes, istm
that it should be "doable" to implement a parametrized/generic mixin - thing which
will be something stunning. (or very "interesting", to cite you).

Doing the same thing, with class fragments it's a little bit 'fuzzy', imho.

--

m. th.

m. Th.

unread,
Sep 18, 2007, 3:18:40 AM9/18/07
to
Rudy Velthuis [TeamB] wrote:
> Bill Bonde wrote:
>
>> "Troy Wolbrink" <troy.w...@ccci.org> wrote in message
>> news:46ed90cf$1...@newsgroups.borland.com...
>>> Does Delphi for .NET support partial classes in RAD Studio 2007?
>> Depending on what you need the partial classes for, class helpers
>> maybe what will work for you. However, as far as I know, usage of
>> class helpers was never officially encouraged.
>
> It was even officially discouraged, AFAIK. <g>
>
> But they exist, even in Win32, where they are not really needed (they
> were designed to make .NET classes and Delphi classes compatible), so
> why not use them?
>

Because

1. It was officially discouraged <g>

...in fact, istm that the compiler guys seem to know hidden things that can bite us,
and that's why they tend to 'protect' us. Well, it would be a nice gesture from them
(Nick?, Allen?, Barry?) to inform us about the implementation details.

2. No virtual methods (see my first post for a link to one of Joe Withe's blog posts
for details) - but perhaps in Tiburon we'll have them. Anyway, now the class helpers
are used also by developers, so they cannot remove the feature.

3. They doesn't extend the RTTI of helped class. Which isn't quite the thing which
one could expect

...anyway, I must confess that I like the 'class helper' _term_, is much more
descriptive. A 'class helper' syntax with a full fledged mixin engine underneath
would be very nice.

Rudy Velthuis [TeamB]

unread,
Sep 18, 2007, 7:23:05 AM9/18/07
to
m. Th. wrote:

> Rudy Velthuis [TeamB] wrote:
> > Bill Bonde wrote:
> >
> >>"Troy Wolbrink" <troy.w...@ccci.org> wrote in message
> > > news:46ed90cf$1...@newsgroups.borland.com...
> > > > Does Delphi for .NET support partial classes in RAD Studio 2007?
> > > Depending on what you need the partial classes for, class helpers
> > > maybe what will work for you. However, as far as I know, usage of
> > > class helpers was never officially encouraged.
> >
> > It was even officially discouraged, AFAIK. <g>
> >
> > But they exist, even in Win32, where they are not really needed
> > (they were designed to make .NET classes and Delphi classes
> > compatible), so why not use them?
> >
>
> Because
>
> 1. It was officially discouraged <g>
>
> ...in fact, istm that the compiler guys seem to know hidden things
> that can bite us, and that's why they tend to 'protect' us. Well, it
> would be a nice gesture from them (Nick?, Allen?, Barry?) to inform
> us about the implementation details.
>
> 2. No virtual methods (see my first post for a link to one of Joe
> Withe's blog posts for details) - but perhaps in Tiburon we'll have
> them.

I doubt it, since you can't simply change the VMT of a class which is
not aware of the helpers. That is why you can't have anything that
would require a change to the layout of the helped class or instances
of it.

> Anyway, now the class helpers are used also by developers, so
> they cannot remove the feature.

I'm sure they don't want to remove them.


>
> 3. They doesn't extend the RTTI of helped class. Which isn't quite
> the thing which one could expect

It is what I'd expect. Like I said: the helped class does not know
anything about the helper. The helper can't do anything that would
require changing the layout of the VMT (and other class-specific
fields, including RTTI, see documentation) or the instances of the
helped class.


--
Rudy Velthuis [TeamB]

"When I told the people of Northern Ireland that I was an
atheist, a woman in the audience stood up and said, 'Yes, but
is it the God of the Catholics or the God of the Protestants
in whom you don't believe?" -- Quentin Crisp.

Marc Rohloff [TeamB]

unread,
Sep 18, 2007, 8:48:02 AM9/18/07
to
On Tue, 18 Sep 2007 10:18:40 +0300, m. Th. wrote:

> ...anyway, I must confess that I like the 'class helper' _term_, is much more
> descriptive. A 'class helper' syntax with a full fledged mixin engine underneath
> would be very nice.

Interestingly enough the latest C# spec contains something very
similar so you might see a lot more support in the future, although I
don't believe the spec includes anything like Mixins.

--
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com

Rudy Velthuis [TeamB]

unread,
Sep 18, 2007, 1:09:27 PM9/18/07
to
Marc Rohloff [TeamB] wrote:

> On Tue, 18 Sep 2007 10:18:40 +0300, m. Th. wrote:
>

> > ...anyway, I must confess that I like the 'class helper' term, is


> > much more descriptive. A 'class helper' syntax with a full fledged
> > mixin engine underneath would be very nice.
>
> Interestingly enough the latest C# spec contains something very
> similar so you might see a lot more support in the future, although I
> don't believe the spec includes anything like Mixins.

http://www.codeproject.com/useritems/C__3_Mixin.asp

--
Rudy Velthuis [TeamB]

"UNIX is simple. It just takes a genius to understand its
simplicity."-- Dennis Ritchie

m. Th.

unread,
Sep 19, 2007, 2:45:06 AM9/19/07
to
Rudy Velthuis [TeamB] wrote:
>>
>> 2. No virtual methods (see my first post for a link to one of Joe
>> Withe's blog posts for details) - but perhaps in Tiburon we'll have
>> them.
>
> I doubt it, since you can't simply change the VMT of a class which is
> not aware of the helpers. That is why you can't have anything that
> would require a change to the layout of the helped class or instances
> of it.
>

Yes, is not trivial, but if they want to do it, there are ways (like a cluster chain
organization for VMT, lookup table etc.) but these are presumptions because I don't
know the compiler from inside). Perhaps an approach to build from scratch a mixin
engine supporting all these would be better.

>> Anyway, now the class helpers are used also by developers, so
>> they cannot remove the feature.
>
> I'm sure they don't want to remove them.
>> 3. They doesn't extend the RTTI of helped class. Which isn't quite
>> the thing which one could expect
>
> It is what I'd expect.

Yes, /you/ expect. But I meant the average developer(s). Or worse, one who doesn't
know that the published property '<x>' (from a foreign code at which he doesn't have
access/doesn't understand etc.) comes, in fact, from a helper and tries to use RTTI
to locate it.

> Like I said: the helped class does not know
> anything about the helper.
> The helper can't do anything that would
> require changing the layout of the VMT (and other class-specific
> fields, including RTTI, see documentation) or the instances of the
> helped class.
>

Yes, too bad. But (at least theoretically speaking) this can be changed - but of
course this will break the binary compatibility between the releases (which anyway
will happen). Imho, it will worth the effort.

Just my 2c,

--

m. th.

Rudy Velthuis [TeamB]

unread,
Sep 19, 2007, 1:27:04 PM9/19/07
to
m. Th. wrote:

> Rudy Velthuis [TeamB] wrote:
> > >
> > > 2. No virtual methods (see my first post for a link to one of Joe
> > > Withe's blog posts for details) - but perhaps in Tiburon we'll
> > > have them.
> >
> > I doubt it, since you can't simply change the VMT of a class which
> > is not aware of the helpers. That is why you can't have anything
> > that would require a change to the layout of the helped class or
> > instances of it.
> >
>
> Yes, is not trivial, but if they want to do it, there are ways (like
> a cluster chain organization for VMT, lookup table etc.) but these
> are presumptions because I don't know the compiler from inside).

It would require a fundamentally different and more complicated (and
slower) VMT.

> Yes, you expect. But I meant the average developer(s). Or worse, one


> who doesn't know that the published property '<x>' (from a foreign
> code at which he doesn't have access/doesn't understand etc.) comes,
> in fact, from a helper and tries to use RTTI to locate it.

That is another reason why class helpers should be used with extreme
care, and only if inheritance or generics won't do.

> Imho, it will worth the effort.

No, it won't, since anything else would make virtual calls slower.
--
Rudy Velthuis [TeamB]

"Not only is there no God, but you try getting a plumber at
weekends." -- Woody Allen.

danny heijl

unread,
Sep 28, 2007, 5:06:31 AM9/28/07
to
David Clegg schreef:

> While he does have a point WRT WinForms, I think partial classes do
> have their place, especially if used by other frameworks which may
> auto-generate code. In addition to the examples Robert listed, I think
> ECO could make great use of partial classes, to greatly simplify the
> maintenance of any user code in the ECO generated classes.

Exactly. We use partial classes extensively for generating C# NHibernate
classes with MYGeneration.

Danny
---

Reply all
Reply to author
Forward
0 new messages