Lazarus

Programming => General => Topic started by: AsleyCruz on February 26, 2020, 10:27:55 pm

Title: (SOLVED) Clean the project - remove unnecessary components
Post by: AsleyCruz on February 26, 2020, 10:27:55 pm
Hi team

We sometimes add components in our project, but in the end, we decided not to use that component.
But we still have its unit in "Uses" section or in the section "Required packages" and this makes the .exe size increase.

Is there a way to remove automatically that unnecessary components that our project does not need?

Thanks in advance.
Title: Re: Clean the project - remove unnecessary components
Post by: lucamar on February 26, 2020, 10:41:35 pm
To delete the references to the units in the uses clause(s), use the menu "Source->Refactoring->Unused units", which can also be accessed through the pop-up menu of the editor.

If that doesn't work then you'll have to do it by hand, deleting the offending references in the source. Note that hovering the mouse pointer over a control/component class will tell you (most of the time) in which unit it's declared. Also, compiling after each deletion will allow you to ascertain whether the deleted unit is still "used", somehow, in your code (look for "Identifier not found" errors).

Package dependencies can be deleted in the Project Inspector (menu Project->Project Inspector). Again. compiling after each deletion will tell you whether the dependency was really needed.

HTH!
Title: Re: Clean the project - remove unnecessary components
Post by: marcov on February 26, 2020, 10:41:50 pm
No, this is not really easy to do components might be added runtime.
Title: Re: Clean the project - remove unnecessary components
Post by: howardpc on February 26, 2020, 10:44:06 pm
There is no way to remove unnecessary components, except manual deletion.
 Only the developer knows whether a component is needed. If it is not needed, just delete it.

How can the IDE read your mind to know whether you need it or not?
Title: Re: Clean the project - remove unnecessary components
Post by: jamie on February 26, 2020, 10:58:37 pm
Deleting it via the OI does work but you still have the units behind in the uses list however, the warnings tell you that it's not being used and thus it should be ok.
Title: Re: Clean the project - remove unnecessary components
Post by: AsleyCruz on February 27, 2020, 01:16:04 am
To delete the references to the units in the uses clause(s), use the menu "Source->Refactoring->Unused units", which can also be accessed through the pop-up menu of the editor.

If that doesn't work then you'll have to do it by hand, deleting the offending references in the source. Note that hovering the mouse pointer over a control/component class will tell you (most of the time) in which unit it's declared. Also, compiling after each deletion will allow you to ascertain whether the deleted unit is still "used", somehow, in your code (look for "Identifier not found" errors).

Package dependencies can be deleted in the Project Inspector (menu Project->Project Inspector). Again. compiling after each deletion will tell you whether the dependency was really needed.

HTH!

Thanks a lot guys
This helped me a lot... with maybe 1MB of my project...

Code: Text  [Select][+][-]
  1. To delete the references to the units in the uses clause(s), use the menu "Source->Refactoring->Unused units"

TinyPortal © 2005-2018