Forum > Beginners

ActionList

(1/2) > >>

Weitentaaal:
Hello Guys :)

So lately i came to a point where i did a more complicated calculation.
I want my Programm to react to changes, did on the Form.

So the User has some Stuff on my Form he can choose then he clicks "Calculate" and the Results are returned. After that i changed my Button Color to green (yellow = not calculated / green = calculated). So now what i want to have is some Event or something else wich checks if the user changes something again, then the calculation is not valid anymore. So if the User doeas some changes then an Event should do some stuff.

Pseudo Code Example:

Function ClickCalculate

If calculation did go well
 Button --> green
else
Yellow


Function Event

If change some component wich has impact on calculation

Button again yellow (or just some signal to the user that the calculatoion is not valid anymore)

thanks in advance :)

Edit: It does not have to be an event .. just searching for a good solution.
   i got a solution (but  just not a very clean 1):

I hide somewhere a TEdit an use its OnChange event so i just change the caption from 0 = not calculated to 1 = calculated and the Event gets triggered

howardpc:
One solution would be to put an ActionList on your form, and define a new Action which is triggered by the appropriate user change(s).
Every action has an OnExecute event which you could use for the needed recalculation.

Weitentaaal:
Just Looked it up and yes ...that was what i need thanks:)

Is there somewhere a short example how to use it correctly ?

Edit: or even better: could some1 pls provide an Example with some components wich trigger the action liste when they change ?

Thanks in advice

Edit2: I did some Tests and came to the point to assign the action. not every component has a property "Action", so where do i put it when i have for example a TEdit ?
   I need something like If this field changes then do this and that

jamie:
You must be referring to TEDIT's ? they don't have a action property..

Each control that has a focus ability, meaning the receive keyboard input, has a onEnter and OnExit. those events get triggered when the control gains focus or looses it.

 So if the user is pressing a button to see the results then this would mean that control has gain focused and at which point you can change the color and when the OnExit fires, it looses focus and then you can change color again..

 During these events you can set some variable or what ever you need to do..

howardpc:

--- Quote from: jamie on June 04, 2021, 12:39:34 pm ---You must be referring to TEDIT's ? they don't have a action property..

--- End quote ---
All controls have a (public) Action property. However, not all controls publish this property, so not all controls allow you to set this property in the object inspector.

For controls such as edits that do not publish their Action property you have to set it in code if you wish to use it.

See the following example. It is rather contrived -- the same effect could easily be achieved without actions in this simple case, but it serves to demonstrate the capability of actions.
Actions are overkill for almost all simple programs. They only start to shine when you have complex apps with complicated GUI interactions and commands that might be be executed from various controls such as toolbuttons, menuitems, checkboxes radiobuttons and so on. Having a centralised action container in an actionlist then helps you separate the logic of checking for a change in a control or in data, from the logic of updating the state(s) of various related controls.

Navigation

[0] Message Index

[#] Next page

Go to full version