B4J Question Changing the eventname

Firpas

Active Member
Licensed User
Longtime User
Hello everyone

Is it possible to change the Eventname to a view after initializing it?

Normally in Sub Process_Globals the views that are going to be used in a form are defined (Textfields, Checkboxes, Comboboxes, ...)

Then in Sub AppStart (Form1 As Form, Args () As String) these views are initialized

MainForm.RootPane.LoadLayout ("Main") 'Load the layout file.

In this same method or in another, values will be given to textfield.tex, checbox.checked, ... etc. and this triggers the _TextChanged, _CheckedChange, etc. events that are defined in the class.

In order to avoid this, it could be good to initialize the views with eventname "", then assign the values to the properties text, checked, etc ... in this way the corresponding events would not be triggered and finally change the eventname "" by the corresponding in each case, and from that moment the events would be triggered.

Thanks for your cooperation
 
Just use a flag to track if the event is being fired by the "initial values" or not
 
Upvote 0
Hi Klaus,
I believe there are circumstances where the initial values aren't known at compile time. One case is data retrieved from an on-line service or a DB (local or external doesn't matter). So, imho, Cableguy's hint should suffice to solve OP's problem.
 
Upvote 0
Thank you all for your answers

use a flag to track if the event is being fired ...
It is an arduous task in addition to having to declare a global variable to collect the value or initial state of each view. There is also the difficulty of when you have to declare these views at runtime.

It is possible to declare all the views disabled in the designer so as not to trigger events, and once the corresponding properties have been assigned, activate them so that the events begin to trigger with the intervention of the user.
In fact this is a common practice in VB.Net but here it does not work correctly. In Vb.Net you can also remove handler an add handler.

For example in B4J this code triggers the _TextChanged evnt

Code: Copy
    Dim TextField1 As TextField
    TextField1.Initialize("TextField1")
    TextField1.Enabled = False
    TextField1.Text = "Some text"
    MainForm.RootPane.AddNode(TextField1, 10, 10, 100, 30)
    TextField1.Enabled = True

Sub TextField1_TextChanged (Old As String, New As String)
    Log("Old = " & Old)
    Log("New = " & New)
End Sub

Any idea ?
 
Upvote 0
It is possible to declare all the views disabled in the designer so as not to trigger events, and once the corresponding properties have been assigned, activate them so that the events begin to trigger with the intervention of the user.
you are free to ignore events if the requirements are not met.
It is not possible o change it at runtime.
 
Upvote 0
Old will equal "" if you add text to a textfield for the first time.
 
Upvote 0
I want ignore events only temporaly
Then the questions: when, why and how !?

You need to define the conditions when you want to ignore events.
As alreday suggested, define a global variable which reflects your requirements and act accrording to these conditions.
There is no general method to do this, as far as I know.
 
Upvote 0
As I suggested, set a flag, start a timer while you load/populate your initial values and in the tick event change your flag status so that it reflects your actual status
 
Upvote 0
you can catch the event once with wait for and nothing happens :)
use at your own risk.

i guess the root of your problem is that you change other ui elements in the change event
and then u have a domino effect.

Code: Copy
Sub Test
 
    Dim TextField1 As TextField
    TextField1.Initialize("TextField1")
    TextField1.Enabled = False
    TextField1.Text = "Invisible Change Event"
    Wait For TextField1_TextChanged(Old As String, New As String)
    MainForm.RootPane.AddNode(TextField1, 10, 10, 100, 30)
    'TextField1.Text = "Visible Change Event"
    TextField1.Enabled = True
 
End Sub

Sub TextField1_TextChanged (Old As String, New As String)
    Log("Old = " & Old)
    Log("New = " & New)
End Sub
 
Last edited:
Upvote 0
Back
Top