[fpc-pascal] Syntax changes suggestions

Sven Barth pascaldragon at googlemail.com
Wed Jul 18 23:05:38 CEST 2018


Ryan Joseph <ryan at thealchemistguild.com> schrieb am Mi., 18. Juli 2018,
21:41:

>
>
> > On Jul 18, 2018, at 12:47 PM, Sven Barth via fpc-pascal <
> fpc-pascal at lists.freepascal.org> wrote:
> >
> > A point against stack based classes is that Object Pascal's object model
> is highly geared towards polymorphism (with things like virtual class
> methods and constructors that C++ does not support). You can't make use of
> this however if the class is instantiated on the stack.
>
> Isn't that what Object does though? Something strange happened when FPC
> implemented classes because they didn’t unify the model between stack and
> heap. That was the obvious thing to do in my mind.
>

You have to keep in mind the history here. The "object" type is from Turbo
Pascal times and back then it already showed its weaknesses. Then along
came Delphi and Borland decided to introduce a brand new object model based
on the "class" type which tackled the weak points of the "object" type and
introduced some more polymorphism for the type.
You can't utilize polymorphism with "object" instances in the stack either.


> I remember back when I was using Objects and doing like C++ where I used
> new to allocate on the heap then dereference using ^. to access members.
> When classes came around I thought, this is nice, no more new and ^.
> everywhere and easier to use. Fast forward to today and I want the option
> to go stack based back but the models have diverged so much it’s not
> possible anymore.
>
> Just now I wanted to use TFPGList and I wanted it on the stack because I
> didn’t want it to survive outside the function I was in. What do I do now?
>

I really wonder why you keep thinking that you need them on the stack. I'm
developing in Object Pascal (and this the "class" based model) for around
16 years or so and I never felt the need to put a class on the stack. I'm
saying that while I also work with C++ at work for nearly 5 years and *do*
use stack based structs and classes there.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180718/22f7575a/attachment.html>


More information about the fpc-pascal mailing list