XIncludeFile Literal String Limitation

Just starting out? Need help? Post your questions and find answers here.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

XIncludeFile Literal String Limitation

Post by Paul »

Is there any way to do this or is it a Feature Request ?

Code: Select all

XIncludeFile GetUserDirectory(#PB_Directory_AllUserData)+"MyFolder\MyData.pbi"
Image Image
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: XIncludeFile Literal String Limitation

Post by skywalk »

Not sure you can use a runtime function?
Make a compiler constant.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: XIncludeFile Literal String Limitation

Post by Little John »

Paul wrote:Is there any way to do this or is it a Feature Request ?

Code: Select all

XIncludeFile GetUserDirectory(#PB_Directory_AllUserData)+"MyFolder\MyData.pbi"
This is no "Literal String Limitation". GetUserDirectory() is a run time function.
The problem is, that the argument of XIncludeFile must be known already at compile time.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: XIncludeFile Literal String Limitation

Post by Paul »

Guess it will have to be a Feature Request then and function similar to a constant like #PB_Compiler_Home which retrieves the compiler home directory at compile time.
Something like using just #PB_Compiler_AllUserData would be retrieved and filled at compile time.
Image Image
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: XIncludeFile Literal String Limitation

Post by RASHAD »

Just a guess
It could be like IncludeBinary "filename" and the filename should be between quotes
Try

Code: Select all

SetCurrentDirectory(GetUserDirectory(#PB_Directory_AllUserData)+"MyFolder")
XIncludeFile "MyData.pbi"
Egypt my love
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1243
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: XIncludeFile Literal String Limitation

Post by Paul »

RASHAD wrote:Just a guess
It could be like IncludeBinary "filename" and the filename should be between quotes
Try

Code: Select all

SetCurrentDirectory(GetUserDirectory(#PB_Directory_AllUserData)+"MyFolder")
XIncludeFile "MyData.pbi"
It was worth a try but unfortunately it doesn't work.
Even though you set the Current Directory somewhere else, PB throws an error saying it can't find the file can't be found in the same folder that your .pb source code file is in.
Image Image
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: XIncludeFile Literal String Limitation

Post by Little John »

RASHAD wrote:Just a guess
It could be like IncludeBinary "filename" and the filename should be between quotes
Try

Code: Select all

SetCurrentDirectory(GetUserDirectory(#PB_Directory_AllUserData)+"MyFolder")
XIncludeFile "MyData.pbi"
:?:
THIS DOES NOT WORK.
see viewtopic.php?p=543138#p543138
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: XIncludeFile Literal String Limitation

Post by RASHAD »

Hi Paul
2 nd. round :)
Try

Code: Select all

CopyFile(GetUserDirectory(#PB_Directory_AllUserData)+"MyFolder\MyData.pbi",GetTemporaryDirectory()+"MyData.pbi")
XIncludeFile "MyData.pbi"
Egypt my love
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: XIncludeFile Literal String Limitation

Post by Little John »

Rashad,

all these trials by you don't make sense, since you obviously do not understand the difference between things that happen at compile time, and things that happen at runtime.
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: XIncludeFile Literal String Limitation

Post by Josh »

Little John wrote:all these trials by you don't make sense, since you obviously do not understand the difference between things that happen at compile time, and things that happen at runtime.
GetUserDirectory() is needed at compile time, but not at runtime, because there is no (X)IncludeFile in the final exe anymore. The usage of GetUserDirectory() shouldn't make problems in this case.
sorry for my bad english
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: XIncludeFile Literal String Limitation

Post by #NULL »

Not sure if this is even a good idea. You might compile something completely different depending on which user you are. Imagine you have multiple users and they each have a different version of the include file in their respective MyFolder. Now to get the correct compilation result you would have to know which user you have to compile it as. It's probably better to use a hardcoded path and get an error if the path/user doesn't exist.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: XIncludeFile Literal String Limitation

Post by mk-soft »

Its compiler directive...

You can use IncludePath
Create a separate MainUserX.pb file for each user in the subfolder with the user-dependent data

Code: Select all

;-TOP

; File MainUserX.pb

#ProjectData = #PB_Compiler_FilePath
#ProjectBase = #PB_Compiler_FilePath + ".." + #PS$

IncludePath #ProjectData

IncludeFile "MyData.pbi"

IncludePath #ProjectBase


IncludeFile "Main.pb"
;IncludeFile "Functions.pbi"
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: XIncludeFile Literal String Limitation

Post by Little John »

Josh wrote:
Little John wrote:all these trials by you don't make sense, since you obviously do not understand the difference between things that happen at compile time, and things that happen at runtime.
GetUserDirectory() is needed at compile time, but not at runtime, because there is no (X)IncludeFile in the final exe anymore. The usage of GetUserDirectory() shouldn't make problems in this case.
Yes, in Rashad's code GetUserDirectory() is needed at compile time (as well as SetCurrentDirectory() or CopyFile()).
And that's exactly the problem, because GetUserDirectory(), SetCurrentDirectory() and CopyFile() do not work at compile time.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: XIncludeFile Literal String Limitation

Post by kenmo »

Little John is right... XIncludeFile tells the compiler, at compile time, where to copy in some code from.
GetUserDirectory, SetCurrentDirectory, CopyFile are all library functions which are compiled in, and they can't run until your compiled program is executed.

I don't know of many languages (Jai?) which blur the line between runtime functions and compiler functions like you're requesting.
Paul wrote:Guess it will have to be a Feature Request then and function similar to a constant like #PB_Compiler_Home which retrieves the compiler home directory at compile time.
Something like using just #PB_Compiler_AllUserData would be retrieved and filled at compile time.
This is the best solution I see.
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: XIncludeFile Literal String Limitation

Post by skywalk »

Zig includes compiler functions and a build system and is way ahead of jai in terms of public releases.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply