I don’t know how to solve a little problem, so I’m asking someone who knows more than me.
I have a window that calls a method of a class by passing it parameters; this method creates a recordset and processes it.
I need to make the window display a couple of data present in each record that the class processes.
I would say that the class method should raise an event, but I don’t know how to do it.
I’m inclined to think that there are no asynchronous things in your process.
So maybe just (algorithm, you need to write things):
Var obj As New MyClassWithRecords
obj.DoTheProcessing()
If obj.MoveToFirstRecord() Then // False if fail
Do
DisplayThisRecord(obj.GetCurrentRecord())
Loop Until Not obj.MoveToNextRecord() // True if could move to next
End
use selectsql to insert data because it can use the returning data (rowset)
you could give the method the output listbox to insert data direct. (OOP)
or collect data first (object array) and then display it.
or give the method the window and call a method from there to add/display this data of interest.
if you have multiple windows with the same need, add/create a interface (Display Method) to the windows.
The class method runs a loop reading a recordset, and for each record processed it must be able to notify the window about the record it has just processed, and the window must notify the user. The class could do this by raising an event that the window should catch, but I don’t know how to do it.
Thank you all for your posts!
Tim’s solution is what was on my mind, and it works very well!
What I was missing was dragging the class onto the window: I had defined the class instance as a property of the window, so I couldn’t handle the event defined in the parent class.
Another great thing to add to my Xojo knowledge!
Thanks again to all of you: you are awesome!
You could, using AddHandler if you wanted to. You just need to be sure to use RemoveHandler later when destroying the instance or the Window to prevent leaks.
Hi Greg, I’m having some trouble developing what you suggested.
I have the class clsCommTestate in which I inserted an Event Definition ElaborataCarpetta(Anno As Integer, NumCarp As Integer).
In a window I defined oCommTes As clsCommTestate as window property, and in the Opening of the window I instantiated the class with oCommTes = New clsCommTestate.
Now I would like to execute AddHandler, but I can’t indicate the event ElaborataCarpetta, because it doesn’t exist in my instance.
What should I do?
Thanks!
Maybe I need to drag the class onto the window, as Tim suggested?
In this case it is easier to write the code directly in the event rather than using AddHandler.