{"id":159,"date":"2013-04-20T09:26:50","date_gmt":"2013-04-20T07:26:50","guid":{"rendered":"http:\/\/blog.kassebaum.eu\/?p=159"},"modified":"2013-04-24T18:16:10","modified_gmt":"2013-04-24T16:16:10","slug":"record-helpers-for-intrinsic-types-part-2","status":"publish","type":"post","link":"https:\/\/www.kassebaum.eu\/blog\/2013\/04\/20\/record-helpers-for-intrinsic-types-part-2\/","title":{"rendered":"Record Helpers for Intrinsic Types, Part 2 &#8211; Update"},"content":{"rendered":"<p>This week I used some record helpers for intrinsic types and I think that they are a wonderful feature. This means that you should update at least to XE3 to use this great feature.<\/p>\n<p>But as always there are some issues: I had an resourcestring and wanted to access to the length.<\/p>\n<pre class=\"lang:delphi decode:true\" title=\"Resourcestring And String Helper\">\r\nprogram TestHelper;\r\n\r\n{$APPTYPE CONSOLE}\r\n\r\nuses\r\n  System.SysUtils;\r\n\r\nresourcestring\r\n  SAnswer = '42';\r\n\r\nbegin\r\n  Writeln('The length of ' + SAnswer + ' is:');\r\n  Writeln(SAnswer.Length);\r\n  Readln;\r\nend.<\/pre>\n<p>I tried to compile this code and it doesn&#8217;t! The compiler doesn&#8217;t know the method length although in System.SysUtils there is the TStringHelper with this method! I had been very surprised but then I thought that a resourcestring is not a string but only assignable to a string, something like a type string.<\/p>\n<p>With XE4 this code does compile which is the expected behavior! Many thanks for this fix.<\/p>\n<p>I talked about this issue to a friend (Many thanks to him!) and he told me that I should try a record helper for a WideString.<\/p>\n<pre class=\"lang:delphi decode:true \" title=\"WideStringHelper And Resourcestring\" >program TestHelper;\r\n\r\n{$APPTYPE CONSOLE}\r\n\r\nuses\r\n  System.SysUtils;\r\n\r\nresourcestring\r\n  SAnswer = '42';\r\n\r\ntype\r\n  TWideStringHelper = record helper for WideString\r\n  public\r\n    function Length: Integer; inline;\r\n  end;\r\n\r\n{ TWideStringHelper }\r\n\r\nfunction TWideStringHelper.Length: Integer;\r\nbegin\r\n  Result := System.Length(Self);\r\nend;\r\n\r\nbegin\r\n  Writeln('The length of ' + SAnswer + ' is:');\r\n  Writeln(SAnswer.Length);\r\n  Readln;\r\nend.\r\n<\/pre>\n<p>And this code does compile! This means that a resourcestring is a WideString. Again, I&#8217;m surprised. But run this small project. It shows that the length of &#8217;42&#8217; is 1. This is a bug!!! My friend told me that a there is already the Quality Central item 112844 for this bug. This means that you shouldn&#8217;t use a record helper for resourcestrings in XE3. I hope that this bug will be fixed in XE4, so stay tuned&#8230;.<\/p>\n<p>Again, under XE4 the resourcestring works like a string. This means that a TWideStringHelper doesn&#8217;t work, instead the TStringHelper does. And the length is the correct value. So many thanks for this fix. This is a very good reason to move to XE4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week I used some record helpers for intrinsic types and I think that they are a wonderful feature. This means that you should update at least to XE3 to use this great feature. But as always there are some &hellip; <a href=\"https:\/\/www.kassebaum.eu\/blog\/2013\/04\/20\/record-helpers-for-intrinsic-types-part-2\/\">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-159","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\/159","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=159"}],"version-history":[{"count":9,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"predecessor-version":[{"id":202,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/posts\/159\/revisions\/202"}],"wp:attachment":[{"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kassebaum.eu\/blog\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}