Please someone explain this to me

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

Please someone explain this to me

Anthony Walter-3
I really don't like the include files with Lazarus and Free Pascal for the following reason:

How the **** am I supposed to know which file is including an include file?

Often times I am trying to find a function or class or some other identifier and I search files on disk for the name. Then it turns out the identifier is in some include file. Often the include file doesn't have any information to which unit it belongs and I am then forced to search further for other files which reference the include file. It's a mess.

In this issue http://mantis.freepascal.org/view.php?id=29599 Juha is asking how I was able to compile my patch without using the dynlibs unit. Sure enough I am not using the dynlibs unit, but on my system it compiles. When I control click the LoadLibrary identifier in my Unity patch, Lazarus brings up an include file with LoadLibtary declared, but I have no idea which unit is including it (remember I'm not using unit dynlibs).

So my question is, how do the rest of you deal with include files and locating the unit including them? And also can this system for including files be better implemented, for example by some IDE feature to figure this out for you and displaying the "owning" units.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Ralf Quint
On 2/9/2016 2:58 PM, Anthony Walter wrote:

> I really don't like the include files with Lazarus and Free Pascal for
> the following reason:
>
> How the **** am I supposed to know which file is including an include
> file?
>
> Often times I am trying to find a function or class or some other
> identifier and I search files on disk for the name. Then it turns out
> the identifier is in some include file. Often the include file doesn't
> have any information to which unit it belongs and I am then forced to
> search further for other files which reference the include file. It's
> a mess.
>
> In this issue http://mantis.freepascal.org/view.php?id=29599 Juha is
> asking how I was able to compile my patch without using the dynlibs
> unit. Sure enough I am not using the dynlibs unit, but on my system it
> compiles. When I control click the LoadLibrary identifier in my Unity
> patch, Lazarus brings up an include file with LoadLibtary declared,
> but I have no idea which unit is including it (remember I'm not using
> unit dynlibs).
>
> So my question is, how do the rest of you deal with include files and
> locating the unit including them? And also can this system for
> including files be better implemented, for example by some IDE feature
> to figure this out for you and displaying the "owning" units.
>
It seems to me as if you are approaching the problem from the wrong end,
which has your search end up in the include file instead of the
associated unit.

I had only a cursory look at your problem and it seems you just went
straight to the Linux related LoadLibrary function instead of indeed
using the dynlibs unit, which exist for the purpose of creating a
cross-platform way of using dynamically loaded libraries (hence the
name). You seem to  just ignore the fact that this is a highly OS
depended functionality and seemed to have taken interest only in the
Linux related part of what ever your initial problem is/was and used
that portion of the code in stead of making use of the dynlibs unit.

Ralf

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Anthony Walter-3
Ralf,

A couple of points.

1) As I explained there are times when I, and probably other people as well, need to find the declaration of a function, constant, record, or some other identifier. We may not know if the function even exists or has been declared in Pascal, for example when attempting to use specific APIs dependent on some external library. In those case my approach is often to search (grep) files under either my lazarus or fpc folder. If there is some better way please to find these identifiers, which are not in the help systems, please let me know.

Continuing, when I do locate these files often they are in include files, and it's at that point where the problem I described occurs. That is, trying to locate what file is including the ".inc" file so that I can add the necessary package and units to my project.

And ...

2) In your cursory look you mention I seemed to have only taken interest in a Linux related part. Well the patch I've created deals with Ubuntu's new Unity application indicators which prevent TTrayIcon from working. This is a problem specific to Ubuntu Unity (a Linux distribution), so of course the fix is going to be highly OS dependent. 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

vojtech.cihak
In reply to this post by Anthony Walter-3

There exists IDE directive

{%MainUnit ***.pas}

and include files should contain it. But I don't know if there are more units containing the same include file.

 

V.

______________________________________________________________
> Od: Anthony Walter <[hidden email]>
> Komu: "FPC-Pascal users discussions" <[hidden email]>
> Datum: 10.02.2016 00:06
> Předmět: [fpc-pascal] Please someone explain this to me
>

I really don't like the include files with Lazarus and Free Pascal for the following reason:
How the **** am I supposed to know which file is including an include file?
Often times I am trying to find a function or class or some other identifier and I search files on disk for the name. Then it turns out the identifier is in some include file. Often the include file doesn't have any information to which unit it belongs and I am then forced to search further for other files which reference the include file. It's a mess.
In this issue http://mantis.freepascal.org/view.php?id=29599 Juha is asking how I was able to compile my patch without using the dynlibs unit. Sure enough I am not using the dynlibs unit, but on my system it compiles. When I control click the LoadLibrary identifier in my Unity patch, Lazarus brings up an include file with LoadLibtary declared, but I have no idea which unit is including it (remember I'm not using unit dynlibs).
So my question is, how do the rest of you deal with include files and locating the unit including them? And also can this system for including files be better implemented, for example by some IDE feature to figure this out for you and displaying the "owning" units.



