1

In REALBasic, how do I loop through all of the objects in Window1? Is there some array property of Window1 with all of its children? Also, how do you set custom properties of objects: e.g. Me.isFlamingo = true Thanks in advance!

Paul Lefebvre
  • 6,253
  • 3
  • 28
  • 36
Leticia Meyer
  • 167
  • 1
  • 3
  • 10

2 Answers2

1

Adding properties to a built-in class like a pushbutton can be done in two ways. The better way would be to subclass the PushBustton class and to add properties to the subclass like you would with any custom class. The other, somewhat uglier way would be to use a pair of overloaded functions like this:

Function isFlamingo(Extends ByRef pb As PushButton) As Boolean
  Dim flamingo As Boolean
  //Do stuff to figure out if the PushButton is Flamingo-y
  //and Return a Boolean based on the result
  Return flamingo
End Function

And:

Sub isFlamingo(Extends ByRef pb As PushButton, Assigns b As Boolean)
  If b Then
    //Do stuff that makes the PushButton flamingo-y
  Else
    //Do stuff that makes the PushButton not flamingo-y
  End If
End Sub
Andrew Lambert
  • 1,869
  • 1
  • 17
  • 31
0

To iterate through the controls on a window, use code like this:

  ListBox1.DeleteAllRows

  For i As Integer = 0 To Self.ControlCount-1
    ListBox1.AddRow(Self.Control(i).Name)
  Next

(For this example, be sure to add at least one ListBox to the Window.)

Properties are set just like you describe: ObjectInstance.PropertyName.

If you are in the event of an object that has been dragged to the window, then you can modify its properties using Me.PropertyName. Otherwise you would use the object name.

Paul Lefebvre
  • 6,253
  • 3
  • 28
  • 36
  • Thanks for iterating through controls, that's a huge help! – Leticia Meyer Mar 03 '11 at 01:37
  • However, when I try setting Me.isFlamingo I get this error: `Code, Window1.ShowTextBtn.Action, line 1, This method or property does not exist, Me.isFlamingo = "Hello" ` – Leticia Meyer Mar 03 '11 at 01:37
  • Still doesn't work. It gives me an error if I'm trying to set a property that isn't standard. It's a push button, and if I try and set a custom property, it doesn't work. – Leticia Meyer Mar 03 '11 at 02:36
  • A PushButton cannot have a custom property. You'll have to subclass it first and then use the subclass on the window. How are you adding the "custom property"? – Paul Lefebvre Mar 03 '11 at 02:40
  • Just with a PushButton.isFlamingo – Leticia Meyer Mar 03 '11 at 03:00
  • You can't just reference a property without first adding it! You need to subclass PushButton. Create a new class (call it FlamingoPushButton) and set its Super to PushButton. Open FlamingoPushButton and add a Boolean property called isFlamingo. Now on your Window, drag FlamingoPushButton to your Window (select Project Controls from the dropdown in order to see it). Now that you're using a control that has the property, you'll be able to access it as FlamingoPushButton1.isFlamingo. – Paul Lefebvre Mar 03 '11 at 03:03