Page 1 of 1

Declarations

Posted: Fri Dec 04, 2009 7:22 pm
by russellbdavis
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.

Re: Declarations

Posted: Fri Dec 04, 2009 9:10 pm
by Foz
Check out XIncludeFile and IncludeFile in the help.

Re: Declarations

Posted: Fri Dec 04, 2009 9:16 pm
by russellbdavis
Thanks will do!

Re: Declarations

Posted: Tue Dec 08, 2009 1:01 am
by Mistrel
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.

Re: Declarations

Posted: Wed Dec 30, 2009 11:32 pm
by Kurzer
Mistrel wrote:...and a post somewhere on the "Tricks 'n' Tips" board with a tool that will parse your code and generate declarations automatically.
Advertising :roll:
Declare-Filter

Re: Declarations

Posted: Thu Dec 31, 2009 4:28 pm
by IdeasVacuum
it appears the DECLARE for procedures must exist in the file where the procedure exists.
Hello Russell

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.

Re: Declarations

Posted: Thu Apr 08, 2010 3:01 pm
by jamba
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 :P

Re: Declarations

Posted: Fri Apr 09, 2010 9:09 am
by Trond
but it appears the DECLARE for procedures must exist in the file where the procedure exists.
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.

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.

Re: Declarations

Posted: Fri Apr 09, 2010 10:55 am
by UserOfPure
Trond wrote:IMO there is really no reason for using a lot of declares.
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.

Re: Declarations

Posted: Fri Apr 09, 2010 11:25 am
by Trond
UserOfPure wrote:
Trond wrote:IMO there is really no reason for using a lot of declares.
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.
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.

Re: Declarations

Posted: Fri Apr 09, 2010 11:53 am
by UserOfPure
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.

Re: Declarations

Posted: Fri Apr 09, 2010 12:37 pm
by Kaeru Gaman
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.

Re: Declarations

Posted: Wed May 12, 2010 3:56 pm
by Kaeru Gaman
whom you're adressing? :o

Re: Declarations

Posted: Thu Jun 03, 2010 10:19 pm
by Kurzer
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 :P
Sorry jamba, I overlooked your post. :oops:
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).

Re: Declarations

Posted: Fri Jun 04, 2010 12:12 pm
by jamba
kurzer wrote:
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 :P
Sorry jamba, I overlooked your post. :oops:
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).
ok, cool, thanks!
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.