Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

the use of  'class of'

Posted on 2003-03-20
8
Medium Priority
?
144 Views
Last Modified: 2010-04-04
can anybody give me sample of using key word 'class of'
0
Comment
Question by:zhiyuan-yang
  • 4
6 Comments
 
LVL 9

Expert Comment

by:mocarts
ID: 8172530
did you tried type these words in Delphi Help? :)
wbr, mo.
0
 
LVL 2

Accepted Solution

by:
j42 earned 200 total points
ID: 8172752
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
 
LVL 2

Expert Comment

by:j42
ID: 8172758
consider this:

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

  myClass.DoSomething;
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:j42
ID: 8172838
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
 
LVL 2

Expert Comment

by:j42
ID: 8173148
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
 

Expert Comment

by:CleanupPing
ID: 9316670
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question