Page 1 of 1

Question about (x)include files

Posted: Wed Aug 21, 2019 2:56 pm
by captain_skank
Hi all,

I've used includes forever and have only now run into this problem and wonder if their is a workaround :

So normally i use

Code: Select all

XIncludeFile "C:\Users\MY_USERNAME\Documents\MY_PROJECT\_includes\MY_INCLUDE.pbi"
Recently I wanted to do some work on another pc but had to change all the xincludes because of the username, which is a pain.

The compiler doesn't like it if i put different username xincludes in a IF THEN ELSE or SELECT CASE scenario,
it also throws a hissy fit if the xinclude is on e network drive/share and you cant use variable in xincludes either.

I do want to keep my file structure in a specified users directory though.

Any help appreciated.

cheers

Re: Question about (x)include files

Posted: Wed Aug 21, 2019 3:24 pm
by Sirius-2337

Code: Select all

#MY_USERNAME = "user01"

XIncludeFile "C:\Users\" + #MY_USERNAME + "\Documents\MY_PROJECT\_includes\MY_INCLUDE.pbi"

;OR

XIncludeFile "\_includes\MY_INCLUDE.pbi"

;OR

#PC = 2

CompilerIf #PC = 1
  XIncludeFile "C:\Users\MY_USERNAME\Documents\MY_PROJECT\_includes\MY_INCLUDE.pbi"
CompilerElseIf #PC = 2
  XIncludeFile "C:\Users\ANOTHER_USERNAME\Documents\MY_PROJECT\_includes\MY_INCLUDE.pbi"
CompilerEndIf

Re: Question about (x)include files

Posted: Wed Aug 21, 2019 3:25 pm
by kenmo
Use relative paths

Code: Select all

; relative to the current file
XIncludeFile "myInclude.pbi"
XIncludeFile "includes/modules/myInclude2.pbi"
Or if you want to be able to instantly change your includes dir:

Code: Select all

#IncludesDir = "c:\Projects\MyIncludes\" ; change me!

XIncludeFile #IncludesDir + "myInclude.pbi"
XIncludeFile #IncludesDir + "includes/modules/myInclude2.pbi"
Note if you use the 2nd method, you can't Ctrl+DoubleClick to open an include file instantly.

Re: Question about (x)include files

Posted: Wed Aug 21, 2019 3:26 pm
by mk-soft
Normal Windows permission.

It is best to create your own folder (D:\Projects\Includes) where all users have access to it.

Re: Question about (x)include files

Posted: Thu Aug 22, 2019 9:21 am
by captain_skank
Thanks for the replies.

Looks like i'll have to follow mk-soft's advice and move my project or just the includes to a more generic location.

Re: Question about (x)include files

Posted: Thu Aug 22, 2019 10:21 am
by Marc56us

Code: Select all

XIncludeFile "C:\Users\MY_USERNAME\Documents\MY_PROJECT\_includes\MY_INCLUDE.pbi"
PB >= 5.60 :arrow: GetUserDirectory()

Code: Select all

XIncludeFile GetUserDirectory(#PB_Directory_Documents) + \MY_PROJECT\_includes\MY_INCLUDE.pbi"
See also: GetEnvironmentVariable() (Type SET in a CMD windows to see others variables)

Re: Question about (x)include files

Posted: Thu Aug 22, 2019 10:38 am
by #NULL
I you don't want to edit anything at all, you can try to use some compiler constants to define your project directories at compile time.

Code: Select all

;Debug #PB_Compiler_Home

#environment_1 = "/home/user/purebasic_571_lts/"
#project_1     = "/home/user/project/"

#environment_2 = "/home/userXYZ/purebasic_571_lts/"
#project_2     = "/home/userXYZ/project/"

CompilerIf #PB_Compiler_Home = #environment_1
    #project_path = #project_1
CompilerElseIf #PB_Compiler_Home = #environment_2
    #project_path = #project_2
;CompilerElse
;    #project_path = "<undefined>"
CompilerEndIf

CompilerIf Not Defined(project_path, #PB_Constant)
  CompilerError "Error: Could not determine #project_path."
CompilerEndIf

XIncludeFile #project_path + "inc/some.pbi"
You also could just set IncludePath instead of using a constant and use realtive paths in the include statements. This won't help you with permissions of course. It also requires the compiler home to be different on each of your systems, but you get the idea. Otherwise you could still do the same using the #PB_Compiler_File[...] constants by comparing them to hardcoded strings in your main file for example, so depending where/what the mainfile is you will include with different paths.

Re: Question about (x)include files

Posted: Thu Aug 22, 2019 10:41 am
by #NULL
@Marc56us
These are runtime functions and don't work at compile time, as is necessary for include statements.

Re: Question about (x)include files

Posted: Thu Aug 22, 2019 12:22 pm
by Joris

Code: Select all

IncludePath ...