[Lazarus] How to find out why a unit is used in a project?

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] How to find out why a unit is used in a project?

Free Pascal - Lazarus mailing list
I am porting a Delphi application to Linux and as a stop I am first
doing it from Delphi to Lazarus/Fpc on Windows.

Now when I try to compile it throws an error inside a unit I did not
even know it used. And to further complicate the issue I cannot find a
reference to the unit in question when doing a search in the project
dir inside all pas files. This unit is not mentioned anywhere and
still causes a compile error due to a missing reference.

I tried Lazarus Find In Files and set it to search "all files in
project" and also search the project directory, but it comes up
empty-handed...

So now I wonder:
Is there a Lazarus tool to trace why the unit is referenced in the
first place? Is there such things as "chain of uses"?

The application I am porting is a client communications app that talks
to a service over TCP/IP.
That service app uses the unit that pos up as erroneous now, but it
should not be used by the client comm app at all.
So I need to find out why it does.

--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to find out why a unit is used in a project?

Free Pascal - Lazarus mailing list
Am 23.09.20 um 18:59 schrieb Bo Berglund via lazarus:

> I am porting a Delphi application to Linux and as a stop I am first
> doing it from Delphi to Lazarus/Fpc on Windows.
>
> Now when I try to compile it throws an error inside a unit I did not
> even know it used. And to further complicate the issue I cannot find a
> reference to the unit in question when doing a search in the project
> dir inside all pas files. This unit is not mentioned anywhere and
> still causes a compile error due to a missing reference.
>
> I tried Lazarus Find In Files and set it to search "all files in
> project" and also search the project directory, but it comes up
> empty-handed...
>
> So now I wonder:
> Is there a Lazarus tool to trace why the unit is referenced in the
> first place? Is there such things as "chain of uses"?
>
> The application I am porting is a client communications app that talks
> to a service over TCP/IP.
> That service app uses the unit that pos up as erroneous now, but it
> should not be used by the client comm app at all.
> So I need to find out why it does.
>

Perhaps it can be find in Projects properties?

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to find out why a unit is used in a project?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Wed, 23 Sep 2020 18:59:58 +0200
Bo Berglund via lazarus <[hidden email]> wrote:

>[...]
> Now when I try to compile it throws an error inside a unit I did not
> even know it used. And to further complicate the issue I cannot find a
> reference to the unit in question when doing a search in the project
> dir inside all pas files. This unit is not mentioned anywhere and
> still causes a compile error due to a missing reference.
>
> I tried Lazarus Find In Files and set it to search "all files in
> project" and also search the project directory, but it comes up
> empty-handed...
>
> So now I wonder:
> Is there a Lazarus tool to trace why the unit is referenced in the
> first place? Is there such things as "chain of uses"?

View / Unit Dependencies

Mattias
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to find out why a unit is used in a project?

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Wed, 23 Sep 2020 19:29:36 +0200, John Landmesser via lazarus
<[hidden email]> wrote:

>> So now I wonder:
>> Is there a Lazarus tool to trace why the unit is referenced in the
>> first place? Is there such things as "chain of uses"?
>>
>> The application I am porting is a client communications app that talks
>> to a service over TCP/IP.
>> That service app uses the unit that pos up as erroneous now, but it
>> should not be used by the client comm app at all.
>> So I need to find out why it does.
>>
>
>Perhaps it can be find in Projects properties?

Well, that only shows the units specifc to the application itself...

I figured out that the reason this unit was brought in was via another
unit that *is* used since it contains declarations of the different
data records and classes handled by the server and the client.

In this unit that extra unit is listed in uses since it contains stuff
needed by functions inside this unit itself (but not needed by the
client application).

So there seems to be a chain reaction concerning units involved in the
application....

--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to find out why a unit is used in a project?

Free Pascal - Lazarus mailing list
Bo Berglund via lazarus <[hidden email]> schrieb am Mi., 23. Sep. 2020, 21:13:
So there seems to be a chain reaction concerning units involved in the
application....

If course there is. That's how the unit system is supposed to work after all. 

Regards, 
Sven 

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to find out why a unit is used in a project?

Free Pascal - Lazarus mailing list
On Thu, 24 Sep 2020 07:53:24 +0200, Sven Barth via lazarus
<[hidden email]> wrote:

>Bo Berglund via lazarus <[hidden email]> schrieb am Mi., 23.
>Sep. 2020, 21:13:
>
>> So there seems to be a chain reaction concerning units involved in the
>> application....
>>
>
>If course there is. That's how the unit system is supposed to work after
>all.
>
Yes, I realize that now.

It means that the client even though it will not interface to the
hardware will have all of the code used to do that included in the
app, right?

The reason this was brought in is that the client app needs to know
the structure of the data on the server but not really the
implementatiuon on the server side inmcluding hardware interfacing
details...

Is it possible to have declaration of classes in one file and
implementation in another?

For example one file holding the declarations and another
implementations and then the client just uses the first whereas the
server uses both?

Maybe this is where you can use inc files?

Or I should just accept it and move on...


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to find out why a unit is used in a project?

Free Pascal - Lazarus mailing list
Bo Berglund via lazarus <[hidden email]> schrieb am Do., 24. Sep. 2020, 08:08:
On Thu, 24 Sep 2020 07:53:24 +0200, Sven Barth via lazarus
<[hidden email]> wrote:

>Bo Berglund via lazarus <[hidden email]> schrieb am Mi., 23.
>Sep. 2020, 21:13:
>
>> So there seems to be a chain reaction concerning units involved in the
>> application....
>>
>
>If course there is. That's how the unit system is supposed to work after
>all.
>
Yes, I realize that now.

It means that the client even though it will not interface to the
hardware will have all of the code used to do that included in the
app, right?

