[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
procedure SetType (var SomeObject; VMT: PObjectType); |
The procedure `SetType' explicitly assigns a value to the implicit VMT field of an object. This is normally done implicitly when a constructor is called.
You can use this to write a polymorphic I/O routine which reads an object from a file. In this case, you cannot reasonably use `New' to allocate the storage, but you `GetMem' it and initialize the object manually using `SetType' before calling the constructor explicitly.
The only values you should assign to an object via `SetType' are actual VMT pointers that were obtained via `TypeOf'. In particular, declaring a record like the one shown in the description of `PObjectType' and assigning a pointer to it to an object via `SetType' will usually not work because the virtual method pointers are missing.
Since `SetType' is a dangerous feature, it yields a warning unless `{$X+}' is given.
`SetType' is a GNU extension.
program SetTypeDemo; |
section 9.195 PObjectType, section 9.286 TypeOf, section 8.8 Object-Orientated Programming.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |