Discussion:
window references
David Johnson
2007-01-28 06:37:33 UTC
Permalink
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?


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?


These are driving me crazy, so thank you in advance for any help you
can give.

RB5.5 Pro, MacOSX 10.3.9

Thanks,
David
CV
2007-01-28 21:59:02 UTC
Permalink
Post by David Johnson
I have two related problems.
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"
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.
Post by David Johnson
2. When it comes time to call the method from anotherControlClass,
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).
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
David Johnson
2007-01-30 02:53:51 UTC
Permalink
Message: 5
Subject: Re: window references
Date: Sun, 28 Jan 2007 13:59:02 -0800
Post by David Johnson
I have two related problems.
1. I am generating a control array on the fly with the following
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.
[snip]
Post by David Johnson
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.
So, the code that clones a control *must* be in a method of the
enclosing window. OK.

[snip]
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.
[snip]

So, for a class to access a custom window property or method, the
window name must be hard-coded *somewhere* in the class.

Thank you for clarifying these; I understand better now.

Thanks,
David

Loading...