Jump to content
Ian Branch

Method Selection ability??

Recommended Posts

Hi Team,

During development/rework I often need to select a full procedure or function for delection or replacement.

Delphi doesn't seem to have the ability.

Is there an IDE plug-in that will allow me to select the current procedure in total?

I found in 'Select Current Methody Body' in CnPack but it literally only selects the body of the method.

 

Regards & TIA,

Ian

Share this post


Link to post

If you're using MMX (which I highly recommend), you can use the "Delete Entity..." feature which deletes the current entity your caret is on: interface, class, property, method, field, etc. Not sure if it's the default shortcut, but mine is "Ctrl+Shift+Delete".

 

For fun, here are my MMX usage statistics for features that have been used 1000+ times (Delete Entity is in top 3):

image.png.4596575b00a2fb07f177db1d3e6c60db.png
 

Share this post


Link to post

Tks havrlisan.

I found that one and at times it will be useful.

Sometimes I just want to select the method and comment it out while I try an alternative version of the method.

Share this post


Link to post
1 minute ago, Ian Branch said:

Sometimes I just want to select the method and comment it out while I try an alternative version of the method.

Even that is possible with MMX, with the feature called "Comment member(s)..." in the "Text Tools" group. I know I manually set the shortcut of that one to "Alt+Shift+X". With that one, you can even edit the "TODO" comment that gets added, in MMX > Properties >Editing (Pascal group), and there you'll see the setting "Text to insert when commenting entity" in the last section, "Insert Text When Commenting".

Share this post


Link to post

Tks.  Close ,but not quite.

If I comment a method with it, it also comments the declaration in the class. 😞

Share this post


Link to post
Just now, Ian Branch said:

Tks.  Close ,but not quite.

If I comment a method with it, it also comments the declaration in the class. 😞

I didn't realize you meant only the implementation. In that case, I'd use the plain simple line commenting:

  • Delphi has that feature set to shortcut "Ctrl+/", where / character is on numpad.
  • MMX has the feature "Toggle Comment Selection", which acts very similar. You can assign a custom shortcut to that one.
  • GExperts also has a similar feature; not a toggle comment, but comment and uncomment. You can find it under "Editor Experts", and assign a custom shortcut as well.

Share this post


Link to post

Tks.

ATT I manually select the whole method then use Ctrl-/.

My issue is that with large methods it would be easier if the method could be readily selected, rather than having to manually select from start to finish.

Share this post


Link to post
57 minutes ago, Ian Branch said:

My issue is that with large methods it would be easier if the method could be readily selected, rather than having to manually select from start to finish.

MMX has an action Select Method Body (under Text Tools...), although that spares the variable declarations before the begin. There is no shortcut by default, but that can be configured.

Share this post


Link to post

Hi Uwe,

Yes I have investigated that one, but I want the whole method, not just the body.

Share this post


Link to post

If I understand correctly, use this procedure:

  • collapse the entire method - the + sign at the beginning of the method
  • select the resulting line and you're done

Share this post


Link to post

Hi Stano,

If I collapse it and the ctrl-/ it comments the first line and opens the rest.

Share this post


Link to post

Of course, I got it mixed up. I meant copy Ctrl+C. That's not what you want. Sorry.

Share this post


Link to post

Just to make sure I understand correct: You want to comment the implementation of a method, but not the declaration?

6 hours ago, Ian Branch said:

During development/rework I often need to select a full procedure or function for delection or replacement.

In such a case I usually extract the current method with MMX into a new one. Let's assume the method is named MyMethod. Then I extract the content in question (can be the whole) into a new method MyMethodA. If configured accordingly that leaves a single call to MyMethodA in the body of MyMethod. Then I can either comment that call or replace it with another call to MyMethodB, which is implemented differently. 

 

This has the advantage that I can call either method depending on some condition or configuration setting to test the behavior without re-compiling.

  • Like 1

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

×