Jump to content
Didier Cabalé

"Add Method" (Ctrl+Alt+M) wrongly assigned to TForm

Recommended Posts

Posted (edited)

Here are the basic steps that show the problem

1. create a VCL project

2. on the TForm's TButton OnClick event, type the following:

procedure TForm1.Button1Click(Sender: TObject);
var
  lMyObject: TMyObject;
begin
  lMyObject := TMyObject.Create;
  lMyObject.DoIt;
end;

3. select the 'DoIt', and type Ctrl+Alt+M to invoke  adding a method for (obviously) TMyObject

4. state that the Add method form proposes a method adding for the TForm1, instead of for TMyObject2118096750_2021-04-0910_58_57-ClonedeW7Delphi1Running-OracleVMVirtualBox_1.thumb.png.4e2ebf7bd4599dbc3522d8dba3f34dd3.png

I actually wanted to get some other's feedbacks, before sending this to MMX support

 

Edited by Didier Cabalé

Share this post


Link to post
2 hours ago, Didier Cabalé said:

 adding a method for (obviously) TMyObject

Wrong Expectation! The method is (obviously) added to the currently selected object TForm1. Works as expected.

Share this post


Link to post
4 hours ago, Didier Cabalé said:

lMyObject.DoIt;

 

1. But DoIt is obviously a TMyObject method, not a TForm one.
2. If you stick on your point, then how do you add a TMyObject method on the fly?

Share this post


Link to post
5 minutes ago, Didier Cabalé said:

1. But DoIt is obviously a TMyObject method, not a TForm one.
2. If you stick on your point, then how do you add a TMyObject method on the fly?

You put your cursor in the TMyObject class, and then use Ctrl + Alt + M.

Share this post


Link to post

1. I understand now the logic.

2. However, this logic does not fit to the use-case I quoted. -> MMX could add an option of which class the method must be added to.

Thanks for your replies!

Share this post


Link to post
45 minutes ago, Didier Cabalé said:

1. I understand now the logic.

2. However, this logic does not fit to the use-case I quoted. -> MMX could add an option of which class the method must be added to.

Thanks for your replies!

Alternately, you might recognize that the use case you cited is not supported.

Share this post


Link to post
2 hours ago, Didier Cabalé said:

MMX could add an option of which class the method must be added to.

Adding a layer of action to achieve a goal is probably not well accepted by long time MMX users as it would break their work flow.

 

Even if such functionality would exist, which class should the method be added when DoIt is not declared in TMyObject, but in TMyBaseObject, which TMyObject is derived from?

 

Instead of asking for the target object each time, it is much simpler to Ctrl-Click on the TMyObject reference or even the DoIt reference in the code, which immediately selects the requested object on which the Add Method action then can be executed on.

  • Like 2

Share this post


Link to post
15 hours ago, Uwe Raabe said:

Adding a layer of action to achieve a goal is probably not well accepted by long time MMX users as it would break their work flow.

I totally agree.

 

15 hours ago, Uwe Raabe said:

Even if such functionality would exist, which class should the method be added when DoIt is not declared in TMyObject, but in TMyBaseObject, which TMyObject is derived from?

The same question does exist when you propose to add a method to TForm1. And in that case, you simply add it to TForm1, not to TForm, the TForm1 ancestor.
 

15 hours ago, Uwe Raabe said:

Instead of asking for the target object each time, it is much simpler to Ctrl-Click on the TMyObject reference or even the DoIt reference in the code, which immediately selects the requested object on which the Add Method action then can be executed on.

1. Ctrl-Click on the TMyObject, that selects TMyObject, makes you loose the fluidity of the change (helped with bookmark #7 and bookmark #9 when method added to TForm1)
2. Ctrl-Click on DoIt does not do anything, because it is not created yet.

Share this post


Link to post
1 hour ago, Didier Cabalé said:

Ctrl-Click on DoIt does not do anything, because it is not created yet.

OK, I didn't realize that DoIt doesn't exist.

 

MMX basically works on the current unit and the selected entity - property, method, class, module etc.

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
×