Hello,
On Thu, 18 Apr 2002, Prof Abimbola Olowofoyeku wrote:
On 18 Apr 2002 at 19:01, Adam Naumowicz wrote:
[...]
program tester;
type t=object procedure proc;virtual; constructor Init; end;
procedure t.proc; begin writeln('Proc'); end;
constructor t.init; begin writeln('Init'); proc; end;
var p:array[0..10] of t;
begin fillchar(p,sizeof(p),0); p[1].Init; end.
I assume, there was some optimalization added to call the virtual methods really the virtual way. Or maybe the constructor creates the VMTP at the end of the constructor process. Is there a chance to get the previous behavior back ?
Are you sure that you are not overwriting the VMT with the "fillchar" call? IIRC, it is not a good idea at all to use fillchar on records and objects. It might be better to initialise the fields manually.
I'm sure I do overwrite it! But still it should be possible (other Pascal compilers I know and some previous versions of GPC allow for it) to use virtual methods within a constructor. The FillChar example maybe doesn't make much sense, but let's say I have something like that:
type t=object constructor Init; procedure Proc;virtual; end;
constructor t.Init; begin Proc; end;
procedure t.Proc; begin end;
ar=array[0..10000] of t; pa=^ar; var p:pa;
begin GetMem(p,n*SizeOf(t)); p^[1].Init; end.
Then the elements of the array should know their type, that is, even after GetMem there should be a way to call the virtual method. Again you may say that this example is not a good programming technique - I agree, but still I would like to have the choice to use it or not. It used to work with static objects with GPC and Borland's compilers as well as FPC allow for it.
Regards, Adam Naumowicz
-------------------------------------- WWW: http://math.uwb.edu.pl/~adamn/ --------------------------------------