----------

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Sven Barth-2
In reply to this post by Ralf Quint

Am 10.02.2016 00:32 schrieb "Ralf Quint" <[hidden email]>:
>
> On 2/9/2016 2:58 PM, Anthony Walter wrote:
>>
>> I really don't like the include files with Lazarus and Free Pascal for the following reason:
>>
>> How the **** am I supposed to know which file is including an include file?
>>
>> Often times I am trying to find a function or class or some other identifier and I search files on disk for the name. Then it turns out the identifier is in some include file. Often the include file doesn't have any information to which unit it belongs and I am then forced to search further for other files which reference the include file. It's a mess.
>>
>> In this issue http://mantis.freepascal.org/view.php?id=29599 Juha is asking how I was able to compile my patch without using the dynlibs unit. Sure enough I am not using the dynlibs unit, but on my system it compiles. When I control click the LoadLibrary identifier in my Unity patch, Lazarus brings up an include file with LoadLibtary declared, but I have no idea which unit is including it (remember I'm not using unit dynlibs).
>>
>> So my question is, how do the rest of you deal with include files and locating the unit including them? And also can this system for including files be better implemented, for example by some IDE feature to figure this out for you and displaying the "owning" units.
>>
> It seems to me as if you are approaching the problem from the wrong end, which has your search end up in the include file instead of the associated unit.
>
> I had only a cursory look at your problem and it seems you just went straight to the Linux related LoadLibrary function instead of indeed using the dynlibs unit, which exist for the purpose of creating a cross-platform way of using dynamically loaded libraries (hence the name). You seem to  just ignore the fact that this is a highly OS depended functionality and seemed to have taken interest only in the Linux related part of what ever your initial problem is/was and used that portion of the code in stead of making use of the dynlibs unit.

Since 3.0.0 the DynLibs unit is only needed to initialize the dynamic library manager on platforms that don't have it in System (like Windows does). The related functions (e.g. LoadLibrary() ) have been moved to System as that functionality is required both for dynamic packages and delay loading. (Note: DynLibs still contains the functions, but they forward to the System ones).

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Anthony Walter-3
Sven,

Thanks for clarifying that particular issue. I assumed the functions had been moved to System but wasn't sure when.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Marc Santhoff-2
In reply to this post by Anthony Walter-3
On Di, 2016-02-09 at 18:46 -0500, Anthony Walter wrote:

> Ralf,
>
> A couple of points.
>
> 1) As I explained there are times when I, and probably other people as
> well, need to find the declaration of a function, constant, record, or some
> other identifier. We may not know if the function even exists or has been
> declared in Pascal, for example when attempting to use specific APIs
> dependent on some external library. In those case my approach is often to
> search (grep) files under either my lazarus or fpc folder. If there is some
> better way please to find these identifiers, which are not in the help
> systems, please let me know.

If you are using Lazarus:
- put the cursor inside the indentifier
- use right mouse key
- klick "find declaration of ..." or use key combination ALT-UpArrow

When on the console, I don't know. Searching would have to be done with
the OS and target cpu in mind, because in many cases that's what
switches included files. I did not try yet.

There hsa been a thread on the lazaurs list lately, handling the topic
of "navigating huge files" or similar. There is a lot of info about what
lazarus can do for you regarding search and navigation.

--
Marc Santhoff <[hidden email]>

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Graeme Geldenhuys-6
In reply to this post by vojtech.cihak
On 2016-02-10 00:01, Vojtěch Čihák wrote:
> There exists IDE directive
> {%MainUnit ***.pas}
> and include files should contain it.

That is not an include file requirement, plus that functionality is a
Lazarus-only trick. Any other editor and the FPC compiler sees that as a
simple code comment. Plus not all include files include that information
- in fact most I've seen don't.

Regards,
  - Graeme -

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Anthony Walter-3
In reply to this post by Marc Santhoff-2
Marc,

Your suggestions only work if a unit declaring the function is in your uses clauses. In the scenario I described that is clearly not the case. 

Additionally, and in a different scenario, when the identifier IS defined and several units are in the uses clause the goto declaration can jump to an include file without any information pertaining to which of the units is including the file. To the best of my knowledge there isn't a straight forward way to figure this out, unless the author add that text to a comment in the included file which often is not the case.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Sven Barth-2

