Hi,
REALbasic 2006r2 Commercial Pro for Macintosh
REALbasic 2006r2 Commercial Std for Windows
REALbasic 2006r2 Commercial Std for Linux
Mac OS X 10.4.6
Windows XP
Suse 10.1
Isn't my title funny ?
[a bit dark, but funny!]
OK, here's the challenge (question):
I want to use some controls that are on one window (Using Controls) from a
module (from a distant object).
The target window have 23 controls:
11 EditFields, 1 ListBox, 10 StaticText and one PushButton.
Since I have to use at two different places (or more ?) the same code to do the
same job, it is better to remove that code from the Window's DropObject Event
Handler and put it in a Module.
The original code to clears the Control (that holds data):
Dim w As Window1
// Get a reference to the target window
w = New Window1
// Delete the previous contents
w.LBFileName.DeleteAllRows
w.EFCharacter.Text = ""
w.EFStory.Text = ""
w.EFScript.Text = ""
w.EFArt.Text = ""
w.EFKind.Text = ""
w.EFNumber.Text = ""
w.EFLength.Text = ""
w.EFDateStart.Text = ""
w.EFDateEnd.Text = ""
w.EFComments.Text = ""
Replaced by:
// Start by removing the previous contents
Dim CtrlCnt As Integer
Dim CtrlIdx As Integer
// Get the number of controls in the target Window
CtrlCnt = Window1.ControlCount - 1 // 0-based
// Loop thru the Controls and clears their contents
For CtrlIdx = 0 to CtrlCnt
If Window1.Control(CtrlIdx) IsA ListBox Then
// Clears the ListBox contents (only one ListBox)
ListBox(Window1.Control(CtrlIdx)).DeleteAllRows
ElseIf Window1.Control(CtrlIdx) IsA EditField Then
// Clears the EditField contents (for all EditFields)
EditField(Window1.Control(CtrlIdx)).Text = ""
End If
If UserCancelled Then Exit // Avoid Infinite Loop
Next
Actually, I read the data from a text file - some (10) lines goes to the
EditFields - and in a loop I populate the ListBox using absolute reference like:
<Remember the earlier code:>
Dim w As Window1
// Get a reference to the target window
w = New Window1
</Remember the earlier code>
Window1.EditField1.Text = textTIS.ReadLine
Window1.EditField2.Text = textTIS.ReadLine
Window1.EditField3.Text = textTIS.ReadLine
While Not textTIS.EOF
// Fills the ListBox from here
// Actual code removed
If UserCancelled Then Exit // Avoid Infinite Loop
Wend
Here comes the question:
I have 10 EditFields (this may vary in the future, who knows) and one ListBox, I
do not think that it is reasonable - good programming skill - to pass so many
references from the window to the Module Method.
Must I use the Cast trick - as I already do earlier - assuming as I already do
that the data _AND_ the Control Order have a _fixed_ 'flow' (will always have
the same order in both the text file and in the Window) ?
Please share your input here.
TIA,
Emile
_______________________________________________
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>