Jump to content
Sign in to follow this  
Stano

Custom component TAction (s) - OnExecute overide

Recommended Posts

I always create all Actions only once. They live during the life of the instance.

I define an OnExecute event in the component and, if necessary, at design time in the instance
I want this behavior on the runtime:

  • if the event is only in the component, it will not always exist, so it will be triggered
  • if the event is only in the instance, it will fire
  • if the event is in the component as well as in the instance, then the event in the instance is triggered first and the event in the component is called with inherited

Classic behavior

About component

  TjstVstDBNavigator = class(TCustomActionToolBar)
  strict private
    FAcnMan: TAcTionManager;

Current status

  • In the component, I assign an Action OnExecute to each. As a result
  • Logically, only the event in the component always fires
  • Event in the instance will never run
Edited by Stano

Share this post


Link to post

I did not write that events must have access to component fields. Otherwise they are worthless.

Share this post


Link to post

I found out it could also be a Button.OnClick. Which is easier.

Share this post


Link to post
5 hours ago, Stano said:

I want this behavior on the runtime:

  • if the event is only in the component, it will not always exist, so it will be triggered
  • if the event is only in the instance, it will fire
  • if the event is in the component as well as in the instance, then the event in the instance is triggered first and the event in the component is called with inherited

I cannot understand what you mean by event in component or instance. In fact I can't make any sense out of this. 

Share this post


Link to post

In component - code written hard during component design. E.g. DataSource.Post itself
In the instance - a component on the form and it is necessary to extend the event. E.g. for DataSource.Post do the data check first

Edited by Stano

Share this post


Link to post

I think I've found a solution

  TjstVstDBNavigator = class(TCustomActionToolBar)
  type
  Ta = class(TAction)
  private
    bb: TjstVstDBNavigator;
  public
    constructor Create(AOwner: TComponent); override;
  end;

constructor TjstVstDBNavigator.Ta.Create(AOwner: TComponent);
begin
  inherited;
  bb := TjstVstDBNavigator(Owner);
  bb.AcnMan;  // It knows AcnMan
end;

This is a principle. Now I can override the event. I believe it will work.

Share this post


Link to post

Premature joy. I forgot that OnExecute is a property!

Share this post


Link to post
8 minutes ago, Stano said:

Premature joy. I forgot that OnExecute is a property!

There is always a virtual DoXY behind the OnXY.

Share this post


Link to post

If he overrides it, will it work for me normally? That would make me very happy.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×