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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:03:44+00:00 2026-06-07T03:03:44+00:00

In Delphi, sometimes we need to do this… function TForm1.EDIT_Click(Sender: TObject); begin (Sender As

  • 0

In Delphi, sometimes we need to do this…

function TForm1.EDIT_Click(Sender: TObject);
begin
  (Sender As TEdit).Text := '';
end;

…but sometimes we need to repeat the function with other object class like…

function TForm1.COMBOBOX_Click(Sender: TObject);
begin
  (Sender As TComboBox).Text := '';
end;

…because the operator As does not accept flexibility. It must know the class in order to allow the .Text that come after the ().

Sometimes the code gets full of similar functions and procedures because we need to do the same thing with similar visual controls that we can’t specify.

This is only an case of use example. Generally I use these codes on more complex codes to achieve a standard objective on many controls and other kind of objects.

Is there an alternative or trick to make these tasks more flexible?

  • 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-07T03:03:45+00:00Added an answer on June 7, 2026 at 3:03 am

    Use RTTI to perform common tasks on similarly-named properties of unrelated classes, eg:

    Uses
     ..., TypInfo;
    
    // Assigned to both TEdit and TComboBox
    function TForm1.ControlClick(Sender: TObject);
    var
      PropInfo: PPropInfo;
    begin
      PropInfo := GetPropInfo(Sender, 'Text', []);
      if Assigned(PropInfo) then
        SetStrProp(Sender, PropInfo, '');
    end;
    

    In some cases, some controls use Text and some use Caption instead, eg;

    function TForm1.ControlClick(Sender: TObject);
    var
      PropInfo: PPropInfo;
    begin
      PropInfo := GetPropInfo(Sender, 'Text', []);
      if not Assigned(PropInfo) then
        PropInfo := GetPropInfo(Sender, 'Caption', []);
      if Assigned(PropInfo) then
        SetStrProp(Sender, PropInfo, '');
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps a stupid question, but what exactly is the purpose of this Delphi folder?:
I use ActivateKeyboardLayout(HKL_NEXT, KLF_ACTIVATE); to load Persian keyboard layout using Delphi XE2, But sometimes
I'm using Delphi 2007. Sometimes properties linking to components get lost. This is typically
Delphi has this function: function VarToDateAsString(const V: TVarData): TDateTime; .... LResult := VarDateFromStr(S, VAR_LOCALE_USER_DEFAULT,
// delphi code (delphi version : Turbo Delphi Explorer (it's Delphi 2006)) function GetLoginResult:PChar;
Delphi XE2 starter for me, but maybe a general answer will help others ...
Delphi used to include a demos folder for web Services, but no longer seems
I sometimes try to understand what constitute the size of my exe in Delphi.
Sometimes, when coding in RAD Studio 2009 (Delphi), suddently the behaviour of the code
ShlObj.pas line 9922 (as in Delphi XE): type BFFCALLBACK = function(Wnd: HWND; uMsg: UINT;

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.