Jump to content
Larry Hengen

Is there a way to get the IDE to generate interface methods

Recommended Posts

Please forgive the question if it's seems obvious.  I have always Implemented an interface in a new class the hard way in Delphi by copying the interface members from the interface into the class and using class completion to generate the methods.  Is there a way to do so in the Delphi IDE without such a manual brute force technique?  I don't see anything in the Refactor menu and invoking Class Completion on a class with an unimplemented interface does nothing.  Is this only possible through a third party IDE add-in like MMX? 

 

I would think that in the age of interface based development, making it easy to define and implement interfaces would be a well supported use case within the IDE, so I am assuming I just don't know of it. It's a snap in Visual Studio.

Share this post


Link to post

Put the cursor within the class and press Ctrl+Space. This will give you a list of all interface methods. Iirc this also supports multi select.

Unfortunately the method declarations will always be added as public which is usually not what you want.

Edited by dummzeuch
  • Thanks 2

Share this post


Link to post
3 hours ago, dummzeuch said:

Unfortunately the method declarations will always be added as public which is usually not what you want.

And they fully qualify every type -.-

Share this post


Link to post

Thanks all for the replies!

 

I tried it out and it certainly beats copy/pasting from the interface.  This feature has been unknown to me until now.  I wish I had asked earlier.  Is there a similar way to implement an event handler when you don't know what the declaration is?  I usually end up drilling into, or using GExperts to search through, the vendor source code (if I have it).  Sometimes I have to write down the handler definition given by code insight, and then code the handler manually.  I assume there is probably a better way?

Share this post


Link to post

Inside the Code Explorer drag the interface onto the class name. MMX will open a dialog where you can see which methods will be implemented and which method sigatures might possibly get corrected because of changes in the interface definition.

EDIT: MMX will show the implemented interfaces below the class name. You can repeat the drag operation to update the class definition whenever the interface definition changes.

Edited by jottkaerr
  • Thanks 1

Share this post


Link to post
On 9/24/2019 at 8:26 AM, dummzeuch said:

Put the cursor within the class and press Ctrl+Space. This will give you a list of all interface methods. Iirc this also supports multi select.

Unfortunately the method declarations will always be added as public which is usually not what you want.

Does this support copying to the clipboard?  In Delphi XE it doesn't.

Share this post


Link to post
10 minutes ago, A.M. Hoornweg said:

Does this support copying to the clipboard?  In Delphi XE it doesn't.

I am not sure if the quote is actually the intended one, as Thomas description is not related to the clipboard at all.

 

In case you are referring to the MMX solution, make sure that you copy the interface (not its methods) from the contents list of the MMX Code Explorer window and paste it into the members list of the target class.

  • 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

×