The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,262 other subscribers

The IOTAComponent.SetPropByName, when used for an integer property, always sets that property to 0 instead of the desired value.

Posted by jpluimers on 2019/01/03

Reminder to self: [WayBack…The IOTAComponent method SetPropByName, when used for an integer property, always sets that property to 0 instead of the desired value…. – Thomas Mueller (dummzeuch) – Google+

Fix in GExperts for the Rename Component functionality in [WayBack] GExperts / Code / Commit [r2318]: Workaround for an apparent OTA-bug: IOTAComponent.SetPropByName for integers always sets the property to 0 instead of the given value. Now we compare the values and if they don’t match use RTTY on the NativeObject to set it. This seems to work. (The bug exists on Delphi 2007 and 10.2, I haven’t tested other versions. The bugfix also works on these versions.):

         VInteger := StrToInt(Value);
         Result := AComponent.SetPropByName(PropertyName, VInteger);
+        if AComponent.GetPropValueByName(PropertyName, TempInt) then begin
+          // Setting an integer property often (always?) fails, so we check the value here and if
+          // it is different, we use the native object to set the value. This works.
+          // (Example: Try to set the Interval property of a TTimer. It always gets set to 0.)
+          // This happens in Delphi 2007 and 10.2, I haven't tested other versions.)
+          // -- 2018-07-16 twm
+          if TempInt <> VInteger then
+            SetPropValue(NativeObject, PropertyName, VInteger);
+        end;

Only the IOTAComponent interface is mentioned (only once!) in the documentation at [Archive.is] Using Editor Interfaces – RAD Studio, so I have ambivalent feelings on how important this is for Embarcadero to fix IOTAComponent.SetPropByName.

It has been broken since at least Delphi 2007 as per GExperts fix and XE3 as per [RSP-20895] IOTAComponent.SetPropByName always sets an integer to zero – Embarcadero Technologies.

–jeroen

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.