Larry Hengen 39 Posted September 24, 2019 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
Jacek Laskowski 57 Posted September 24, 2019 Delphi is very backward when it comes to coding and refactoring support tools. 1 2 Share this post Link to post
dummzeuch 1505 Posted September 24, 2019 (edited) 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 September 24, 2019 by dummzeuch 2 Share this post Link to post
Stefan Glienke 2002 Posted September 24, 2019 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
Larry Hengen 39 Posted September 24, 2019 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
Stefan Glienke 2002 Posted September 24, 2019 (edited) I am almost sure MMX Code Explorer can handle both - but @Uwe Raabe certainly knows better. Edited September 24, 2019 by Stefan Glienke Share this post Link to post
jottkaerr 1 Posted September 26, 2019 (edited) 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 September 26, 2019 by jottkaerr 1 Share this post Link to post
A.M. Hoornweg 144 Posted October 10, 2019 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
Uwe Raabe 2057 Posted October 10, 2019 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. 1 Share this post Link to post