Jump to content
JonRobertson

"Auto complete used units" does not recognize units without unit scope.

Recommended Posts

I sent an email to support@mmx-delphi.de. I decided to post here in case someone knows a solution aside from turning off "Auto complete used units" under Pascal->Editing.

 

When adding an event, MMX does not recognize when the required unit is already in the uses clause without a unit scope.

 

For example, adding an event for TDataSet.OnNewRecord adds "Data.DB" to the uses clause, even though "DB" is already in the uses clause.

[MMX] FormUsers(12): Auto Completed uses clause. Added: Data.DB

On compile/build, this results in:

[dcc32 Error] E2004 Identifier redeclared: 'Data.DB'

This is a legacy project. Adding unit scopes to each unit reference is on the to-do list. I do feel this is a flaw in MMX that could be corrected if MMX can distinguish the unit scope from the unit name.

 

Jon

Share this post


Link to post
1 hour ago, JonRobertson said:

Adding unit scopes to each unit reference is on the to-do list.

You can have this for free:

  1. Open MMX properties and navigate to Pascal - Sorting
  2. Under Format unit uses clauses check Group and sort uses

Now when you format the uses clause (with Ctrl-Alt-U while the cursor is inside a uses clause) MMX does the following:

  • Resolve any unit aliases
  • Resolve all unit scope names
  • Group the units as configured (see below)
  • Compress and wrap each group according to the settings

The groups are configured per project in the MMX Project options setting. If the entry for Groups is cleared neither grouping nor sorting is done.

 

Also these Project options have an Auto Format checkbox, which when checked forces the uses clause formatting whenever MMX manipulates a uses clause. 

 

My personal preference would be to format the uses clauses without any other changes done to keep version control happy. This can be achieved by a command line tool available on GitHub: UsesCleaner

It provides almost the same functionality as MMX, but targets complete projects instead of single units.

 

  • Like 1

Share this post


Link to post

Thank you. I am still a new user to MMX and still exploring the options. Unfortunately I have not had time to read the user manual from cover to cover. :classic_wink:

 

I am also coming back to the Delphi community after being away (due to job availability) for a couple of years. So I have a little catching up to do. I have not come across UsesCleaner. That sounds like a huge time saver.

Share this post


Link to post
24 minutes ago, JonRobertson said:

I have not had time to read the user manual from cover to cover.

I'm afraid the user manual doesn't cover this feature.

Share this post


Link to post
On 11/8/2023 at 3:59 PM, Uwe Raabe said:

Now when you format the uses clause (with Ctrl-Alt-U while the cursor is inside a uses clause) MMX does the following:

  • Resolve any unit aliases
  • Resolve all unit scope names
  • Group the units as configured (see below)
  • Compress and wrap each group according to the settings

I must be doing something wrong. In MMX Properties, Pascal, Sorting, I enabled "Group and sort uses clauses". But Ctrl-Alt-U changes this

uses
  ShlObj, SysUtils, Windows;

to this

uses
  Winapi.ShlObj,
  SysUtils, Windows;

and I expected this

uses
  System.SysUtils,
  Winapi.ShlObj, Winapi.Windows;

This is using Delphi 11.3 and MMX 15.1.7 build 2567.

 

Thanks

Share this post


Link to post
Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi;Data.Win;System.Win

I recently started this position and inherited this project. At the time, was partially migrated from Delphi 7 to Delphi 10. I have not modified the Unit Scope Names in the project as I have not needed to.

Share this post


Link to post

Can you reproduce on a minimal project?

 

I just copied that uses clause into a fresh VCL project and everything works as expected.

Share this post


Link to post

I wanted to say that yesterday I took the time to configure MMX to group and sort uses clauses they way I wanted and it is working great.

 

I expect you hear this a lot, but thank you for your help and keeping MMX alive. I did not have the opportunity to use Code Explorer when it was a ModelMaker product. Yesterday I took the time to go through most of the options and will be changing my coding habits to take advantage of more MMX features. :classic_smile:

  • 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
×