hi guys. I’m facing a problem that I never faced and have no ideia what’s going on. I have main window, that open a window, and for update some record of this listbox, I open another window. but when I open this window, the window that opens this window get duplicated. I have no ideia why. when i trace , after ends the opening event handlers, the windows that open this new is duplicated. I’m using shwomodal to open the windows.
Implicit instantiation?
I bet you somewhere have a reference to a certain window (WindowName.Open)
Set some breakpoints and Debug
Definitely Implicit instantiation.
Imagine you have a window named winMain in the project.
Somewhere you do
dim x as new winMain
x.show
Then you show the next window in response to a listbox event..
dim x2 as new winSecondary
x2.showmodal
Somewhere in winSecondary, you have code that says something like:
winMain.listbox1.listindex = 2
the winMain reference causes a second instance of winMain to appear.
The best way to handle this is to create a constructor method for winSecondary, which takes a parameter of type winMain
create the second window like this:
dim x2 as new winSecondary(self)
x2.showmodal
Set a property of the winSecondary window to be = that variable in the constructor.
Let’s call that property ‘winParent as winMain’
Then later , instead of winMain.listbox1.listindex = 2, you would do
winParent.listbox1.listindex = 2
and it will affect the already open window, not create a new one
Var wTemplatesUpdate As New TemplatesUpdate(self)
wTemplatesUpdate.ShowModal
I got an error when try to use the self
Templates.ButtonUpdateTemplate.Pressed, line 7
Too many arguments: got 1, expected only 0.
Var wTemplatesUpdate As New TemplatesUpdate(self)
This is because you didn’t implement all of the message above -
you did not create a new constructor which takes a parameter.
Add a property to the window, of the type of your main window
Add a constructor which takes the main window as a parameter:
I used global variables to get and update… I don’t have the problems with the windows. but tis guys.
You may be assigned a property of the window before “win.show”