FormInForm and Eventhandling

Post

Posted
Rating:
#1 (In Topic #1044)
Trainee
Hi, I'd like to get userdefined events from an embedded form in its parent form like this:

Code

' Form1 (parent)
Public Sub Form_Open()
  Form2.Load(Me)
End

Public Sub Form2_AnyEvent(sData As String)
  Debug sData
End

' Form2 (embedded)
Event AnyEvent(Data As String)

Public Sub _new()
  Dim bResult As Boolean
  bResult = Raise AnyEvent("AnyData")
  If bResult Then Debug "canceled"
End

But that's not working. I know, the embedded Form keeps its own Observer, but shouldn't the parent receive those events? What's wrong in this code?

Thanks!
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
Its the ide sets up the observer for Form1 when it compiles/runs.

Because you add Form2 manually you'll need to set up your own observer.

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Form2.Load(Me)
  4.   Dim hObs As Observer = New Observer(Form2) As "Form2"
  5.  
  6.  
  7.  
I assume the above will work but I never really use Form.Load()

Or you can add Form2 to Form1 like this…

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Dim f2 As Form2
  4.   f2 = New Form2(Me) As "Form2"
  5.  
  6.  
  7.  

The f2 can be local and use Last in the events to refer to it.

Or make f2 public (and a better name)

Code (gambas)

  1. Private FForm2 As Form2
  2.  
  3. Public Sub Form_Open()
  4.  
  5.   FForm2 = New Form2(Me) As "Form2"
  6.  
  7.  
  8.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.