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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:39:05+00:00 2026-06-14T14:39:05+00:00

I am using Delphi. I have a root class and many derived class from

  • 0

I am using Delphi. I have a root class and many derived class from the root, the name of the class says TROOT, TA, TB, TC … In the code, I have some code to control the flow of the program by following code

var
  obj :TROOT;
begin
  if ((obj is TA) or (obj is TB) or (obj is TC) or (obj is TD)) then
  begin
    // some other codes here
  end
end;

this code works good but then I extend my code so more subclasses are derived from TROOT and that swtich appears at more than one place in the program. Is there any way I can put the class type into a set or array and have some psudeo code like following so I don’t have to modify everywhere when the code is extended?

classarray = {TA, TB, TC, TD, TE, TF};
if (obj in classarray) then
begin
  // put my code here
end

Thanks.

  • 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-14T14:39:06+00:00Added an answer on June 14, 2026 at 2:39 pm

    You can of course put the classes in an array. Declare the types like this:

    type
      TRootClass = class of TRoot;
      TRootClassArray = array of TRootClass;
    

    Declare and populate the array:

    var
      RootClasses: TRootClassArray;
    
    SetLength(Classes, 4);
    RootClasses[0] := TA;
    RootClasses[1] := TB;
    RootClasses[2] := TC;
    RootClasses[3] := TD;
    

    Then you can test the contents of the array:

    var
      c: TRootClass;
    
    for c in RootClasses do
      if obj is c then
        // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Delphi XE2 with FireMonkey. I have read many other questions about MD5
I have this delphi code that basically download a file (using Delphi 2010 +
I have no idea why, but using Delphi 2009's ribbon control, the small images
Using Delphi XE on Win7 x64, have Jedi Class Library ver. 3.45, and 7z.dll
I'm automating some document creation using Delphi 2010. In the layout I have, I
Is possible create (register) a new class in runtime using delphi. I have a
I'm using TNMHTTP in Delphi to retrieve the code from a webpage. The code
I'm using Delphi 2010 on Windows 7 and have a problem with single quotes
I have just started a new project, and I am using the Delphi 2009
I have a Delphi 2009 application that runs a query over a database using

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.