Hmmm....I'd do something like this, TBaseNumberFormatter = class(TObject) private class function FormatString(...): String; virtual; abstract; end;
TCustomerNumberFormatter = class(TBaseNumberFormatter) private class function FormatString(...): String; override; end; TArrangementNumberFormatter = class(TBaseNumberFormatter) private class function FormatString(...): String; override; end; TNumberFormatterClass = class of TBaseNumberFormatter; ... var MyClass: TNumberFormatterClass; case FormatType of ftArrangmentNumber: MyClass := TArrangementNumberFormatter; ftCustomerNumber: MyClass := TCustomerNumberFormatter; end; {case} Edit1.Caption := MyClass.FormatString(...); That's purely ottomh, so I may not have the details exactly correct. Hopefully it'll point you in the right direction though. Regards, Darren Jesper Stenlund wrote: > 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? > _______________________________________________ Delphi mailing list -> Delphi@elists.org http://lists.elists.org/cgi-bin/mailman/listinfo/delphi