On 19 Apr 2002 at 22:17, Frank Heckenbach wrote: [...]
To sum up, when a constructor is called, the VMT pointer has already been set under normal conditions. It might not hurt to set it again, but it would not really solve any problem, either, since in `GetMem' situations, object fields of string, schema, etc. type would still remain uninitialized. Currently, in such a situation, one can do it all manually (with `SetType' for objects, and some more or less dirty tricks to set the discriminants). An initialize-any-variable (name?) builtin procedure as I suggested would seem like a better solution to this problem. (Though I'm still not sure why this problem arises at all -- I suppose to be bug-compatible to BP's lack of support for variables of dynamic size!?)
Perhaps. But it is likely to arise more for people who are new to GPC, or who are porting existing code from BP/Delphi/Virtual Pascal. An "initialize-any-variable" procedure would be a good idea. In Delphi, a similar procedure exists, called "Initialize". This is the Dephi documentation on it:
"procedure Initialize(var V [ ; Count: Integer ] );
Description
Initialize should be used only in situations where a variable is dynamically allocated by other means than the New standard procedure.
For global variables, local variables, objects, and dynamic variables allocated using New, the compiler generates code that initializes all long strings and variants contained by a variable upon creation of the variable. A call to Initialize is required to initialize a variable before it can be used if:
The dynamic variable is created by other means than the New standard function (for example using GetMem or ReallocMem). The variable contains long strings, variants, or interfaces. The memory allocated for the variable is not initialized to zeros.
Initialize simply zeros out the memory occupied by long strings, variants, and interfaces, causing long strings to be empty and variants and interfaces to be Unassigned.
In cases where several variables are allocated in a contiguous memory block, the additional Count parameter can be specified to initialize all variables in one operation.
If the variable specified in a call to Initialize contains no long strings, variants, or interfaces, the compiler eliminates the call and generates no code for it."
Best regards, The Chief -------- Prof. Abimbola A. Olowofoyeku (The African Chief) web: http://www.bigfoot.com/~African_Chief email: African_Chief@bigfoot.com