From PowerBASIC to FreeBASIC ...

Started by Jean-pierre Leroy, April 01, 2015, 01:40:47 PM

Previous topic - Next topic

Jean-pierre Leroy

Dear all,

I would like to know if some of you have some tips and tricks about source code migration from PowerBASIC to FreeBASIC.

Now that we have a complete FireFly Visual Designer for both FreeBASIC 32 bits and 64 bits, I will try to convert my PowerBASIC projects to FreeBASIC.

Regards,
Jean-Pierre

Paul Squires

Hi Jean-Pierre,

So far in my use of FreeBASIC, I have encountered a few differences that I would like to share:

(1)  There is much stronger type checking needed in FreeBASIC. It is VERY close to "C" when you are using WinAPI functions. For example, in PowerBASIC you could almost always use a LONG or DWORD to represent a pointer variable. In FreeBASIC, you should cast (using the Cast function) your variables to the correct type as defined in the WinApi headers (eg.  HANDLE, HWND, BITMAP, WNDPROC, HFONT, etc...). for the most part you can get away with still using INTEGER or UINTEGER but you will get a LOT of compiler warnings of pointer conversions.

(2)  PowerBASIC has a richer set of built in string functions for manipulating all different kinds of strings.

(3)  PowerBASIC currently has better support for COM and Unicode on Windows machines.

(3)  FreeBASIC has built in functionality to Print directly to the console screen as your Windows GUI program is running. This is fantastic for debugging your program as it is running. You can easily disable that console window whenever you need to.

(4) In PowerBASIC you need to buy a whole separate compiler for console programs. In FreeBASIC, you get EXE (GUI and console), DLL, and static libraries all built into the one compiler and that compiler is free.

(5)  FreeBASIC allows for dynamic strings in TYPE structures!

(6)  "Classes" in FreeBASIC are built by extending TYPE structures. TYPE's in FreeBASIC are amazing. They are more like C++ because you use them for OOP.

(7) FreeBASIC can compile to ASM or C so that the backend GCC compiler can optimize the code for speed and size.

(8)  FreeBASIC is now 64bit.

(9)  FreeBASIC has a large number of converted header files available to interface to existing C libraries.

....must be more that I can not think of right now  :-)

You will encounter frustration as you start to convert a program from PowerBASIC to FreeBASIC. That would be no different than any other conversion but if you get stuck then please ask questions here or over in the FB forum. If I don't know the answer then I will try to find it for you.

 
Paul Squires
PlanetSquires Software

Elias Montoya


Paul, i plan to take a look at it, but what about #2? can at least some kind of "wrappers" be created to achieve the same functionality?

For me, it would be too hard to convert my firefly projects to Freebasic, my code relies heavily on pointers and inline assembly. do you think it would be possible to convert such code?

IMO, #5 would be a blessing in PowerBASIC.

Win7, iMac x64 Retina display 5K, i7-5820K 4.4 ghz, 32GB RAM, All updates applied. - Firefly 3.70.

Paul Squires

Hi Elias, there are many source codes and libraries already available with the FB community that simulate most of the string functionalities and containers (hash, collection, linked lists, queues, etc) that exist in PB. It is just that in PB it is built into the compiler runtime, whereas in FB it is separate external libraries or include files. No big deal in my opinion. FB already has very flexible pointers and inline assembly.
Paul Squires
PlanetSquires Software

Petrus Vorster

FB help on their site not so nicely structured as here.

The 64bit compiler package lacks a lot of the .bi files.
I have been poking around on the site, saw the notice about the test builds but dont seem to find it.

Where do i get all their header files again?
-Regards
Peter

Paul Squires

Hi Peter,

I have links on my FireFly FreeBasic page to the latest test compilers:  http://planetsquires.com/firefly_freebasic.html
They can be found at this link: http://sourceforge.net/projects/fbc/files/Test%20Builds/
Those test builds have all of the WinAPI headers.

The official 1.02 release will be very soon:  http://www.freebasic.net/forum/viewtopic.php?f=17&t=23439

Paul Squires
PlanetSquires Software

Petrus Vorster

Got those thanks.
Both versions gives errors, so i cant get anything going yet, but i will give this a shot in a while again.
The studies has to come first now, but i am so darn curious.  ???
Will let you know when i had a poke at it again.
-Regards
Peter

Richard Marchessault

I thought that I would give FreeBASIC a try by converting a small program written using FireFly and PowerBASIC. As expected there is some frustration in finding equivalents for the PowerBASIC language in FreeBASIC. It's a learning experience which slows me down but does not create any road blocks. All was going well until I worked on converting procedures I had written to read and write to an INI file. I wrote these procedures before I became aware of the INI procedures in FireFly for PowerBASIC. My procedure made use of the statement:

Line Input #F, Y -- where F is assigned using Freefile and Y is a string variable.

Trying to compile using the latest 32 bit version (1.02.0) of FreeBASIC results in a compile error which I cannot overcome. I checked the forums and others are encountering exactly the same error. See attached image.

