Jump to content
luciano_f

How to detect when a Form is active in Designer

Recommended Posts

How to detect when a Form is active in Designer
  
 Guys, I'm posting here because in this area I know that you are the experts in OTA
 
 I posted this topic in another area of the forum
https://en.delphipraxis.net/topic/10262-permanently-the-lock-controls-in-ide/
 
 When searching I found this link
https://www.gexperts.org/open-tools-api-faq/
 
 However, it does not have an example explaining how to register
 only that:
 IOTAModule.GetModuleFileEditor(0).AddNotifier

TMyFormNotifier = class(TNotifierObject, IOTANotifier, IOTAFormNotifier)
protected
  procedure FormActivated;
  procedure FormSaving;
  procedure ComponentRenamed(ComponentHandle: TOTAHandle;
      const OldName, NewName: string);
end;

 

 I want to detect when the forms are opened and check if the Menu
 EditLockControlsItem


 it is activated and if it is activated I deactivate it and activate it again so I don't have to keep every form I open performing this action.

Share this post


Link to post
1 hour ago, luciano_f said:

it is activated and if it is activated I deactivate it and activate it again so I don't have to keep every form I open performing this action.

Can you explain this in another way? It sounds very confusing.
 

Share this post


Link to post
15 minutes ago, Dave Nottage said:

Can you explain this in another way? It sounds very confusing.
 

Using the "Lock Controls" option in Delphi's "Edit" menu I can lock the components, but each Form I open I have to deactivate and activate.

This way, I want to create a BPL where I can detect when a form is opened and automatically perform the procedure for deactivating and activating the "Lock Controls" option

Share this post


Link to post
1 hour ago, luciano_f said:

but each Form I open I have to deactivate and activate

Just so I understand: why do you need to do this?

Share this post


Link to post
7 hours ago, Dave Nottage said:

Just so I understand: why do you need to do this?

Because I like to work with the controls locked so I don't accidentally click and move components unnecessarily

 

I've been working for a long time, always blocking the components.

But I'm tired of always having to deactivate and activate "Lock Controls" every time I open Form it.

Edited by luciano_f

Share this post


Link to post
1 hour ago, luciano_f said:

But I'm tired of always having to deactivate and activate "Lock Controls" every time I open Form it.

You know that the locked mechanism has nothing to do with the application you building, it is only for the designer at design time, and that is it, also closed forms and frames don't tend to move their dropped components around nor change the design.

The only way components move and resize is by your actions, unless there is a bug in the IDE, so locking components is rarely used, i use it once or twice per year may be for few minutes and i can do without it though.

Share this post


Link to post

I think you are looking for IDesignNotification / DesignerOpened in DesignIntf.pas

 

the menu item is EditLockControlsItem:TMenuItem on the main Form, and the action is EditLockControlsCommand:TAction

Edited by Attila Kovacs

Share this post


Link to post

Looks like "Lock Controls" in the Edit menu is an IDE wide setting that can be toggled on and off. However, it is bugged - the locked state is not applied to the design surfaces of forms created or opened after Lock Controls is toggled on - they have unlocked controls. This leaves us with a toggle that isn't consistently applied so users must toggle it off then back on to get it applied to all open forms. Same for opening a project - even with Lock Controls toggled on all forms are opened unlocked. 

 

I created a new ticket for it. There are other related tickets, but none specifically target the failure to apply the current setting when loading/creating forms. 

[RSP-42429] ON setting of Edit -> Lock Controls ignored by newly opened or created forms - Embarcadero Technologies

 

Share this post


Link to post
1 minute ago, Brian Evans said:

I created a new ticket for it

Thanks.. your ticket is the explanation I was looking for.

Share this post


Link to post
3 minutes ago, Brian Evans said:

Looks like "Lock Controls" in the Edit menu is an IDE wide setting that can be toggled on and off. However, it is bugged - the locked state is not applied to the design surfaces of forms created or opened after Lock Controls is toggled on - they have unlocked controls. This leaves us with a toggle that isn't consistently applied so users must toggle it off then back on to get it applied to all open forms. Same for opening a project - even with Lock Controls toggled on all forms are opened unlocked. 

 

I created a new ticket for it. There are other related tickets, but none specifically target the failure to apply the current setting when loading/creating forms. 

[RSP-42429] ON setting of Edit -> Lock Controls ignored by newly opened or created forms - Embarcadero Technologies

 

Exactly my friend, that's right.

However, I believe it is possible to solve this problem.

I need to know how to create a BPL where I can detect when a Form is opened or active

 

I need to know how to register this

TMyFormNotifier = class(TNotifierObject, IOTANotifier, IOTAFormNotifier)
protected
  procedure FormActivated;
  procedure FormSaving;
  procedure ComponentRenamed(ComponentHandle: TOTAHandle;
      const OldName, NewName: string);
end;

 

 

Share this post


Link to post
On 10/5/2023 at 8:50 AM, Brian Evans said:

Looks like "Lock Controls" in the Edit menu is an IDE wide setting that can be toggled on and off. However, it is bugged - the locked state is not applied to the design surfaces of forms created or opened after Lock Controls is toggled on - they have unlocked controls. This leaves us with a toggle that isn't consistently applied so users must toggle it off then back on to get it applied to all open forms. Same for opening a project - even with Lock Controls toggled on all forms are opened unlocked. 

 

I created a new ticket for it. There are other related tickets, but none specifically target the failure to apply the current setting when loading/creating forms. 

[RSP-42429] ON setting of Edit -> Lock Controls ignored by newly opened or created forms - Embarcadero Technologies

 

 

For those who want to fix the bug, the correction was made with CnPack
https://github.com/cnpack/cnwizards/issues/181

 

Edited by luciano_f

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
×