Jump to content
Stano

Format uses clause

Recommended Posts

49 minutes ago, TheDelphiCoder said:

This does NOT work for the Forms unit, it should become Vcl.Forms (in a VCL project, of course)!

Sorry, but I cannot reproduce here. Can you give an example for such a uses clause, please?

 

To be honest, I doubt that there is some wrong with the code. The algorithm tries to find a unit (like Sysutils or Forms) in the search path. If not found, it tries each entry in the Unit Scope Names.

 

That doesn't rule out any uncommon uses clause, so I would like to see an example showing that problem.

Share this post


Link to post

Here is an example:

uses
  Forms, Graphics,
  Vcl.Menus, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Controls, System.Classes, Dialogs, Windows, SysUtils;

becomes

uses
  System.Classes, System.SysUtils,
  Winapi.Windows,
  Vcl.Graphics, Vcl.Menus, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Controls, Vcl.Dialogs,
  Forms;

Use clause sorting is

System.Win;System;WinApi;Data;IBX;id*;Vcl

"Group and sort uses" is checked in the options

Share this post


Link to post

I copied the uses clause as well as the group/sort-order from your post into a fresh VCL forms unit and this is what I get:

uses
  System.Classes, System.SysUtils,
  Vcl.Forms, Vcl.Graphics, Vcl.Menus, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Controls, Vcl.Dialogs,
  Winapi.Windows;

 

Share this post


Link to post

I can confirm it works as intended in a new project! 👍

 

Do you have any ideas what could cause the behaviour I'm expieriencing in my project?

Share this post


Link to post
1 hour ago, TheDelphiCoder said:

Do you have any ideas what could cause the behaviour I'm expieriencing in my project?

Is that with all units of that project or only with some of them?

 

Anyway, the implementation is quite similar to my command line tool UsesCleaner. If you are curious and the problem persists with that you can debug it yourself without giving away your project sources.

Share this post


Link to post
7 hours ago, Uwe Raabe said:

Is that with all units of that project or only with some of them?

Only unit Forms is affected.

 

Thanks for the link, I'll have a closer look what is going on there!

Share this post


Link to post
26 minutes ago, TheDelphiCoder said:

Only unit Forms is affected.

Can you check if you have some file named Forms.pas or Forms.dcu anywhere in your search paths?

Share this post


Link to post
9 hours ago, Uwe Raabe said:

Can you check if you have some file named Forms.pas or Forms.dcu anywhere in your search paths?

A quick search revealed indeed a unit Forms.pas in the path C:\Program Files (x86)\CnPack\CnWizards\PSDecl\ !

But this this path seems not be included in the PATH nor the library path nor the search paths (global and project).

Share this post


Link to post

I found out what caused that issue! 🎉

The unit was declared only as "Forms" (not "Vcl.Forms") in the dpr file. As soon as I changed it to its fully qualified name there, the Vcl prefix got added to the Forms entry in another units uses clause when formatting it with MMX!

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
×