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 7898715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:30:33+00:00 2026-06-03T08:30:33+00:00

For logging and reporting reasons I create objects that have the class name and

  • 0

For logging and reporting reasons I create objects that have the class name and message belonging to an Exception. I do this so I don’t have to manage the lifetime of the Exception object. What I would like to do is recover the advantages of RTTI identification that allow you to tell if an object is derived from a given class using the “is” operator in Delphi 6.

Is there a way to use a class name in string form to tell if the class the string contains is derived from another class?

Suppose I have the class of an object stored in strClassName and that class is “derivedClass”. Further, derivedClass is derived from baseClass. Is there a function I can write that can tell if the class in string form in strClassName is derived from baseClass? For example:

// Hypothetical function that returns TRUE if the class in strClassName is
//  derived from the class passed in theBaseClass
function isDerivedClass(strClassName: string; theBaseClass: TAnyClass): boolean;

What would the body of that method look like?

  • 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-06-03T08:30:35+00:00Added an answer on June 3, 2026 at 8:30 am
    function isDerivedClass(strClassName: string; theBaseClass: TClass): boolean;
    begin
      Result := FindClass(strClassName).InheritsFrom(theBaseClass);
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      RegisterClass(TLabel); // must be registered to be found by FindClass/GetClass
    
      if isDerivedClass('TLabel', TWinControl) then
        ..
    

    If you don’t want an exception to be raised when a class by the name ‘strClassName’ cannot be found, use GetClass instead of FindClass:

    function isDerivedClass(strClassName: string; theBaseClass: TClass): boolean;
    var
      aClass: TClass;
    begin
      Result := False;
      aClass := GetClass(strClassName);
      if Assigned(aClass) then
        Result := aClass.InheritsFrom(theBaseClass);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that uses the Ent Lib 4.1 logging application block. This
I'm using a logging module that can have reporting enabled/disabled at runtime. Calls generally
For logging purposes, I'd like to create a logger that automatically adds the current
In my unhandled exception logging I see this error sporadically through the day on
In my CI config file I have this logging treshold set: $config['log_threshold'] = 1;
I have successfully configured an application that uses log4j for it's logging to log
We have exception catching code in most of our event handlers etc, this leads
I have a logging table that I need to run close to real time
I have a SQL Reporting Services instance that has a couple of reports with
I have a commons-logging configuration question. I want it to use SimpleLog (instead of

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.