Constraint Issue

I’m having an issue with constraints in that when I name a constraint, I am not able to later access that constraint from code. So here’s an example. In the screenshot below, I have a constraint named SourceLeft on a canvas.

I have the following code in the Activated event of my view:

If ItisIPad Then
  Dim c As iOSLayoutConstraint = SourceLabelCanvas.Constraint("SourceLeft")
  c.Offset = 120
End If

But when this runs, I get a Nil object exception. I have tried this multiple times and multiple ways on multiple controls and I am unable to get the constraint returned. What am I doing wrong? Is this a Xojo bug? I’m using Xojo 2025r2.1 right now..

I see my problem after looking at the examples. The constraint is a property of the view not of the control..

Constraints are part of the layout, not the controls. Try Self.Constraint…

1 Like