Recent

Author Topic: [SOLVED] {$I or #I  (Read 2787 times)

WickedDum

  • Full Member
  • ***
  • Posts: 211
[SOLVED] {$I or #I
« on: September 06, 2016, 07:00:05 am »
Good evening!!

I have been reading until my eyes are tired... :'(

I am trying to compile an old Pascal file.  It's fun! :D   Until it wasn't.  In the olden days, I had a file that contained the VARs and CONSTs that I used in all of my programs.  I am trying to do it again.

I tried to figure out the directories that are in the Tools-Options-Environment-Files page.  I can't find how to include it in the reference book Lazarus - the complete guide or in the Lazarus help files (http://wiki.freepascal.org/IDE_Window:_Compiler_Options.

I did find it online in the FPC Programmer's Guide http://lazarus-ccr.sourceforge.net/fpcdoc/prog/progsu37.html#x44-420001.1.37.  It told me it would work ..but I could not tell if it did or not.  I don't think it used the file because I have a lot of 'Error:Identifier not found "...".

1.  How do I include it?
2.  How can I tell if the compiler even included it?
3.  Does #I still work or has it been deprecated?
4.  Should I just make it into a unit and go from there?

Example:
Code: Pascal  [Select][+][-]
  1. INTERFACE
  2.  
  3. Uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  4.  
  5. {$I ALLVARS.PAS }
  6.  
  7. var
  8.   char_str_flag,
  9.   star_comment_flag,
  10.   brace_comment_flag : boolean;
  11.  
  12. IMPLEMENTATION        

The most frustrating part of this whole thing is that I cannot tell if the compiler read it at all!

One project in the future is to make the look and feel of all of my programs the same.  Is it recommended that it should be coded in its own unit, too?

Thanks for your time!!
« Last Edit: September 08, 2016, 09:25:24 pm by WickedDum »
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: {$I or #I
« Reply #1 on: September 06, 2016, 07:29:40 am »
Quote
1.  How do I include it?
Using {$I filename} or {$INCLUDE filename}

Quote
2.  How can I tell if the compiler even included it?
If the compiler is unable to locate your include file it will usually generate a fatal compilation error, for which the message can be found in your compiler message output window (or on the prompt in case you compile from shell).

Quote
3.  Does #I still work or has it been deprecated?
Never heard of such a thing so probably not (but do note that i am terrible at remembering such things from the past).

Quote
4.  Should I just make it into a unit and go from there?
With regards to your problems with including a file, no. With regards to coding style, perhaps yes :-) What do you actually want to achieve with that include file ?

You are probably having problems somewhere else as your error messages seem to suggest (that of missing identifiers).

Are you sure that all the declarations inside your include file "ALLVARS.PAS" are correct ?
« Last Edit: September 06, 2016, 09:01:49 am by molly »

Thaddy

  • Hero Member
  • *****
  • Posts: 10568
Re: {$I or #I
« Reply #2 on: September 06, 2016, 12:24:28 pm »
Ad 3: that never worked except in GNU pascal as far as I know. It has never been part of any true pascal syntax, but rather implementation specifics. (nothing wrong with that)

In general most of the relics that are part of the official language still work: Like escaping with e.g. ^M.

WickedDum

  • Full Member
  • ***
  • Posts: 211
Re: {$I or #I
« Reply #3 on: September 07, 2016, 07:23:27 pm »
Thank you for your info!!

I searched through a lot of old code looking for the #I.  Guess I was just getting my languages mixed up.  Got it:  $I.

As for 'missing identifiers', yep, that's cause the include file is not there.

No news is good news?  I guess if the compiler doesn't tell me it couldn't find it, then it included it.

From my original post:
4.  Should I just make it into a unit and go from there?
With regards to your problems with including a file, no. With regards to coding style, perhaps yes :-) What do you actually want to achieve with that include file ?
Include File #1:  Many of the vars and const, not to mention procedures/functions, that I have used in the past to make coding consistent therefore less errors.  It's also simpler and quicker.
Include File #2:  The look and feel...consistent layout, operation, color scheme...

I feel that including those types of files is all-around more efficient.

Are you sure that all the declarations inside your include file "ALLVARS.PAS" are correct?
The declarations are perfect (no pride of ownership there!!).  No, not at all.  That's why I am going through and trying to include it.  If I miss a change between TP and FPC, the compiler will show me.  It loves telling me how stupid I am.

Thanks, again!
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

molly

  • Hero Member
  • *****
  • Posts: 2345
Re: {$I or #I
« Reply #4 on: September 08, 2016, 08:34:41 am »
Quote
As for 'missing identifiers', yep, that's cause the include file is not there.
I can only judge based on the example code that you pasted and, that gives no reason whatsoever for missing identifiers.

Quote
No news is good news?  I guess if the compiler doesn't tell me it couldn't find it, then it included it.
That is correct. As long as the tax-collector does not come banging on your door, you are good to go  :D

Quote
Include File #1:  Many of the vars and const, not to mention procedures/functions, that I have used in the past to make coding consistent therefore less errors.  It's also simpler and quicker
When you use an editor like lazarus, i would disagree with things being simpler. Include files are much harder to maintain.

If you have build your own library of useful (and reusable) functions it is often much more efficient to put them inside a unit (and make that become part of a (custom) fpc or lazarus package that you can use for every other project).

Of course if those things you mention are heavily tied to a specific unit/form, then i might be inclined to agree with what you wrote but, then i would just put them where they belong: inside the unit (of the form).

Much easier to navigate with a source-browser  ;)

What i often do is create a globals.pas (or something similar) unit for a project. Easy to maintain and handle. Of course there might be situations where it is more comfortable to use include files but, since i avoid them, i've learned how to be able to stuff everything into units. Might perhaps be personal preference as well.


Quote
I feel that including those types of files is all-around more efficient.
Personally i have such bad experience with include-files with FPC/Lazarus, that i avoid them like the plague and use them as less as is humanly possible.

Other than that, there is not a sane word someone would be able to tell about what is wrong in your situation as there there is simply lacking vital information. In case you are not able to provide that information then try to compile with verbosity set to all, and read what the compiler is complaining about. The compiler output will be very specific   :)

WickedDum

  • Full Member
  • ***
  • Posts: 211
[SOLVED] Re: {$I or #I
« Reply #5 on: September 08, 2016, 09:25:08 pm »
I agree, Molly.  As I was going through old code, I saw that I did include the globals.pas as a unit.  :)

Thank you all for your help and assistance!!

I remain,
ME  :D
Practice Safe Computing!!

Intel i5-4460K @ 3.2GHz | Win8.1 64-bit | FPC: v3.0 | Lazarus:  v1.6.0

 

TinyPortal © 2005-2018