Hi,
REALbasic 2006r3 Commercial Pro
Mac OS X 10.4.7
In the REALbasic User’s Guide (pdf), page 472, why the example below:
For i = 1 to Self.ControlCount //number of controls in window
If Self.control(i) IsA EditField then
fieldname = EditField(control(i)).DataField //cast it
//the text property assigned to the contents of that field
fieldContents = EditField(control(i)).text //cast the control as an
EditField
r.column(fieldname)= fieldContents
end if
next
does not save a reference of the EditField and use that reference instead of
"casting" two times ?
Dim MyEF As EditField
Dim CtrlCnt As Integer
Dim CtrlIdx As Integer
// Get the number of controls in window
CtrlCnt = Self.ControlCount - 1 // Window.Control is 0-based
// Scan the controls
For CtrlIdx = 0 To CtrlCnt
// Is this Control an EditField ?
If Self.Control(CtrlIdx) IsA EditField Then
// Cast the Control and save the reference in myEF
MyEF = EditField(Control(CtrlIdx))
// Get the name
FieldName = MyEF.DataField
// Get the Text Property assigned to the contents of that field
FieldContents = MyEF.Text
// Continue...
r.Column(FieldName) = FieldContents
End If
// Avoid Infinite Loop
If UserCancelled Then Exit // ... the loop if Command-. or Ctrl+.
Next
Read note [*] below
I am also horrified that in the 2006 edition of the REALbasic User’s Guide,
one trains the newbie to use that bad habbit:
For i = 1 to Self.ControlCount //number of controls in window
REMEMBER: Self.ControlCount is computed each time the loop... loops. OK, we will
have less than 30 Controls in windows, most of teh time far less than that, so
if we talks about spend time, we will talks about some Ticks, certainly less
than one Tick.
BUT: John Newbie will read that, think this is a good programming practice and
remember to absolutely use that in its programs... After all, REAL Software use
it in its Reference Manuals...
Emile
Note [*]: It's funny, that code compiles fine even when no EditField exists in
the window it resides. But if you fire that code, you got an OutOfBounds...
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>