Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6685211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:01:55+00:00 2026-05-26T05:01:55+00:00

I have a Delphi 6 Metaclass variable that services a component property for a

  • 0

I have a Delphi 6 Metaclass variable that services a component property for a design time Server component:

type
  TClientClass = class of TClient;
...
FClientClass: class of TClientClass;
FClientObj: TClient;

I have another design-time component that is a Client component. At design time I assign a concrete instance of the Client component, dropped on to the same Form, to the Server component using the Server’s “client” property via the IDE’s Property Editor. However, I also want to assign the FClientClass variable the underlying class of the concrete component I am assigning to FClientObj via the “client” property. This is so the Server component can create new instances of the Client component at run time, using FClientClass.Create.

I can’t figure out how to assign the underlying class of the “client” object to the FClientClass data member when I set the FClientObj data member via the Server component’s property setter:

procedure setClientClass(theClient: TClient);
begin
    // Assign the "client" property.  This works.
    FClientObj := theClient;

    // Assign the class of the "client" object to the Metaclass variable.
    // THIS DOESN'T WORK: incompatible types error from the compiler.
    FClientClass := theClient;
end;

I’m pretty sure the problem is that I am trying to assign an object of TClient to a Metaclass of TClient variable. I just don’t know the correct syntax to make the assignment. I don’t want to just do:

FClientClass := TClient;

because I want to allow for the assignation of concrete components in the future that may be descendants of TClient.

What is the syntax for doing the assignment correctly? I’m hoping it is simpler than doing something complex with the RTTI library like as Malte’s reply in this thread indicates:

How can I create an Delphi object from a class reference and ensure constructor execution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:01:56+00:00Added an answer on May 26, 2026 at 5:01 am

    I believe you are looking for TObject.ClassType. Use it like this:

    procedure setClientClass(theClient: TClient);
    begin
      FClientObj := theClient;
      FClientClass := TClientClass(theClient.ClassType);
    end;
    

    Note 1: I’m assuming that you mean FClientClass: TClientClass rather than FClientClass: class of TClientClass.

    Note 2: I’ve only compiled this in my head; I hope it works on a real compiler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Delphi Web Server setup and running, publishing Web Services, and I
I have a Delphi 6 application that is heavily multithreaded. I have a component
I have a Delphi generic class that exposes a function with an argument of
We have a Delphi 2006 application that drives a MS SQL Server database. We
I have Windows Server 2008 R2 Machine that is running a Delphi 2007 application.
I have a Delphi 6 application that uses the DSPACK component library. That library
I have a Delphi 7 application that has two views of a document (e.g.
I have a delphi (Win32) web application that can run either as a CGI
I have a Delphi 5 executable that calls into a .NET assembly via the
I have a Delphi application similar to Taskbar Shuffle that includes a hook dll.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.