Recent

Author Topic: ActionList  (Read 1599 times)

Weitentaaal

  • Sr. Member
  • ****
  • Posts: 272
ActionList
« on: June 04, 2021, 07:43:51 am »
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
« Last Edit: June 04, 2021, 10:26:02 am by Weitentaaal »
Lazarus: 2.0.6 x86_64-win64-win32/win64
FPC-Version: 3.0.4
Compiler Version: 3.2.0

howardpc

  • Hero Member
  • *****
  • Posts: 3753
Re: Own Events / Custom OnChange Event
« Reply #1 on: June 04, 2021, 08:40:44 am »
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

  • Sr. Member
  • ****
  • Posts: 272
Re: Own Events / Custom OnChange Event
« Reply #2 on: June 04, 2021, 09:36:24 am »
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
« Last Edit: June 04, 2021, 10:29:37 am by Weitentaaal »
Lazarus: 2.0.6 x86_64-win64-win32/win64
FPC-Version: 3.0.4
Compiler Version: 3.2.0

jamie

  • Hero Member
  • *****
  • Posts: 4834
Re: ActionList
« Reply #3 on: June 04, 2021, 12:39:34 pm »
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..
The only true wisdom is knowing you know nothing

howardpc

  • Hero Member
  • *****
  • Posts: 3753
Re: ActionList
« Reply #4 on: June 05, 2021, 01:25:56 pm »
You must be referring to TEDIT's ? they don't have a action property..
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.
« Last Edit: June 05, 2021, 03:53:42 pm by howardpc »

Weitentaaal

  • Sr. Member
  • ****
  • Posts: 272
Re: ActionList
« Reply #5 on: June 07, 2021, 01:34:37 pm »
Thank u Guys for ur Reply's :)

The Example was realy helpfull but i didn't managed to Advance the small Programm to a multi use of TAction.

Question: How do i Use HandlesTarget and UpdateTarget correctly ?
               How do i advance this Programm to Multiuse ?

Edit : U just did what i wanted but in the wrong way. U check if 1 field is changed and then change color. I wanted for Example to check if 1 of those 3 fields changed and when it changed then it should recalculate the Result.

Thanks in advice
« Last Edit: June 07, 2021, 02:14:15 pm by Weitentaaal »
Lazarus: 2.0.6 x86_64-win64-win32/win64
FPC-Version: 3.0.4
Compiler Version: 3.2.0

howardpc

  • Hero Member
  • *****
  • Posts: 3753
Re: ActionList
« Reply #6 on: June 07, 2021, 05:04:26 pm »
Quote
Question: How do i Use HandlesTarget and UpdateTarget correctly ?
               How do i advance this Programm to Multiuse ?
It all depends on what your target control is, and what you want to do.
You can add several actions, each one triggered by a different event.

Quote
U just did what i wanted but in the wrong way. U check if 1 field is changed and then change color. I wanted for Example to check if 1 of those 3 fields changed and when it changed then it should recalculate the Result.
The example I gave did not check any fields. The change to the VolumeEdit.Value was set in the object inspector simply by assigning spinedit OnChange event handlers. This works without any actions at all.


Perhaps the attached slightly changed example is more helpful, where the relevant knock-on colour-change action is explicitly invoked using Action.Execute in the event handler.

You can monitor three disparate control's properties changing by creating three actions, one of which you associate with each control. Is this what you mean by multi-use?
« Last Edit: June 07, 2021, 05:07:11 pm by howardpc »

wp

  • Hero Member
  • *****
  • Posts: 8731
Re: ActionList
« Reply #7 on: June 07, 2021, 05:44:43 pm »
Maybe you should read Brian Long's great article "Actions, Action Lists And Action Managers" (http://blong.com/Articles/Actions/Actions.htm). It's about Delphi, but everything - except for the ActionManager - is valid for Lazarus, too.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Weitentaaal

  • Sr. Member
  • ****
  • Posts: 272
Re: ActionList
« Reply #8 on: June 08, 2021, 07:44:30 am »
 
Maybe you should read Brian Long's great article "Actions, Action Lists And Action Managers" (http://blong.com/Articles/Actions/Actions.htm). It's about Delphi, but everything - except for the ActionManager - is valid for Lazarus, too.


I Will Definitely have a Look at it thank you :)

Quote
Question: How do i Use HandlesTarget and UpdateTarget correctly ?
               How do i advance this Programm to Multiuse ?
It all depends on what your target control is, and what you want to do.
You can add several actions, each one triggered by a different event.

Quote
U just did what i wanted but in the wrong way. U check if 1 field is changed and then change color. I wanted for Example to check if 1 of those 3 fields changed and when it changed then it should recalculate the Result.
The example I gave did not check any fields. The change to the VolumeEdit.Value was set in the object inspector simply by assigning spinedit OnChange event handlers. This works without any actions at all.


Perhaps the attached slightly changed example is more helpful, where the relevant knock-on colour-change action is explicitly invoked using Action.Execute in the event handler.

You can monitor three disparate control's properties changing by creating three actions, one of which you associate with each control. Is this what you mean by multi-use?

Goal : I was looking for some central control wich does lock some components after clicking a button and then check if an update happend in some other fields. IF an update happend then the the disabled controls should be enabled again and the Calculation is not on valid anymore and u have to press button again if u want to continue with ur calculation.

Thanks for the sample Programm ... i was looking for something like this .. a simple how to use Programm because i do not know how to use Actions.

But with both of ur Reply's i can work. Thank u Guys :)
« Last Edit: June 08, 2021, 07:56:06 am by Weitentaaal »
Lazarus: 2.0.6 x86_64-win64-win32/win64
FPC-Version: 3.0.4
Compiler Version: 3.2.0

 

TinyPortal © 2005-2018