hi,

maybe with the "class of" declaration ?

A generic class :
    TFormatter = class  end;

A "class of" class :
   TFormatterClass = class of TFormatter;

TCustomerNumberFormatter = class (TFormatter)
private
  class function FormatString(aString: String): string;
end;

TArrangementNumberFormatter = class (TFormatter)
private
  class function FormatString(aString: String): string;
end;

Cédric

----- Original Message ----- 
From: "Jesper Stenlund" <jes...@handelsbanken.se>
To: <delphi@elists.org>
Sent: Tuesday, May 12, 2009 1:20 PM
Subject: Class method


>I have a bunch of classes that formats a string in different ways.
> Today I have to create an instance of a specific "formattingobject" and
> then run the formattingmethod.
> Instead of that behaviour I now want make the formattingmethod a class
> method.
>
> But that causes me some other problems.
> Here's a small example:
>
> TCustomerNumberFormatter = class (TObject)
> private
>  class function FormatString(aString: String): string;
> end;
>
> TArrangementNumberFormatter = class (TObject)
> private
>  class function FormatString(aString: String): string;
> end;
>
>
> Then I want to do something like this but I don't know exactly how to
> write my code.
>
> case FormatType of
>  ftArrangementNumber: myClass := TArrangementNumberFormatter;
>  ftCustomerNumber: myClass := TCustomerNumberFormatter;
> end;
>
> TEdit1.Caption := myClass.FormatString(myObject.StringToFormat);
>
>
> I know that last row isn't correct, but how can I do this?
>
> I hope you understand what I'm looking for.
> I want to use the classname that I get from the case-sentence and then run
> the class function on that particular class.
> Is it possible to do it like this?
>
>
> //Jesper
> _______________________________________________
> Delphi mailing list -> Delphi@elists.org
> http://lists.elists.org/cgi-bin/mailman/listinfo/delphi 

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to