Is it possible that in Delphi the class method calls the inherited instance method with the same name? For example, I tried something like this:
//... Skipped surrounding class definitions function TSomeAbstractDialogForm.Execute: Boolean; begin Result := ShowModal = mrOk; end;
I had several specialized dialog classes that inherited the abstract form of dialogue, and each class had its own factory method:
class function TSomeInheritingDialogForm.Execute: Boolean; var Fm: TSomeInheritingDialogForm; begin Fm := TSomeInheritingDialogForm.Create(nil); try Result := Fm.Execute; finally Fm.Free; end end;
This approach led to an endless loop, because F.Execute, instead of calling the method of the alleged instance of the base class, continued to call the factory method again and again (the result is a bunch of created forms).
Of course, the obvious solution was to change the name of the factory method (I called it CreateAndShow), but I was curious. Why didn't the compiler warn me about a hidden method? Is there a way to explicitly call the instance method in this situation?
source share