Class Constructors, Sometimes Not What You Expect - Delphi 215

preview_player
Показать описание


Alister Christie is a Delphi MVP (Most Valued Professional), Consultant, Developer, Trainer, Presenter, and Author. He has presented at ADUG (Australasian Delphi Users Group) Symposia and Code Rage Conferences for many years. Alister holds a degree in Mathematics and Computer Science from Victoria University, Wellington. He lives near Wellington, New Zealand.

On this YouTube Channel, Alister has created many hours of video tutorials to help you learn Delphi Programming in efficient and effective ways. Using his lessons, you will program faster and better, skills applicable for beginners through to experts wanting to expand their programming and coding proficiency.

Video topics by Alister Christie include VCL (Visual Component Library), FireMonkey, FireDAC, Cross-platform, Android, iOS (iPad or iPhone Operating System), Mac OS/X, Windows, IoT (Internet of Things), Algorithms, and more.

Рекомендации по теме
Комментарии
Автор

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.)

Graham_Wideman
Автор

interesting, with Lazarus at 04:04 I get TDog TDog

thierrybo
Автор

Very interesting video. Thank you very much.

jensknaack
Автор

I am not sure if this programming pattern should be applied at all.

schobihh
Автор

Thanks for sharing, it is really confusion that the subclass class constructor not behaving as it should.

kennethmark
Автор

rad optimization standards, interesting

CorsaDT