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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:08:31+00:00 2026-06-02T07:08:31+00:00

I have a class in my Delphi app where I would like an easy

  • 0

I have a class in my Delphi app where I would like an easy and dynamic way of resetting all the string properties to ” and all the boolean properties to False
As far as I can see on the web it should be possible to make a loop of some sort, but how to do it isn’t clear to me.

  • 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-02T07:08:34+00:00Added an answer on June 2, 2026 at 7:08 am

    Please note, the following code works only for published properties of a class! Also, the instance of a class passed to the function below must have at least published section defined!

    Here is how to set the published string property values to an empty string and boolean values to False by using the old style RTTI.

    If you have Delphi older than Delphi 2009 you might be missing the tkUString type. If so, simply remove
    it from the following code:

    uses
      TypInfo;
    
    procedure ResetPropertyValues(const AObject: TObject);
    var
      PropIndex: Integer;
      PropCount: Integer;
      PropList: PPropList;
      PropInfo: PPropInfo;
    const
      TypeKinds: TTypeKinds = [tkEnumeration, tkString, tkLString, tkWString,
        tkUString];
    begin
      PropCount := GetPropList(AObject.ClassInfo, TypeKinds, nil);
      GetMem(PropList, PropCount * SizeOf(PPropInfo));
      try
        GetPropList(AObject.ClassInfo, TypeKinds, PropList);
        for PropIndex := 0 to PropCount - 1 do
        begin
          PropInfo := PropList^[PropIndex];
          if Assigned(PropInfo^.SetProc) then
          case PropInfo^.PropType^.Kind of
            tkString, tkLString, tkUString, tkWString:
              SetStrProp(AObject, PropInfo, '');
            tkEnumeration:
              if GetTypeData(PropInfo^.PropType^)^.BaseType^ = TypeInfo(Boolean) then
                SetOrdProp(AObject, PropInfo, 0);
          end;
        end;
      finally
        FreeMem(PropList);
      end;
    end;
    

    Here is a simple test code (note the properties must be published; if there are no published properties in the class, at least empty published section must be there):

    type
      TSampleClass = class(TObject)
      private
        FStringProp: string;
        FBooleanProp: Boolean;
      published
        property StringProp: string read FStringProp write FStringProp;
        property BooleanProp: Boolean read FBooleanProp write FBooleanProp;
      end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      SampleClass: TSampleClass;
    begin
      SampleClass := TSampleClass.Create;
      try
        SampleClass.StringProp := 'This must be cleared';
        SampleClass.BooleanProp := True;
        ResetPropertyValues(SampleClass);
        ShowMessage('StringProp = ' + SampleClass.StringProp + sLineBreak +
          'BooleanProp = ' + BoolToStr(SampleClass.BooleanProp));
      finally
        SampleClass.Free;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Almost all of the Delphi code I have read has all the class type
I have a Delphi 2006 app with a CHM help file. It all works
I want to write in Delphi (2009 - so I have generic dictionary class)
I have: class Foo { int a; int b; std::string s; char d; };
I have a Delphi form with a bunch of VCL controls, like TButton and
I have a query in Delphi using DBExpress TSQLQuery that looks like so ActiveSQL.sql.add('SELECT
Coming from a Delphi background, I am used to be able to have class
Is it possible in Delphi to have a class method invoke an inherited instance
I have a C++ class that I am converting to Delphi that has a
In Delphi we have an option to do a thing like this: TClass1 =

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.