I want to give a default value in a metaclass argument:
type
TMyClass = class
end;
type
TMyClassMetaClass = class of TMyClass;
procedure MyProcedure(const AMetaClass: TMyClassMetaClass = TMyClass);
It is possible? In Delphi2009 it gives me the error: E2026 Constant expression expected
According to the rules of the language, a metaclass is not a constant expression. So your best bet is to use overloading instead:
procedure MyProcedure(const AMetaClass: TMyClassMetaClass); overload;
procedure MyProcedure; overload;
And in the implementation:
procedure MyProcedure(const AMetaClass: TMyClassMetaClass);
begin
....
end;
procedure MyProcedure;
begin
MyProcedure(TMyClass);
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With