OOP_(re)
Wed, 28 May 1997 12:08:08 +0200 (MET DST)
According to Pierre Phaneuf:
>
> Could this compiler generated function be generated in the program? Then
> it would be optimized out if unused?
Then it would have to be in the GPI file. Much effort. I think the few
bytes we can save like that (Just those for the strings plus one pointer
in each VMT) are not worth it, but perhaps somebody else wants to try
himself on this problem? ;-)
> On the other hand, maybe we should do
> differently. In BP, there is a switch to have object symbols in for the
> object browser. It is separate from the debugging symbol switch. Maybe we
> could have a switch to have the object names and parent/childs
> informations included, which the ClassName() and others functions would
> consult. If the information isn't there, the ClassName() function would
> return "Unknown", an empty string or something similar... This information
> could be included in the VMT? This is more for you to decide... :-)
I don't like that solution either. It makes units compiled with different
options *really* incompatible with each other. (Programs using `ClassName'
will rely on the function returning the correct result.)
> Ok, can you give me an example of how to create an instance of a type
> specified by TypeOf? Would probably look like this:
That's almost perfect. :-)
> function TStream.Get: PObject;
> var
> ObjID: word;
> VMTLink: pointer;
> LoadPtr: pointer;
> P: PObject;
> begin
> { here some code to read the ObjID and fetch the
> corresponding VMTLink. }
> GetMem(P, word(VMTLink^));
WordPtr ( VMTLink )^; (* WordPtr = ^Word *)
> TypeOf(P):=VMTLink;
(* {$X+} is needed to compile this assignment. *)
> { call the LoadPtr constructor, how do I do this correctly? }
> { With @Self as the 'normal' parameter of course... }
(* I suggest to define a pointer to a procedure like the constructor *)
(* with an *explicit* `Self' parameter, to cast `LoadPtr' to it and *)
(* then call it. *)
> end;
> Hmm... One thing I think isn't very clean is the way TypeOf() works "in
> reverse"... It is *very* peculiar IMHO to set a value to a function! Maybe
> more something like SetTypeOf(P, VMTLink)? ;-)
That's why I did "hide" it behind (*$X+*). But maybe I should change this
application of `TypeOf' to make `TypeOf' an implicit *field* of an object
- which it is - instead of a function:
PtrToMyObj^.TypeOf:= TypeOf ( SomeObjectType );
> Attached to this message is
> the OBJECTS.PAS that goes with FPK-Pascal... Take a look at TObject and
> TStream.Get implementations...
They do assembler. Not very portable.
> So a constructor does *NOTHING* more than a normal procedure? Umm... What
> is the interest in a constructor then? :-)
*NOTHING*. ;-) In principle, it would be possible to call just
"MyObjPtr := New ( MyObjType );" without any constructor call. `New'
would still initialize the implicit VMT field, and one could call a
"constructor" procedure afterwards manually. I just implemented it
like I did (a) for compatibility's sake and (b) because I was not so
sure that this would really work and planned to change it to make
constructors initilalize the object instead of `New'. But in fact
this seems to work and to be more effective than BP's method.
Greetings,
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer
peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201]
maintainer GNU Pascal [970510] - http://home.pages.de/~gnu-pascal/ [970125]
Peter Gerwinski (peter@agnes.dida.physik.uni-essen.de)
HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada -
Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es