>with ControllerClass do begin
> ControllerClass.AddElement(TSpecificChild.Create);
> with TSpecificChild(LastElement) do begin
> // Do Stuff
> end;
>end;
>
>Is there some way of doing this without that cast? (or an is / as paring)
>It works fine as is but I would quite like to remove the casting. Should I
>provide the method in the abstract class, override in the child class to
>return itself?
If what you are doing here (the "Do Stuff" part) depends on the
object in hand being a TSpecificChild then I think a better way
would be to have a class method
class function AddSpecificElement: TSpecificChild;
in each TSpecificChild that calls the ControllerClass.AddElement.
(It could even be a constructor if the error handling isn't too messy)
then your code above looks like
with TSpecificChild.AddSpecificElement do begin
// Do Stuff
end;
and the class function looks like
class function TSpecificChild.AddSpecificElement: TSpecificChild;
begin
result:= TSpecificChild.Create;
ControllerClass.AddElement(Result);
end;
A nice thing about doing it this way is that TSpecificChild.Create
can be private leaving AddSpecificElement as the only way to create
one of these things, presumably what you want.
ns
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"