the use of 'class of'

can anybody give me sample of using key word 'class of'
zhiyuan-yangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mocartsCommented:
did you tried type these words in Delphi Help? :)
wbr, mo.
0
j42Commented:
Hi zhiyuan-yang,

a short example, not tested :-|



type
  TBaseClass = class
  public
    constructor Create; virtual; abstract;
    procedure DoSomething; virtual; abstract;
  end;

type
  TMyClass = class(TBaseClass)
  public
    constructor Create; virtual;
    procedure DoSomething; virtual;
  end;

type
  TMyClass_2 = class(TBaseClass)
  public
    constructor Create; virtual;
    procedure DoSomething; virtual;
  end;

type
  TAllClasses = class of TBaseClass;

function CreateClass(const class_: TAllClasses): TBaseClass;
begin
  Result := class_.Create;
end;

var
  myClass: TBaseClass;

...
  myClass := CreateClass(TMyClass);
  myClass.DoSomething;   // -> TMyClass.DoSomething;
...
  myClass := CreateClass(TMyClass_2);
  myClass.DoSomething;   // -> TMyClass_2.DoSomething;



Regards
J
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
j42Commented:
consider this:

  if someSwitch then
  begin
    myClass := CreateClass(TMyClass);
  end
  else
  begin
    myClass := CreateClass(TMyClass_2);
  end;

  myClass.DoSomething;
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

j42Commented:
Sorry for posting that often... The good ideas seam to come just after I've hit the submit button:

const
  ALL_THE_CLASSES: array[0..1] of TAllClasses = (TMyClass, TMyClass_2);

...
  myClass := CreateClass(ALL_THE_CLASSES[i]);
0
j42Commented:
Sorry, 4th post.
Should read:

type
 TMyClass = class(TBaseClass)
 public
   constructor Create; override;
   procedure DoSomething; override;
 end;

type
 TMyClass_2 = class(TBaseClass)
 public
   constructor Create; override;
   procedure DoSomething; override;
 end;
0
CleanupPingCommented:
zhiyuan-yang:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.