I thought I might just go ahead and use the INI functions in FireFly but I found that these functions are not available in FireFly for FreeBASIC.

I suppose that this bug in FreeBASIC will be fixed in the near future so I can continue, but this raises a question in my mind about the reliability of FreeBASIC. How many other issues like this will I encounter with fundamental language constructs which I must depend on? Can I trust that the compiled code is correct?

I'm trying to keep an open mind but I am concerned about using this for major projects.
Thanks,
Dick

Paul Squires

I find FreeBASIC to be remarkably bug free especially given the size and scope of the project. Of course there are issues here and there but nothing that would prevent me from creating 99% of all programs that I'd want to create. FB expands across several operating systems in both 32 and 64 bit. Not too bad for a free open source project.

That LINE INPUT problem emerged with the last set of Includes because dkl used different/newer C includes to convert using is automated fbfrog program (he wanted a common set of includes for both 32 and 64 bit). You probably already know the fix for the LINE INPUT problem:  http://sourceforge.net/p/fbc/code/ci/a92ae2

The fundamental constructs of the language work perfectly well based on my experience.

Paul Squires
PlanetSquires Software

Klaas Holland

I am trying to convert a FF-PB program to a FF-FB program.
The forms are Oke thanks to Paul's FireFly.
The syntax however is a bit different e.g.

FF_ComboBox_AddString HWND_FORM1_COMBO2, Using ( "  ##  ", X + 1)       ' This works in PB but not in FB, the compiler gives:

Error 1: Argument count mismatch, found 'Using' in 'FF_ComboBox_AddString HWND_FORM1_COMBO2, Using( "  ##  ", X + 1)

and after that the program starts the exe that is in the release folder as if nothing happened.

FF_ComboBox_AddString HWND_FORM1_COMBO2, Str (X + 1)    ' This works in FB, but I want it like above

1. What am I doing wrong?

2. Why does the program start although an Error occurs?


Paul Squires

Hi Klaas,

Happy to hear that you are attempting to do a conversion. Hopefully you will not run into too many problems.

I believe that the USING statement in FB can only be used as part of the PRINT USING statement. I do not think that it can be used standalone. For your purposes, maybe the FORMAT statement would be more appropriate?   http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgFormat

Not sure why the program starts. It is quite possible that Firefly is running a previously created EXE. I will have to run some tests on this situation.
Paul Squires
PlanetSquires Software

Klaas Holland

Hi Paul,

Thanks, it works this way:

FF_ComboBox_AddString HWND_FORM1_COMBO2, Format( X + 1, "  ##  ")

Next questions:
1.
When you customize a Combobox and you want to start each item with a blank like " 2010"  then
in the executable in the first item the blank is always ignored also in the PB version.
The next items are oke.
2.
In FF-FB the Combobox folds out 20 items although it holds only 16 items.
In FF-PB the Combobox folds out only the 16 items it contains.
3.
How do I connect with a MYSQL-DataBase and where can I find the SQL_statements that can be used in FB.
In PB I use SQL Tools from Perfect Sync.
4.
How can I choose to what printer I want to send a print job.

I hope you can help me with these problems too.

Klaas


Paul Squires

Hi Klaas,

1. Yes, I believe that I have been LTRIMing the data prior to saving it in the project files. I will put that in my bugtracker to be fixed.
2. Thanks for that report. I will put that in my bugtracker to be fixed.
3. There should be a fair amount of sample code on the FB site for interfacing with MySQL. The FB distribution comes with header files for MySQL. They are located in \inc\mysql. There is also an example program under \examples\database  I did a search for MYSQL on the FB forum and got a lot of hits.
4. Maybe try code in this post:  http://www.freebasic.net/forum/viewtopic.php?f=6&t=8285&hilit=printdlg
Paul Squires
PlanetSquires Software

James Klutho

SQLTools is BSTR centric in its function calls.  You might find it useful to write a PB DLL that calls SQLTools with wrapper functions that use ASCIIZ.  I never understood why Eric Pearson never built that flexiblitiy into SQLTools.

Paul Squires

Klaas,

Please try the new Firefly FB exe attached to this post. I am pretty sure that I have fixed your Issue #1. I have not been able to recreate issue #2 yet.
I have also fixed your earlier reported problem of the exe running after a failed compile.
Quote

FireFly3 - 3.74 (Not Yet Released) [ View Issues ]
==================================
- 0000903: [Bug] FB/PB: ComboBox/ListBox "Custom" property editor does not allow leading spaces for items being added (Paul Squires) - closed.
- 0000905: [Bug] FB/PB: After failed compile, FF is running a previously existing version of the project exe (Paul Squires) - closed.
- 0000902: [Change] FB: Removed % from %SW_SHOWNORMAL|%SW_SHOWMINIMIZED|%SW_SHOWMAXIMIZED in WindowState property (Paul Squires) - closed.

If you could test this new exe for me then that would be appreciated. I have not released it yet as a full update to the general community yet.


Paul Squires
PlanetSquires Software