Am 10.02.2016 11:11 schrieb "Anthony Walter" <[hidden email]>:
>
> Marc,
>
> Your suggestions only work if a unit declaring the function is in your uses clauses. In the scenario I described that is clearly not the case. 
>
> Additionally, and in a different scenario, when the identifier IS defined and several units are in the uses clause the goto declaration can jump to an include file without any information pertaining to which of the units is including the file. To the best of my knowledge there isn't a straight forward way to figure this out, unless the author add that text to a comment in the included file which often is not the case.

You can alternatively simply try F1, at least as long as you know the identifier. That will either take you to the help or it will open the Code Browser which will search for the identifier.

This was also discussed in the following thread on the Lazarus mailing list: http://lists.lazarus.freepascal.org/pipermail/lazarus/2014-February/085631.html

Maybe this will help in at least some situations :)

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Marc Santhoff-2
In reply to this post by Anthony Walter-3
On Mi, 2016-02-10 at 05:10 -0500, Anthony Walter wrote:

> Marc,
>
> Your suggestions only work if a unit declaring the function is in your uses
> clauses. In the scenario I described that is clearly not the case.
>
> Additionally, and in a different scenario, when the identifier IS defined
> and several units are in the uses clause the goto declaration can jump to
> an include file without any information pertaining to which of the units is
> including the file. To the best of my knowledge there isn't a straight
> forward way to figure this out, unless the author add that text to a
> comment in the included file which often is not the case.

What use case do you plan to handle?

If things are so weird as they are reagrding your requirements then
build up a search index, there are many crawlers, search engines and the
like available.

--
Marc Santhoff <[hidden email]>

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

leledumbo
Administrator
In reply to this post by Anthony Walter-3
> So my question is, how do the rest of you deal with include files and locating the unit including them?

I don't know what "deal" here refers to, so I can't answer that. I seldom use include files except when I have to deal with what the compiler/rtl face: platform dependent implementation of certain API in a platform independent unit. Sometimes I use it to have multiple classes in the same unit but I want each class to be in their own (include) file. Condition compilation is used to have interface and implementation in one file and is included twice in each respective section in the unit.