The compiler (and linker) only includes code that is used. Thus as long as you don't call the hardware functions anywhere in your program (this includes indirectly or through initialization/finalization sections) then the code won't be in the final binary either.

Regards, 
Sven 

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to find out why a unit is used in a project?

Free Pascal - Lazarus mailing list


On 2020/09/24 11:04, Sven Barth via lazarus wrote:
Bo Berglund via lazarus <[hidden email]> schrieb am Do., 24. Sep. 2020, 08:08:

>If course there is. That's how the unit system is supposed to work after
>all.
>
Yes, I realize that now.

It means that the client even though it will not interface to the
hardware will have all of the code used to do that included in the
app, right?

The compiler (and linker) only includes code that is used. Thus as long as you don't call the hardware functions anywhere in your program (this includes indirectly or through initialization/finalization sections) then the code won't be in the final binary either.

Regards, 
Sven


Sven, I believe Bo's problem is that even though he won't need the Code (which the linker/compiler will surely cleverly disregard), he also do not even wish to "need" the physical Unit files to be in view of the compiler - at least not the secondary-dependency units - when he references a unit file in which he only needs a few declarations visible.

Sadly Bo, the entire premise of the Unit system is that every dependency will be in view, the compiler cannot decide BEFORE compiling that it would or wouldn't need a unit which appears in a "unit" clause lower down the dependency tree. Consider that a used unit may well declare a global variable that overrides one from a higher-up unit, for instance. So even though the program has all the participating symbols at hand without looking at this depended unit with the override, it will produce a different program (than when that override IS considered) and so cannot simply decide to ignore/not require a unit preemptively before actually parsing the physical file.

All units you use, pluse every dependent unit they use, must be available and visible to the compiler. That rule is absolute.



--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to find out why a unit is used in a project?

Free Pascal - Lazarus mailing list
R.Smith via lazarus <[hidden email]> schrieb am Do., 24. Sep. 2020, 12:19:


On 2020/09/24 11:04, Sven Barth via lazarus wrote:
Bo Berglund via lazarus <[hidden email]> schrieb am Do., 24. Sep. 2020, 08:08:

>If course there is. That's how the unit system is supposed to work after
>all.
>
Yes, I realize that now.

It means that the client even though it will not interface to the
hardware will have all of the code used to do that included in the
app, right?

The compiler (and linker) only includes code that is used. Thus as long as you don't call the hardware functions anywhere in your program (this includes indirectly or through initialization/finalization sections) then the code won't be in the final binary either.

Regards, 
Sven


Sven, I believe Bo's problem is that even though he won't need the Code (which the linker/compiler will surely cleverly disregard), he also do not even wish to "need" the physical Unit files to be in view of the compiler - at least not the secondary-dependency units - when he references a unit file in which he only needs a few declarations visible.


Well, Bo could always split the data type declarations into a separate unit. 

Regards, 
Sven 

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to find out why a unit is used in a project?

Free Pascal - Lazarus mailing list
On Thu, 24 Sep 2020 14:22:13 +0200, Sven Barth via lazarus
<[hidden email]> wrote:

>Well, Bo could always split the data type declarations into a separate
>unit.

But I cannot wrap my head around this (constructed example):

interface

type
 TMyRecord = packed record
   Item1: word;
   Item2: Cardinal;
  end;


TMyController = class
  private
    FGPIO_driver: TIoDriver;
    FGpF: TIoPort;
    function CheckValidRelay(Relay: byte): boolean;
  public
    constructor Create;
    destructor Destroy; override;
    procedure ClearRelays;
    function PulseRelay(Relay: byte; PulseTime: LongWord): boolean;
    function RelayOff(Relay: byte): boolean;
    function RelayOn(Relay: byte): boolean;
    function RelayState(Relay: byte): boolean;
    procedure Delay(T: LongWord);
  end;

implementation
  ...All of the methods here...

AFAIK the records could be declared elsewhere but the objects not
since their methods, constructor, destructor etc reside in the same
file below implementation, right?

Just specifying a uses file with everything above the implementation
will not cut it, right?

But as I indicated I have just moved on and I am leaving this because
it seems to do more harm than good and is a lot of work too.


--
Bo Berglund
Developer in Sweden

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] How to find out why a unit is used in a project?

Free Pascal - Lazarus mailing list
Bo Berglund via lazarus <[hidden email]> schrieb am Do., 24. Sep. 2020, 15:22:
On Thu, 24 Sep 2020 14:22:13 +0200, Sven Barth via lazarus
<[hidden email]> wrote:

>Well, Bo could always split the data type declarations into a separate
>unit.

But I cannot wrap my head around this (constructed example):

interface

type
 TMyRecord = packed record
   Item1: word;
   Item2: Cardinal;
  end;


TMyController = class
  private
    FGPIO_driver: TIoDriver;
    FGpF: TIoPort;
    function CheckValidRelay(Relay: byte): boolean;
  public
    constructor Create;
    destructor Destroy; override;
    procedure ClearRelays;
    function PulseRelay(Relay: byte; PulseTime: LongWord): boolean;
    function RelayOff(Relay: byte): boolean;
    function RelayOn(Relay: byte): boolean;
    function RelayState(Relay: byte): boolean;
    procedure Delay(T: LongWord);
  end;

implementation
  ...All of the methods here...

AFAIK the records could be declared elsewhere but the objects not
since their methods, constructor, destructor etc reside in the same
file below implementation, right?

Would your code require the hypothetical TMyController or only the TMyRecord? If it only requires the later then you could indeed solve this by moving the record into a separate unit. If your code requires TMyController as well, then it can't be left out anyway (though the compiler will leave out any non-virtual method of that class which isn't used). 


Just specifying a uses file with everything above the implementation
will not cut it, right?

No, that will not help.

Regards, 
Sven 

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus