Re: [fpc-pascal] Virtual object methods

2019-07-02 Thread Sven Barth via fpc-pascal
Am 02.07.2019 um 19:43 schrieb Michael Van Canneyt: On Tue, 2 Jul 2019, Ryan Joseph wrote: On Jul 2, 2019, at 10:32 AM, Michael Van Canneyt wrote: It overwrites the first. There is no such thing as '2 VMT tables'. That’s what I thought. How costly is this? Not sure what it’s doing un

Re: [fpc-pascal] Virtual object methods

2019-07-02 Thread Marco van de Voort
Op 2019-07-02 om 19:41 schreef Ryan Joseph: On Jul 2, 2019, at 10:32 AM, Michael Van Canneyt wrote: It overwrites the first. There is no such thing as '2 VMT tables'. That’s what I thought. How costly is this? Not sure what it’s doing under the hood but I’d like to know more. You'd expect

Re: [fpc-pascal] Virtual object methods

2019-07-02 Thread Michael Van Canneyt
On Tue, 2 Jul 2019, Ryan Joseph wrote: On Jul 2, 2019, at 10:32 AM, Michael Van Canneyt wrote: It overwrites the first. There is no such thing as '2 VMT tables'. That’s what I thought. How costly is this? Not sure what it’s doing under the hood but I’d like to know more. As far as I

Re: [fpc-pascal] Virtual object methods

2019-07-02 Thread Ryan Joseph
> On Jul 2, 2019, at 10:32 AM, Michael Van Canneyt > wrote: > > It overwrites the first. There is no such thing as '2 VMT tables'. That’s what I thought. How costly is this? Not sure what it’s doing under the hood but I’d like to know more. Regards, Ryan Joseph

Re: [fpc-pascal] Virtual object methods

2019-07-02 Thread Michael Van Canneyt
On Tue, 2 Jul 2019, Ryan Joseph wrote: Another question: what happens if you call the constructor twice? Does this create 2 VMT tables or overwrites the first? It overwrites the first. There is no such thing as '2 VMT tables'. Michael. ___ fpc-pa

Re: [fpc-pascal] Virtual object methods

2019-07-02 Thread Ryan Joseph
Another question: what happens if you call the constructor twice? Does this create 2 VMT tables or overwrites the first? type TA = object constructor Create; procedure DoThis; virtual; end; procedure TA.DoThis; begin writeln('TA.Do

Re: [fpc-pascal] Virtual object methods

2019-06-27 Thread Marco van de Voort
Op 27/06/2019 om 23:56 schreef Ryan Joseph: On Jun 27, 2019, at 5:53 PM, Ben Grasset wrote: If you specifically need inheritance (combined with virtual methods) you should probably just use classes, because doing it with objects will require heap allocation regardless. Heap allocate how so?

Re: [fpc-pascal] Virtual object methods

2019-06-27 Thread Ben Grasset
On Thu, Jun 27, 2019 at 5:57 PM Ryan Joseph wrote: > > Heap allocate how so? Calling the constructor seems to fix this and puts > the VMT table on the stack (I think anyways). Btw I’m doing this > specifically as testing for a possible “advancedobjects” mode switch and > the only reason to use ob

Re: [fpc-pascal] Virtual object methods

2019-06-27 Thread Ryan Joseph
> On Jun 27, 2019, at 5:53 PM, Ben Grasset wrote: > > If you specifically need inheritance (combined with virtual methods) you > should probably just use classes, because doing it with objects will require > heap allocation regardless. > Heap allocate how so? Calling the constructor seems

Re: [fpc-pascal] Virtual object methods

2019-06-27 Thread Ben Grasset
On Thu, Jun 27, 2019 at 4:17 PM Ryan Joseph wrote: > Why do I get a runtime error with this? > If you specifically need inheritance (combined with virtual methods) you should probably just use classes, because doing it with objects will require heap allocation regardless. ___

Re: [fpc-pascal] Virtual object methods

2019-06-27 Thread Ryan Joseph
> On Jun 27, 2019, at 4:20 PM, Jonas Maebe wrote: > > tt.pp(4,6) Warning: Virtual methods are used without a constructor in "TA" > tt.pp(14,6) Warning: Virtual methods are used without a constructor in "TB" That’s what the meant! Thanks Regards, Ryan Joseph __

Re: [fpc-pascal] Virtual object methods

2019-06-27 Thread Ryan Joseph
> On Jun 27, 2019, at 4:42 PM, Stefan V. Pantazi wrote: > > Read down the first page, the section "Objects - Dynamic Variables" - all > will become clear. > > By avoiding the virtual methods, you can keep your objects static, all stored > on stack, no need for constructors. I personally find

Re: [fpc-pascal] Virtual object methods

2019-06-27 Thread Stefan V. Pantazi
Read down the first page, the section "Objects - Dynamic Variables" - all will become clear. By avoiding the virtual methods, you can keep your objects static, all stored on stack, no need for constructors. I personally find very useful for my projects. Find fixed example below. Hope it help

Re: [fpc-pascal] Virtual object methods

2019-06-27 Thread Jonas Maebe
On 27/06/2019 22:17, Ryan Joseph wrote: > Why do I get a runtime error with this? tt.pp(4,6) Warning: Virtual methods are used without a constructor in "TA" tt.pp(14,6) Warning: Virtual methods are used without a constructor in "TB" You have to add a constructor and call it, otherwise the object

[fpc-pascal] Virtual object methods

2019-06-27 Thread Ryan Joseph
Why do I get a runtime error with this? == {$mode objfpc} program test; // http://wiki.freepascal.org/Programming_Using_Objects // http://wiki.freepascal.org/Programming_Using_Objects_Page_2 type TA = object procedure DoThis; virtual; end; procedure TA.DoTh