Text after "
We all know in a known form, when we call a producer of a class like this:
< Code> example: = TSomeClass.Create;
Delphi compilers actually do the following things:.
- Call the NewInstance method to allocate memory and start a memory layout
- Call the manufacturer method to perform the initialization of the class
- Call the AfterConstruction method
It's simple and easy to understand. But I'm pretty sure how the second and third phase In the compiler handle exception
It seems there is no obvious way to see an example in an example D2010 by using an RTTI Creator method. Therefore I had written a simple function in Delphi Spring Framework to reproduce the process of construction
class function TActivator.CreateInstance (instanceType: TRttiInstanceType; constructorMethod: TRttiMethod; constant argument: TValue Array of): tubabject; Var class type: teclus; Start TArgument.CheckNotNull (type example, 'instanceType'); TArgument.CheckNotNull (Constructor Method, 'Constructor Method'); Class Type: = Instance type.maxaclus type; Results: = classtype New Instance; Try Constructor Method.Invoke (Results, Logic); Except exception, if the result is TInterfacedObject starts, then starts (TInterfacedObjectHack (results). FRefCount); End; Result.Free; Increased; End; End; Try the result. After creation; Except the exception, start the result. free; Increased; End; End; End;
I think this is probably not 100% correct, so please show me the way. Thanks!
constructer and class passing arguments as an argument (an example As opposed) will build the class correctly. The process of creation involves
NewInstance
, AfterConstruction
etc. that you are doing manually here: It is not necessary.
It should be sufficient:
Result: = Constructor method. Invoke (example type metaclass type, logic);
One of the odds of Delphi is how it allows consultants to call examples and classes. This feature is used as "Placement New" (C ++ Terminology) for form creation, so that the Global Form Variable (such as Form1
by default for the first form) is assigned at the same time Thus, the code is applied to the OnCreate
constructor, thus your code does not increase the exception but passing the class rather than the example as self
argument is more common.
Comments
Post a Comment