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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:48:56+00:00 2026-05-26T14:48:56+00:00

Looking for a way in Delphi to do deep object comparison for me, preferably

  • 0

Looking for a way in Delphi to do deep object comparison for me, preferably 2010 RTTI based as my objects don’t inherit from TComponent. I’m developing a test framework in DUnit and need something solid which will point out exactly which field is causing problems (serialization comparison leaves it a bit vague).

  • 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-05-26T14:48:56+00:00Added an answer on May 26, 2026 at 2:48 pm

    Sort of solved this myself, implemented as a class helper for TObject so can be used everywhere if people want it. D2010 and up due to RTTI but you may be able to convert it to use original RTTI stuff.

    Code below may be buggy as originally mine was for DUnit and had lots of checks in it instead of changing the result and doesn’t support TCollections or a load of other special cases but can be adapted for that by using the if-elseif-then switch in the middle.

    If you have any suggestions and additions please don’t hesitate to comment so I can add them to it so other people can use this.

    Have fun coding

    Barry

    unit TObjectHelpers;
    
    interface
       uses classes, rtti;
    
    type
    
    TObjectHelpers = class Helper for TObject
      function DeepEquals (const aObject : TObject) : boolean;
    end;
    
    implementation
    
    uses sysutils, typinfo;
    
    { TObjectHelpers }
    
    function TObjectHelpers.DeepEquals(const aObject: TObject): boolean;
    var
      c : TRttiContext;
      t : TRttiType;
      p : TRttiProperty;
    begin
    
      result := true;
    
      if self = aObject then
        exit; // Equal as same pointer
    
      if (self = nil) and (aObject = nil) then
        exit; // equal as both non instanced
    
      if (self = nil) and (aObject <> nil) then
      begin
        result := false;
        exit; // one nil other non nil fail
      end;
    
      if (self <> nil) and (aObject = nil) then
      begin
         result := false;
         exit; // one nil other non nil fail
      end;
    
      if self.ClassType <> aObject.ClassType then
      begin
         result := false;
         exit;
      end;
    
      c := TRttiContext.Create;
      try
        t := c.GetType(aObject.ClassType);
    
        for p in t.GetProperties do
        begin
    
           if ((p.GetValue(self).IsObject)) then
           begin
    
              if not TObject(p.GetValue(self).AsObject).DeepEquals(TObject(p.GetValue(aObject).AsObject)) then
              begin
          result := false;
          exit;
        end;
    
      end
      else if AnsiSameText(p.PropertyType.Name, 'DateTime') or AnsiSameText(p.PropertyType.Name, 'TDateTime') then
      begin
    
        if p.GetValue(self).AsExtended <> p.GetValue(aObject).AsExtended then
        begin
          result := false;
          exit;
        end;
    
      end
      else if AnsiSameText(p.PropertyType.Name, 'Boolean') then
      begin
    
        if p.GetValue(self).AsBoolean <> p.GetValue(aObject).AsBoolean then
        begin
          result := false;
          exit;
        end;
    
      end
      else if AnsiSameText(p.PropertyType.Name, 'Currency') then
      begin
    
         if p.GetValue(self).AsExtended <> p.GetValue(aObject).AsExtended then
         begin
            result := false;
            exit;
         end;
    
      end
      else if p.PropertyType.TypeKind = tkInteger then
      begin
    
        if p.GetValue(self).AsInteger <> p.GetValue(aObject).AsInteger then
        begin
          result := false;
          exit;
        end;
    
      end
      else if p.PropertyType.TypeKind = tkInt64 then
      begin
    
        if p.GetValue(self).AsInt64 <> p.GetValue(aObject).AsInt64  then
        begin
          result := false;
          exit;
        end;
    
      end
      else if p.PropertyType.TypeKind = tkEnumeration then
      begin
    
        if p.GetValue(self).AsOrdinal <> p.GetValue(aObject).AsOrdinal then
        begin
          result := false;
          exit;
        end;
    
      end
      else
      begin
    
        if p.GetValue(self).AsVariant <> p.GetValue(aObject).AsVariant then
        begin
          result := false;
          exit;
        end;
    
      end;
    
    end;
    
     finally
       c.Free;
      end;
    
     end;
    
     end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking on the Delphi newsgroups, it appears the best way to GET content from
I'm looking for way to PHP to detect if a script was run from
Using either Delphi 2007+ or Lazarus(Win64) I'm looking for a way to determine if
I am looking for a way to develop a plugin for Delphi 2010IDE and
I've been looking for a way to monitor for specific registry changes in Delphi.
I'm looking for a way to use the content repository of Apache Jackrabbit from
I am looking for a software that can reverse engineering a delphi 2010 project
I'm looking for a way to extract the computer SID using Delphi code. There's
I'm looking for a way to write GeoTIFF files in Delphi. If possible, I
I am looking for a way to use my webcam in delphi, primary for

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.