Search code examples
delphidelphi-xe6

How do I create a path in code to locate a file in a specific location? Delphi XE6?


What is the procedure or method add a path to a file in the {$I ...} line? I have a file that I want the compiler to be able to find.

For example, say I have downloaded a file named "abc.inc" that receives a file error as follows:

F1026 File not found: 'abc'

The file in code is something like this:

{$I abc.inc}

My question is how do you write a file path in code to a particular folder in my project?

For example, let's say my file "abc" is located this path: project\comps\jcl\abc.inc

How would I write in code {$I abc.inc} "is located in path comps\jcl\abc.inc ?

I think I know how {$I functions... How to add/include/incorporate "abc.inc" file into my project using code. How do I write a path in code?


Solution

  • The answer can be found in the documentation:

    If the filename does not specify a directory path, then, in addition to searching for the file in the same directory as the current module, Delphi searches in the directories specified in the Search path input box on the Delphi Compiler page of the Project > Options dialog box.

    This documentation text is vague at best. What actually happens if you specify a relative path, is that the path is taken to be relative to the file which contains the $INCLUDE directive.

    So if the file to be included is not in the same directory as the source file that is including it then your options are to:

    1. Specify the absolute path of the include file, or
    2. Specify the path of the include file, relative to the source file containing the $INCLUDE directive, or
    3. Add the directory containing the include file to the search path.