how to add textChanged event to textBox control at runtime

Discussion in 'Questions (Windows Mobile)' started by Gorazd, Jun 16, 2009.

  1. Gorazd

    Gorazd New Member Licensed User

    Hello!

    I'd like to add event TextChanged to Object(Door library) object at runtime
    like in following example:

    Code:
    numberObj.New1(False)
    numberObj.FromControl(
    "number")
    numberEvt.New1(numberObj.value,
    "TextChanged")
    I tried with following code but it doesn't work:

    Code:
    ctrl="number2"
    AddObject (ctrl&
    "_obj""Object")
    Control(ctrl&"_obj").New1(False)
    Control(ctrl&"_obj").FromControl(ctrl)
    AddEvent(ctrl&
    "_obj.value",TextChanged, "NumberEvent_NewEvent")
    My intent is to add event textChanged to some textBox control at runtime.

    Can anybody help me, please

    Best regards

    Gorazd
     
  2. derez

    derez Expert Licensed User

    I'm not sure about the code, but this seems wrong:

    ctrl & "_obj.value"

    Try writing:

    control( ctrl & "_obj" , "object").value

    so it will be

    AddEvent( control( ctrl & "_obj" , "object").value , TextChanged, "NumberEvent_NewEvent")
     
  3. agraham

    agraham Expert Licensed User

    Like this
    Code:
    Sub App_Start
       Form1.Show
       
       
    ' Specify the control and the Event
       Ctrl = "TextBox1"
       
    Event = "TextChanged"
       
       
    ' Names for the new Object and Event
       CtrlObj = Ctrl & "_obj"
       CtrlEvt = Ctrl & 
    "_evt"
       
       
    ' Add a new object and associate it with the control
       AddObject (CtrlObj, "Object")
       
    Control(CtrlObj).New1(False)
       
    Control(CtrlObj).FromControl(ctrl)   

       
    ' Add a new Event object
       AddObject (CtrlEvt, "Event")
       
       
    ' Make the new Event a TextChanged event of the specified control
       ' This makes the TextChanged event of the control call the NewEvent event handler of the Event Object
       Control(CtrlEvt).New1(Control(CtrlObj).value, Event)
       
       
    ' Now make the NewEvent handler of the Event object call our event Sub.
       AddEvent(CtrlEvt, NewEvent, "Some_NewEvent")   

    End Sub

    Sub Some_NewEvent
       
    Msgbox("Some_NewEvent!")
    End Sub
    EDIT :- If you want to optimise compile the above you will need to edit the Control(...) statements to include the object types, Object or Event as appropriate.
     
    Last edited: Jun 16, 2009
  4. Gorazd

    Gorazd New Member Licensed User

    Thank you for your help.
    Now the code compiles and executes correctly.
    I missed two steps and misunderstood AddEvent command.
    Guess I miss some basic understanding of objects and events.:)

    Best regards

    Gorazd
     
  5. HARRY

    HARRY Active Member Licensed User

    Hallo Andrew,

    The sample code you gave does not work anymore (with 6.90?) while compiling for the device. I understand that the keyword Control has been deprecated, but I can't get it working now.

    I want to raise an event when a form is activated.

    Could you help me (one more time)?

    Harry
     
  6. sitajony

    sitajony Active Member Licensed User

    Hi, Hum TextChanged it's the same think that:
    Code:
    value=""

    Sub TextBox1_GotFocus
      value=TextBox1.Text
    end sub

    Sub TextBox1_LostFocus
      
    if not(value=TextBox1.Text) Then
        
    'Do something...
      End If
    End Sub
    Tell me if I'm Out Subject ;)
     
  7. agraham

    agraham Expert Licensed User

    You are "Out Subject"! :). The TextChanged event is raised every time the contents of the Text property change - not on LostFocus.

    Here's the previous code amended for v6.90 new syntax.
    Code:
    Sub App_Start
       Form1.Show
       
       
    ' Specify the control and the Event
       Ctrl = "TextBox1"
       ChangedEvent = 
    "TextChanged"
       
       
    ' Names for the new Object and Event
       CtrlObj = Ctrl & "_obj"
       CtrlEvt = Ctrl & 
    "_evt"
       
       
    ' Add a new object and associate it with the control
       AddObject (CtrlObj, "Object")
       Object(CtrlObj).New1(
    False)
       Object(CtrlObj).FromControl(ctrl)   

       
    ' Add a new Event object
       AddObject (CtrlEvt, "Event")
       
       
    ' Make the new Event a TextChanged event of the specified control
       ' This makes the TextChanged event of the control call the NewEvent event handler of the Event Object
       Event(CtrlEvt).New1(Object(CtrlObj).value, ChangedEvent)
       
       
    ' Now make the NewEvent handler of the Event object call our event Sub.
       AddEvent(CtrlEvt, NewEvent, "Some_NewEvent")   

    End Sub

    Sub Some_NewEvent
       
    Msgbox("Some_NewEvent!")
    End Sub
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice