{"id":54,"date":"2012-10-09T12:32:16","date_gmt":"2012-10-09T10:32:16","guid":{"rendered":"http:\/\/blog.kassebaum.eu\/?p=54"},"modified":"2012-10-09T12:32:16","modified_gmt":"2012-10-09T10:32:16","slug":"records","status":"publish","type":"post","link":"https:\/\/www.kassebaum.eu\/blog\/2012\/10\/09\/records\/","title":{"rendered":"Records"},"content":{"rendered":"<p>Because of my post about the Switches I would like to mention some things about records. Records are are nice way to do things in an object-oriented way without the overhead of real objects. In the unit System.IOUtils you can find several examples of records.<\/p>\n<pre class=\"lang:delphi decode:true\" title=\"System.IOUtils.pas\">...\r\nunit System.IOUtils;\r\n...\r\n  TDirectory = record\r\n  public\r\n...<\/pre>\n<p>Certainly you have to deal with some disadvantages:<\/p>\n<ol>\n<li>No inheritance. If you need inheritance then use objects.<\/li>\n<li>The constructor needs at least one argument. I guess it is because there is no need to create an instance of a &#8220;normal&#8221; record.<\/li>\n<li>No destructor. Records are destroyed automatically so that it is not possible to define a destructor.<\/li>\n<\/ol>\n<p>For the point 1 there is nothing you can do but for the two other pints there is a workaround.<\/p>\n<pre class=\"lang:delphi decode:true\" title=\"System.Rtti\">  TRttiContext = record\r\n  ...\r\n  public\r\n    class function Create: TRttiContext; static;\r\n    procedure Free;\r\n    ...\r\n  end;<\/pre>\n<p>As you can see it is possible to define a class function for the constructor and a method for Free so so that you can use the record in the way you are used to.<\/p>\n<pre class=\"lang:delphi decode:true\" title=\"Use of a Record\">var\r\n  pContext: TRttiContext;\r\nbegin\r\n  pContext := TRttiContext.Create;\r\n  try\r\n    ...\r\n  finally\r\n    pContext.Free;\r\n  end;\r\nend;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Because of my post about the Switches I would like to mention some things about records. Records are are nice way to do things in an object-oriented way without the overhead of real objects. In the unit System.IOUtils you can &hellip; <a href=\"https:\/\/www.kassebaum.eu\/blog\/2012\/10\/09\/records\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[5],"class_list":["post-54","post","type-post","status-publish","format-standard","hentry","category-tipsandtricks","tag-delphi"],"_links":{"self":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":1,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":55,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts\/54\/revisions\/55"}],"wp:attachment":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}