On 19 Apr 2002 at 9:10, Adam Naumowicz wrote:
[...]
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.
It is perfectly possible. I use it all the time.
The FillChar example maybe doesn't make much sense,
No, it doesn't ;)
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.
The elements of the array know their type and you can call the virtual method - as long as you allocate memory for the object with "New".
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.
It still works with GPC. The problem here is using "Getmem" instead of "New". This might be an unnecessary restriction in GPC (i.e., having to use "New") - but it may well be documented (I don't remember - but I know that I don't use "Getmem" for object pointers, and perhaps there was a reason).
Remember also that "New" is extended for objects under BP (and compatibles). So, a different and perhaps "better" way of doing the above may be something like (untested);
type pt = ^t; t=object .... ... type ar=array[0..10000] of pt; var p : ar;
begin for n := 0 to max do New (p[n], Init); end;
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.bigfoot.com/~African_Chief email: African_Chief@bigfoot.com