Author Topic: A Trick for Library Makers  (Read 2546 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
A Trick for Library Makers
« on: February 06, 2021, 11:33:16 pm »
Here's a little trick I just sat down and sorted out, that you guys who write library style code might want to get familiar with.

For your BI file, write it in a simple little $IF Wrapper, like this one:

$IF VKBI = UNDEFINED THEN 

    (put your actual BI file stuff in between the wrapper, here...)

    $LET VKBI = TRUE
$END IF

Then, at the top of your BM file, write something similar to this little snippet:

$IF VKBI = UNDEFINED THEN
    '$INCLUDE:'Virtual Keyboard.BI'
$END IF

Now, you can work in the BM file without getting type errors and such, and having to code blind.  All your references from the BI file are now included in your work, and auto-formatting and the IDE error checking works as intended, and life is good!!



And best of all? 

Once you're finished, you just write your main program like usual to take advantage of those libraries.

'$INCLUDE:'Virtual Keyboard.BI'

(main program code goes here)

'$INCLUDE:'Virtual Keyboard.BM'

Since your manual include of the BI file occurred already in your main program, the precompiler variable is set, and thus no longer UNDEFINED, so you won't include it twice and generate "Name already in use" errors.



I find, for me, this little trick takes a good bit of the hassle out of working with library creation and editing, so I thought I'd share, and maybe others would enjoy taking advantage of it as well.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: A Trick for Library Makers
« Reply #1 on: February 06, 2021, 11:34:59 pm »
I used this for a while but then just stopped. It is definitely a good idea for BI-BM code
Shuwatch!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A Trick for Library Makers
« Reply #2 on: February 06, 2021, 11:40:48 pm »
I've wrapped it around extremely common routines before (like my ExtendedTimer -- it gets packaged in a ton of stuff), so those common functions only get called once, but for some reason, I just never thought of wrapping it around my whole BI file until this evening.  Happy the light bulb finally DINGED on for me, as it truly does a lot of the hassle out of working inside them.   

Before, I was just remarking and unremarking out a line over and over at the top the BM file which let the BI file work or not, but this is such a simpler method.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!