Recent

Author Topic: New .inc file...  (Read 1670 times)

lastfreedom

  • Newbie
  • Posts: 3
New .inc file...
« on: February 16, 2020, 04:51:31 am »
Hello,

Having just downloaded the IDE and coming from a C++ / Java word (well, actually RPG3 > RPG400 > COBOL400 > Visual Basic > C++ (Visual and otherwise) > Java + Node (urrrgh) + TypeScript (yay!) + Python + and now Pascal (revisiting from college days and light Delphi experience)) I am somewhat stumped as to how to create a .inc file given the options available when I select File > New... In the resulting dialog, I see no option to create such a file (which I assume to be equivalent to a C / C++ .h file). Am I missing it or is it otherwise considered bad practice, in which case how does one keep interfaces separate to implementation (I'd rather relegate a discussion of the virtues of this to another thread if OK). Obviously I can create one using other means, but am curious.

Thanks,

Matthew

jamie

  • Hero Member
  • *****
  • Posts: 6129
Re: New .inc file...
« Reply #1 on: February 16, 2020, 05:00:57 am »
new TEXT file, and saveas  YourName.inc

The only true wisdom is knowing you know nothing

lastfreedom

  • Newbie
  • Posts: 3
Re: New .inc file...
« Reply #2 on: February 16, 2020, 09:14:46 am »
Thanks for the response. Yes, was worried that would be the case, the implication being that an .inc file is not a first class citizen in the Lazarus (or Free Pascal) world. I assume another way to create an 'interface only' type would just to have a strawman / vinalla implementation of it in a Unit file (whereas in Java on can have a single .java file with only an interface declared within it, no need for any implementation).

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: New .inc file...
« Reply #3 on: February 16, 2020, 10:02:12 am »
What you refer to is what we call units. Units are first class citizens. With a unit you can also just declare an interface without an actual implementation.
Code: Pascal  [Select][+][-]
  1. unit ifonly;
  2. interface
  3. // here you can simply declare, similar ro include files in other languages.
  4. // So enums, types, constants, records,  classes
  5. // if you do not implement, make sure - classes are abstract or mark everything as external if the implementation is elsewhere,.
  6. // see also the programmers guide, language reference guide and user manual.
  7. impementation
  8. // here you implement things if required
  9. end.

Note there is a distinction between an interface section of a unit: this provides a programming interface (API) for a unit whereas an interface type is a distinct pascal type just like in Java, CORBA of COM.
« Last Edit: February 16, 2020, 10:51:04 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: New .inc file...
« Reply #4 on: February 16, 2020, 11:04:57 am »
Am I missing it or is it otherwise considered bad practice, in which case how does one keep interfaces separate to implementation (I'd rather relegate a discussion of the virtues of this to another thread if OK).

It is indeed considered bad practice. There is a place for them (and Lazarus handles them much better than Delphi), but their use is different than headers in C++. In Object Pascal as Thaddy wrote we have the concept of units which is essentially a single compilation module (similar to a *.cpp file in C++). Unlike C++ or Java however we have a distinction between interface and implementation through the syntax of a unit (as Thaddy showed as well). And the compiler makes heavy use of this: Instead of including a *.inc file as you'd do with a header in C++ you add the units you want to the uses-clause of your program or unit and all identifiers in the interface-section of the unit will be available in your program/unit as well. Name conflicts are no problem as you can always use UnitName.Identifier to identify them if there is the need to (otherwise the identifier from the unit added last wins). See also here and here.

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: New .inc file...
« Reply #5 on: February 16, 2020, 12:00:35 pm »
I have a question - pure curiosity; no immediate use - about the *.inc (understood that adding "uses *.pas" is more canonical outside the compiler code and the LCL, FCL, ... frameworks).

Is it possible to use them as "Callback" left to the discretion of each user (in the sense of "someone other than me, will tell what is the called code later, after the compilation", like the Windows's Enumxyz callbacks, whose results are sent back by Windows to the calling program).

I'm explaining: it's a common practice in Php to call in a framework a function hypothetically present, if its signature will exist, ie if the hypothetical function has been created and coded in the same namespace as its research, by the user of the framework.
I know that there is a Pascal code interpreter (I don't know it :-[ ).
Has anyone ever seen a fully integrated Pascal solution like this (if so, where is there an example?): a compiled code including a Pascal interpreteur, and some Pascal Callbacks written in a text file like an *.inc ( no, no: I'm not completely off topic :D ) for example [✶]?


[✶] it could then be an interpreted function with normalized name \ signature, which would retrieve the normalized parameter values from a line in a text file -  function_Foo_code.inc , function_Foo_input_output.inc - and returns its result in an array in another line for example.
« Last Edit: February 16, 2020, 12:10:32 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: New .inc file...
« Reply #6 on: February 17, 2020, 09:08:29 am »
What you're asking for is essentially Pascal Script.

devEric69

  • Hero Member
  • *****
  • Posts: 648
Re: New .inc file...
« Reply #7 on: February 17, 2020, 09:22:46 am »
Indeed, thank you. I've read it, and this is a solution to my question: it can actually replace the command line call to a Php interpreter with its script to interpret.
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

lastfreedom

  • Newbie
  • Posts: 3
Re: New .inc file...
« Reply #8 on: February 18, 2020, 06:30:04 pm »
What you refer to is what we call units. Units are first class citizens. With a unit you can also just declare an interface without an actual implementation.
Code: Pascal  [Select][+][-]
  1. unit ifonly;
  2. interface
  3. // here you can simply declare, similar ro include files in other languages.
  4. // So enums, types, constants, records,  classes
  5. // if you do not implement, make sure - classes are abstract or mark everything as external if the implementation is elsewhere,.
  6. // see also the programmers guide, language reference guide and user manual.
  7. impementation
  8. // here you implement things if required
  9. end.

Note there is a distinction between an interface section of a unit: this provides a programming interface (API) for a unit whereas an interface type is a distinct pascal type just like in Java, CORBA of COM.

Thanks for that. It helped a lot.

 

TinyPortal © 2005-2018