On Jan 27, 2007, at 10:37 PM, David Johnson wrote:
I have two related problems.
1. I am generating a control array on the fly with the following
code:
Sub AddRow()
Dim newControl as ControlClass
newControl = new ControlClass1 // clone the existing control
if (newControl <> nil) then
// initialize the new control //
end if
This code works only if it is a method of the window,
window1.Addrow. If this same method is placed in a module or in a
class, it generates a "This method or property does not exist"
compile error. I tried the following modification:
Sub AddRow()
Dim newControl as ControlClass
newControl = new window1.ControlClass1 // clone the existing
control
if (newControl <> nil) then
// initialize the new control //
end if
The error changed to: "This method requires more parameters than
were passed." The constructor for ControlClass does not take any
parameters.
If it is possible, how do I add controls to a control array from an
object other than the window?
It's logical that the method, AddRow, belong to the window. Another
object can tell the window to execute the method. You can include
parameters in the declaration of AddRow which will allow you to set
attributes in the call from the other object.
2. When it comes time to call the method from anotherControlClass,
the call is as follows:
window1.Addrow
This works, but I would like to localize the code so that
anotherControlClass does not need to know the name of its parent
window (so that anotherControlClass can be added to any window).
The following:
me.window.Addrow
window.Addrow
window(0).Addrow (the application has only one window)
all give the "This method or property does not exist" error.
The anotherControlClass.window property does access the ordinary
window items like .top or .visible, but it cannot access any
properties or methods that I have added to the window.
Is there a way to call a window method from another class without
hard-coding the window name?
To gain access to the members not included in Window class, the other
class needs a reference to the window instance which has been
dimensioned or cast to the class of the instance, or to an Interface
implemented by the instance's class in the case of methods. This
means, generally, that the window name, or the name of its superclass
if it has one, or its Interface if it implements one, is going to
appear in the other class somewhere, perhaps in a declaration or as
an IsA argument and/or a cast. For example, in the other class you
can declare a property of type MyCustomWindow, or you can have a
method which accepts a parameter of type MyCustomWindow, or you can
check a Window type using IsA to see if it is a MyCustomWindow and if
so call its methods.
Best,
Jack
_______________________________________________
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>