Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

Logging FireMonkey TControl


#1

How do you do this ?

I tried LogObject, but it gave me an AV.

TIA

Sue


#2

Hello Sue,

Thanks for your posting. An AV inside LogObject is most likely caused by an invalid object that is passed to LogObject (e.g. that has been free’d before). Could this be the case?

Regards,
Tobias


#3

Hello Tobias,

No.

I have tried in two cases.

  1. Calling LogObject on a FMX TRectangle that is on the form, when clicking on a button on the form.

  2. Creating the object in code and the trying to log it. Code snip :

     begin
       if X > FNewCtrl.Position.X then
       begin
         FNewCtrl.Width := X - FNewCtrl.Position.X;
         if Y > FNewCtrl.Position.Y then
         begin
           FNewCtrl.Height := Y - FNewCtrl.Position.Y;
         end
    
       end;
       tbsSiMain.LogObject('newctrl', TRectangle(FNewCtrl));
     end;
    

A call to LogString below this code can access the Position X and Y.

tbsSiMain descends from TSiSession and has some additional methods, but does not override any existing methods.

Tracing through with the debugger, it is failing on this statement in SmartInspect.pas

          LProperties.Add(
            AContext.EscapeItem(UnicodeString(LPropName)) + '=' +
            AContext.EscapeItem(FloatToStr(GetFloatProp(AInstance, LPropInfo)))

with GetFloatProp(AInstance, LPropInfo) returning 0000000 for TRectangle StrokeThickness property.

Regards,
Sue


#4

Hello Tobias,

Have you had a chance to look at this ?

I’m starting a project using FMX, and not being able to use LogObject is a real nuisance.

Regards

Sue


#5

Hello Sue,

Thanks for the update. We haven’t seen this behavior before. This could be an issue with the Delphi detection of the TRectangle type as the code section you’ve posted would only apply to floats. Could you please try to comment out/remove the lines for the tkFloat type in LogObject and try this again?

Regards,
Tobias


#6

Hello Tobias,

I’ve done some more testing and narrowed it down a bit.

The problem is not in floats as such, as properties such as Height are fine.

The issue seems to be with the the Stroke property. If floats are logged, Thickness fails. If floats are commented out, enumeration failed on Cap property.

Looking in the debugger, the property name is StrokeThickness, or StrokeCap. In the Object Inspector, they are Stroke.Thickness and Stroke.Cap. The value returned by GetFloatProp for thickness is returning nil.

HTH,

Sue


#7

Hello Sue,

Thanks for your reply. Which types do Stroke and Stroke.Thickness/Stroke.Cap have? Does LogObject/Delphi recognize the Stroke property as float? You can alternatively also look into logging the object manually (e.g. via a custom method or only the relevant properties).

Regards,
Tobias


#8

Hello Tobias,

Looking at Stroke.Cap, it is of type TStrokeCap, defined in FMX.Graphics.

I think it would be easiest for you to look at this for yourself with a sample app. All you need is an FMX form with a Rectangle placed on it, and a button that calls logging of the Rectangle when clicked.

It looks to me as though LogObject should detect this as an unrecognised type and not be logged, but that is not really a solution, as it defeats the purpose of logging an object.

Hopefully support for these FMX objects will be in the new version for XE7, with some updates for older versions, such as XE6.

Regards
Sue


#9

Hello Tobias,

I did another test with Stroke Thickness. To log this field individually, I had to log Rectangle1.Stroke.Thickness. If I tried to use Rectangle1.StrokeThickness, the compiler gave an error that I could not read a write only property. In the debugger, the property name shown when trying to log this field is StrokeThickness. Don’t know if the write only property is relevant or not, but thought I would mention it.

I don’t know what method to use to call to log Stroke.Cap/StrokeCap;

Regards
Sue


#10

Thanks for the additional details, Sue. I think the write-only property is the key here and this might not be supported by GetFloatProp etc. I would recommend logging the object/rectangle manually for now (or writing a custom log method via LogCustomContext) instead of using LogObject. Would this work for you?

Regards,
Tobias


#11

Hello Tobias,

In the short term I will have a go with the LogCustomContext.

Do you think this will be resolved in the upcoming SmartInspect so that FMX objects are properly handled ?

Regards

Sue


#12

Thanks for the update, Sue, and good to hear that a custom log method would work for you as a workaround. We will also make sure to look into the FMX issue.

Regards,
Tobias


#13

Thanks,

Looking forward to the new release,

Regards,
Sue