Declarations
-
- User
- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Declarations
I would like to be able to create various source files, but have the DECLARE statement in a single main file. I haven't spent a lot of time in the editor, but it appears the DECLARE for procedures must exist in the file where the procedure exists. Or perhaps use the GLOBAL keyword + DECLARE for a procedure at perhaps the root source file. Just an idea.
I come from a strong VB background (since Jan. 1991), but feel PB is the greatest new tool I have found. I HATE Visual Basic .NET and OOP in Visual Studio. So, I am really eager to get my hands around this product. Kudos to everyone involved in the creation of PB.
I come from a strong VB background (since Jan. 1991), but feel PB is the greatest new tool I have found. I HATE Visual Basic .NET and OOP in Visual Studio. So, I am really eager to get my hands around this product. Kudos to everyone involved in the creation of PB.
Re: Declarations
Check out XIncludeFile and IncludeFile in the help.
-
- User
- Posts: 31
- Joined: Wed Dec 02, 2009 4:50 pm
- Location: Oklahoma City, OK
- Contact:
Re: Declarations
Thanks will do!
Re: Declarations
Freak highlighted the benefit of a two-pass compiler in this post:
http://www.purebasic.fr/english/viewtop ... =3&t=40162
There are also several other posts with various discussions about it and a post somewhere on the "Tricks 'n' Tips" board with a tool that will parse your code and generate declarations automatically.
http://www.purebasic.fr/english/viewtop ... =3&t=40162
There are also several other posts with various discussions about it and a post somewhere on the "Tricks 'n' Tips" board with a tool that will parse your code and generate declarations automatically.
Re: Declarations
Advertising :roll:Mistrel wrote:...and a post somewhere on the "Tricks 'n' Tips" board with a tool that will parse your code and generate declarations automatically.
Declare-Filter
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
"Happiness is a pet." | "Never run a changing system!"
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Declarations
Hello Russellit appears the DECLARE for procedures must exist in the file where the procedure exists.
The good news is that the Declares can be in a single file, providing that file is your "main" file, i.e. the one you have active when the compiler is run. The main file does not have to contain any of the procedures. Put the Declares right at the top of the file, before the IncludeFile entries. - I switch on EnableExplicit to prevent my sloppy code from getting too bad. So, my "Main" file usually consists of the Declares, Global vars, Structures, Font specifiers, Image Plugins, Image catche, Loading of a prompts (Catalog) file and then the Includes, followed by a call to one of the procedures that gets the application ball rolling.
I am a PB newbie and I do not have any real experience with VB either, mostly C/C++ and a bit of C# (not really a fan of .Net). What I can say about PB is that I wish I had found out about it sooner! The tiny size of the exe files it produces will amaze you.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Declarations
here is mine that I use:
http://www.purebasic.fr/english/viewtop ... 12&t=41339
kurzer: noscript blocks your website (as does our corp policy anyway). I've always wanted to check your version out, but haven't been able to because of these limitations!
If I had been able to get to yours, I probably wouldn't have written my own
http://www.purebasic.fr/english/viewtop ... 12&t=41339
kurzer: noscript blocks your website (as does our corp policy anyway). I've always wanted to check your version out, but haven't been able to because of these limitations!
If I had been able to get to yours, I probably wouldn't have written my own

Re: Declarations
Think of it like this: The PB compiler really compiles just one big file. To automatically copy-and-paste the contents of other files into this bigfile, use XIncludeFile or IncludeFile.but it appears the DECLARE for procedures must exist in the file where the procedure exists.
Declares can be in a separate file, but it must be included in the main file before the procedures are used.
IMO there is really no reason for using a lot of declares. If you put your procedures in multiple files and include those, it will have the same effect.
-
- Enthusiast
- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Re: Declarations
Depends on your app. Procedures can call other procedures, and sometimes Declares are needed, full stop. You simply can't always have your procedures in the exact order that you want, and Declares come to the rescue in these situations.Trond wrote:IMO there is really no reason for using a lot of declares.
Re: Declarations
I said there wasn't a reason for using a lot of declares. Not that they are never required. I've seen code where all procedures are declared, and I think it's a waste of time.UserOfPure wrote:Depends on your app. Procedures can call other procedures, and sometimes Declares are needed, full stop. You simply can't always have your procedures in the exact order that you want, and Declares come to the rescue in these situations.Trond wrote:IMO there is really no reason for using a lot of declares.
-
- Enthusiast
- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Re: Declarations
I know. One of my apps needs several declares, about 8. I consider that a lot, but my app won't run without them. I agree that declaring everything is unwarranted most of the time, but I suppose people are just playing it safe, and it doesn't waste anything except a bit of source code.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Declarations
I think it's just a matter of what you are used to.
when I started programming I learned to start my program at the top and scroll down to find the subroutines.
when I first programmed in C it turned me upside down, but I learned to deal with it instead of wasting my time with tons of declares.
when I came to PureBasic, it was just a matter of rewarming old habits.
when I started programming I learned to start my program at the top and scroll down to find the subroutines.
when I first programmed in C it turned me upside down, but I learned to deal with it instead of wasting my time with tons of declares.
when I came to PureBasic, it was just a matter of rewarming old habits.
oh... and have a nice day.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Declarations
Sorry jamba, I overlooked your post.jamba wrote:kurzer: noscript blocks your website (as does our corp policy anyway). I've always wanted to check your version out, but haven't been able to because of these limitations!
If I had been able to get to yours, I probably wouldn't have written my own

Thats strange, there is no special magic in my plain HTML coded website.
But please look in this thread. In the 3dr post you'll find the direkt download link to the zip archive of Declare-Filter (if you still want to have a look on it).
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
"Happiness is a pet." | "Never run a changing system!"
Re: Declarations
ok, cool, thanks!kurzer wrote:Sorry jamba, I overlooked your post.jamba wrote:kurzer: noscript blocks your website (as does our corp policy anyway). I've always wanted to check your version out, but haven't been able to because of these limitations!
If I had been able to get to yours, I probably wouldn't have written my own![]()
Thats strange, there is no special magic in my plain HTML coded website.
But please look in this thread. In the 3dr post you'll find the direkt download link to the zip archive of Declare-Filter (if you still want to have a look on it).
I'll take a look, I can always learn from someone else's code

I don't even really use my own declarations tool much anymore (unless I just can't compile or something like that)--but usually it is just one or two procedures that need to be declared.