Często używam konstrukcji
is as
do kastowania parametru eventów Sender: TObject
w taki sposób:
```delphi
if (Sender is TStringGrid) then
sg := (Sender as TStringGrid)
else
Exit;
Chciałem zrobić funkcję której użycie wyglądało by tak:
if not GF<TStringGrid>.TryCastSender( Sender, sgs ) then Exit;
pytanie jak powinno wygląda ciało funkcji, żeby uzyskać taki efekt?
zmajstrowałem coś takiego ale nie idzie skompilować:
class function GenericsFunc<T>.SenderCast( const ASender: TObject; out OCastedSender: T ): boolean;
begin
result := ASender is T;
OCastedSender := T(0);
if not result then Exit;
// OCastedSender := T(ASender);
OCastedSender := ASender as T;
end;
Jakieś pomysły?