I use grep to locate the units including them (the directive is either {$I or {$INCLUDE, no other possibilites), nothing special or complex.

> And also can this system for including files be better implemented, for example by some IDE feature to figure this out for you and displaying the "owning" units.

For IDE, it's up to them of course. For instance, Lazarus uses its own codetools for source navigation, nothing from the compiler, if that's what you mean. It already indexes identifiers where they reside, it won't be difficult to index all {$I and {$INCLUDE as well. It's just since include files may be included by more than one files, the navigation must be altered somehow.
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Juha Manninen
In reply to this post by vojtech.cihak
On Wed, Feb 10, 2016 at 2:01 AM, Vojtěch Čihák <[hidden email]> wrote:
> There exists IDE directive
>
> {%MainUnit ***.pas}
>
> and include files should contain it.

Yes, that is the solution for Anthony's problem. Most include files
used by LCL units have it but FPC libraries may not.
When the directive is set, Lazarus IDE always knows how to jump
between interface in Pascal unit and implementation in an include
file.
The {%...} directive is a comment in other contexts and can be used safely.

> But I don't know if there are more units containing the same include file.

When a big Pascal unit is split into include files then an include
file is referred from one place only.
The directive is not meant for generic include files.

The original question about dynlibs remains. I understood with FPC 3.0
it is not needed but I could not compile without it.
This has nothing to do with cross-platform code. I am testing with
Xubuntu + GTK2 as the code is part of LCL-GTK2.
Actually I still have the RC1 version here:
 $ fpc
 Free Pascal Compiler version 3.0.0rc1 [2015/08/07] for x86_64
 ...
Could there be such a difference between RC1 and the release?
Anyway, I added dynlibs there. It is needed at least by FPC 2.6.4
which we still support for some time.
Ubuntu people, please test the Unity TTrayIcon feature. I have only
tested it does not break LCL-GTK2 in other systems. I will install
Ubuntu + Unity soon.

Juha
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Sven Barth-2

Am 10.02.2016 14:09 schrieb "Juha Manninen" <[hidden email]>:
>
> On Wed, Feb 10, 2016 at 2:01 AM, Vojtěch Čihák <[hidden email]> wrote:
> > There exists IDE directive
> >
> > {%MainUnit ***.pas}
> >
> > and include files should contain it.
>
> Yes, that is the solution for Anthony's problem. Most include files
> used by LCL units have it but FPC libraries may not.
> When the directive is set, Lazarus IDE always knows how to jump
> between interface in Pascal unit and implementation in an include
> file.
> The {%...} directive is a comment in other contexts and can be used safely.

What about include files included by other include files?

> > But I don't know if there are more units containing the same include file.
>
> When a big Pascal unit is split into include files then an include
> file is referred from one place only.
> The directive is not meant for generic include files.
>
> The original question about dynlibs remains. I understood with FPC 3.0
> it is not needed but I could not compile without it.
> This has nothing to do with cross-platform code. I am testing with
> Xubuntu + GTK2 as the code is part of LCL-GTK2.
> Actually I still have the RC1 version here:
>  $ fpc
>  Free Pascal Compiler version 3.0.0rc1 [2015/08/07] for x86_64
>  ...
> Could there be such a difference between RC1 and the release?
> Anyway, I added dynlibs there. It is needed at least by FPC 2.6.4
> which we still support for some time.
> Ubuntu people, please test the Unity TTrayIcon feature. I have only
> tested it does not break LCL-GTK2 in other systems. I will install
> Ubuntu + Unity soon.

I must check whether I had done that change before or after the branch...
On non-Windows systems you'll need to include dynlibs at least in the main project anyway as it is needed to initialize the library manager (just like cthreads and cwstring).

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Marco van de Voort
In reply to this post by Juha Manninen
In our previous episode, Juha Manninen said:
[ Charset UTF-8 unsupported, converting... ]
> On Wed, Feb 10, 2016 at 2:01 AM, Vojt?ch ?ih?k <[hidden email]> wrote:
> > There exists IDE directive
> >
> > {%MainUnit ***.pas}
> >
> > and include files should contain it.
>
> Yes, that is the solution for Anthony's problem. Most include files
> used by LCL units have it but FPC libraries may not.

I think it would be good to add that to most FPC inc files in rtl and fcl
too.

Most usage is straightforward, and can be solved using the directive. Some,
like ptypes.inc are more complicated.

I'll see if I can add some directives in the coming weeks.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Juha Manninen
In reply to this post by Sven Barth-2
On Wed, Feb 10, 2016 at 4:09 PM, Sven Barth <[hidden email]> wrote:
> What about include files included by other include files?

Ok, that is a nasty situation. I think it should be avoided.

Juha
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Michael Van Canneyt


On Wed, 10 Feb 2016, Juha Manninen wrote:

> On Wed, Feb 10, 2016 at 4:09 PM, Sven Barth <[hidden email]> wrote:
>> What about include files included by other include files?
>
> Ok, that is a nasty situation. I think it should be avoided.

Happens regularly in the RTL units, though.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Sven Barth-2
In reply to this post by Juha Manninen

Am 10.02.2016 15:55 schrieb "Juha Manninen" <[hidden email]>:
>
> On Wed, Feb 10, 2016 at 4:09 PM, Sven Barth <[hidden email]> wrote:
> > What about include files included by other include files?
>
> Ok, that is a nasty situation. I think it should be avoided.

Welcome to the RTL. ;)

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Anthony Walter-3
Thanks everyone for taking notice in the include file problem. I'm note sure about other people, but to me its a problem that sometimes limits me from following the source code. Ideally there should be one file per unit with an interface section and an implementation section and no include files, but I can understand how the multi-platform features of FPC and Lazarus necessitate using include files. 

I think the thing is I can't help but feel there should be a better system for organizing implementations for different systems. For example, many units use include file in their interface sections. Is that really necessary and what does that achieve other than making it more difficult to understand what's being declared? And could the IDE be enhanced to should which unit is ultimately including a file? Obviously the CodeTools already knows, it was able to deduce the identifier exists and that it has a declaration by looking through the units in the uses clause in the current unit. Couldn't something therefore display the unit name in IDE, possibly in the include file's source code tab (e.g. system.pas - dynlibh.inc)?

Thanks for considering this as an issue.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Please someone explain this to me

Michael Van Canneyt


On Wed, 10 Feb 2016, Anthony Walter wrote:

> Thanks everyone for taking notice in the include file problem. I'm note
> sure about other people, but to me its a problem that sometimes limits me
> from following the source code. Ideally there should be one file per unit
> with an interface section and an implementation section and no include
> files, but I can understand how the multi-platform features of FPC and
> Lazarus necessitate using include files.

You just need to look at the system or sysutils units from recent delphis to
see why include files are the better option, if you consider that FPC has
far more platforms to support.

That said, the MainUnit directive is easily added to the sources.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
123