So the tricky point appears to be that for TDog.Create to get invoked, the compiler has to detect that the main body of code uses TDog. But not just _any_ use of TDog; the code has to use some method (or maybe field) that is specific to TDog. So even though at 4:00 the main code includes Writeln(TDog.MyClassName), that is not enough to prompt the compiler to run TDog.Create during unit initialization. Whereas at 4:55 Alister adds TDog.ClassName; and evidently that prompts the compiler to include code to run TDog.Create. It's not clear to me why the compiler would do that, since surely TDog.ClassName is known statically at compile time. Maybe the rules are written down somewhere :-). (This is all setting aside the odd idea of having a descendant class override the value in the ancestor class's "MyClassName", but OK I guess, just for testing the call sequence. It would be interesting to know what clever thing Alister was originally hoping to accomplish.)
@codegearguru Жыл бұрын
Nice summary. I've been working with a project that has a DataSnap server with a TDataModule with about 300 TDSServerClass components on it. I was wanting some automated way of every ServerClass registering itself into a list. Then I could do away with about 2500 lines of code in the DataModule. I'll probably end up using RTTI, but I'll need a simple way to stop the TDSServerClasses being optimised out by the compiler. Basically, I want to change as little code as possible while eliminating lots of repeated code..
@thierrybo6304 Жыл бұрын
interesting, with Lazarus at 04:04 I get TDog TDog
@codegearguru Жыл бұрын
I haven't tried this, but it might be that the optimizer in Lazarus is not as aggressive as Delphi's.
@schobihh270311 ай бұрын
I am not sure if this programming pattern should be applied at all.
@epiblitik05 Жыл бұрын
Thanks for the video. insightful
@АлексейТашлинцев-м4ю Жыл бұрын
Спасибо, очень интересно!
@kennethmark6868 Жыл бұрын
Thanks for sharing, it is really confusion that the subclass class constructor not behaving as it should.
@codegearguru Жыл бұрын
It's behaving as it should, just may not be as expected.