Cédric Joubert wrote:
> I've made a little example that works fine, but i don't know if it is what
> you were expecting.
> The problem is :
> if you replace all my "class function" with simple functions, it still
> works...
> so my example do not show the using of generic reference of class you were
> attending ;-)
>
> [...]
>
> procedure TForm1.Test(AFormatType : enumFormatter);
> var
> myClass : TFormatterClass;
> ftClass : TFormatter;
Rename "myClass" to be "ftClass" and then get rid of the TFormatter
variable. (The prefix "my" doesn't really describe the code in terms of
what it does. It describes the code in terms of who wrote it, and then
only when you already know who wrote it. It alienates everyone else
reading your code, too.)
> begin
> myClass := nil;
>
> case AFormatType of
> ftArrangementNumber : myClass := TArrangementNumberFormatter;
> ftCustomerNumber : myClass := TCustomerNumberFormatter;
> end;
> ftClass := myClass.Create;
>
> ShowMessage(ftClass.FormatString('Text to format'));
Now that you've gotten rid of the instance variable, get rid of the line
that calls the constructor. You're creating an instance of a class that
never needs to have an instance. You can call class methods directly on
the class-reference variable.
--
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi