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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:04:22+00:00 2026-06-01T11:04:22+00:00

I have a few different classes which origin is a another class. I have

  • 0

I have a few different classes which origin is a another class. I have one property that is extended to all other classes.
But different classes handle this property differently.
So i want to do this:

TClass(ObjectPointer).Property:=Value;

But TClass is unknown class type

Can i do something like that:

ObjectPointer.ClassType(ObjectPointer).Property:=Value

or this

var
   ClassRef: TClass;
begin

   ClassRef := Sender.ClassType;
   ClassRef(ObjectPointer).DoStuff
   end;

Is there way to do this in delphi without using if statement

  • 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-01T11:04:23+00:00Added an answer on June 1, 2026 at 11:04 am

    Please note, the code from this post will work only for published properties!

    To answer your question if there’s a way to set a property value without using if statement, check the following overloaded functions.

    The first one is for char, string, variant, integer, 64-bit integer, float, enumeration, set and dynamic array type of properties (phew). The second one is just for class type properties. Both will return True if given property exists and the value or object instance is successfuly assigned, False otherwise:

    uses
      TypInfo;
    
    function TrySetPropValue(AInstance: TObject; const APropName: string;
      const AValue: Variant): Boolean; overload;
    begin
      Result := True;
      try
        SetPropValue(AInstance, APropName, AValue);
      except
        Result := False;
      end;
    end;
    
    function TrySetPropValue(AInstance: TObject; const APropName: string;
      AValue: TObject): Boolean; overload;
    begin
      Result := True;
      try
        SetObjectProp(AInstance, APropName, AValue);
      except
        Result := False;
      end;
    end;
    

    And the usage; when the Memo1.Lines is set the, the second version of TrySetPropValue is called:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Strings: TStringList;
    begin
      TrySetPropValue(Memo1, 'Width', 250);
      TrySetPropValue(Memo1, 'Height', 100);
      TrySetPropValue(Memo1, 'ScrollBars', ssBoth);
    
      Strings := TStringList.Create;
      try
        Strings.Add('First line');
        Strings.Add('Second line');
        TrySetPropValue(Memo1, 'Lines', Strings);
      finally
        Strings.Free;
      end;
    
      if not TrySetPropValue(Memo1, 'Height', 'String') then
        ShowMessage('Property doesn''t exist or the value is invalid...');
      if not TrySetPropValue(Memo1, 'Nonsense', 123456) then
        ShowMessage('Property doesn''t exist or the value is invalid...');
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many different small classes which have a few fields each, e.g. this:
I have few different applications among which I'd like to share a C# enum.
We have a few different programs all compiled together in the same suite, recently
I have seen a few different in-process SQL databases for .NET (including one from
I have been researching a few different apps lately for my company which are
I have app with two sites, one where design is done and other which
I have a few related applications that I want to deploy to different computers.
Building a GUI system and I have a few classes for different GUI components
I need to create module in Magento which will have few database tables. One
I have few Pojos in different packages, each POJO contains set of the another

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.