Experience of moving from PB to FB

Started by Barry Gordon, June 07, 2015, 12:31:06 PM

Previous topic - Next topic

Barry Gordon

Hi Chaps,

As a now hobby programmer - over the last few weeks (with Pauls help) I have decided to make the move from Powerbasic to Freebasic.

I am actually surprised that it has not turned out to be as traumatic as I expected and I am making really good progress. And I am seriously impressed with FreeBasic and how similar it actually is to PB.    I don't tend to use the more complex facilities withing PB - so maybe that is why I am happy so far.

Anyway - I decided to start by converting a really (really, really) basic custom control that I used originally to teach me how custom controls worked and also gets used when I want to experiment with custom controls.  I originally got bogged down initially (mainly with TYPES) - but with Paul's excellent guidance I finally got it to work.    My hobby consists of music software - so custom controls for things like knobs and switches and music keyboard layouts are really important to me - so thats why I started in the deepish end.   Since I successfully got my test control to work I have moved onto a rather more complex control and that too worked without too much effort.  And, more importantly, I actually enjoyed it.

So in an effort to be helpful to others trying to make the transition - I thought that I would provide you with copies of the Freebasic and Powerbasic version of the controls - so that you can see what the differences are.  The Powerbasic version is unmodified - but the Freebasic one has been enhanced slightly to show the custom controls and how the messaging can be made to work to control them.   Or at least they show how I do it ....    I made this modification to the Freebasic version because I thought it might be helpful to a Freebasic only person using custom controls for the first time.   Obviously you may do with them whatever you like.   If anyone finds anything wrong - then I would obviously appreciate positive feedback.

Examples of things I found different are:-

1) Types are different so e.g. handles are now type hWnd  and not Dword  (the are many others (see my attached example for some differences))
2) RGB(R,G,B)  will not work in Windows - its called BGR(R,G,B).  This is mentioned in the RGB help.
3) Pointers go from being e.g.  '@ed.ABC = 1'  in PB  to '(*ed).ABC = 1' in FB
4) You cannot use Call for subs :     so 'Call ABCD(23)' in PB has to become simply 'ABC(23)' in FB  (I use it for readability)
5) There seems to a be a general ban on the % symbol  :)  so %WM_PAINT becomes WM_CREATE
6) The basic colour symbols e.g. RED, GREEN, GRAY, etc are not defined  (Paul has a workaround)

Anyway - I hope somebody finds the attached test programs useful and I would encourage people to dive in to FreeBasic.

Regards
Barry

Paul Squires

Hi Barry - thanks for sharing your FreeBASIC conversion experience!  :)

Just an FYI:
Quote
3) Pointers go from being e.g.  '@ed.ABC = 1'  in PB  to '(*ed).ABC = 1' in FB

I have never had problems using pointers without the parenthesis. Likewise you can use the arrow syntax for clarity as well:


*ed.ABC = 1

or

ed->ABC = 1

Paul Squires
PlanetSquires Software

David Kenny

Hello Barry,

Thanks for sharing your version of the "Rosetta Stone", if you wish.  I won't have time for a bit, but will definitely be looking this over.

Quote from: Barry Gordon on June 07, 2015, 12:31:06 PM
so %WM_PAINT becomes WM_CREATE

I really hope this isn't what you meant.  ;)

David

Barry Gordon

Hi Chaps,

>  so %WM_PAINT becomes WM_CREATE - I really hope this isn't what you meant ...

Duh!!! - its my age you know    :(  - you're correct:  %WM_PAINT becomes WM_PAINT  - sorry!

> With regards to Paul's comment about pointers not needing  parenthesis i.e.  *ed.ABC=1 instead of (*ed).ABC = 1

- well actually I just tried removing the parenthesis and it will not compile.   I can't now find the help entry in the FreeBasic help file - but I'm sure I did not make it up as I could never have dreamed (or WM_CREATE - joke!!!)  such a strange syntax.   It gives error 264.   So I'm now confused (normal state!)

Cheers
Barry


Barry Gordon

Hi,

Withe regards to "*ed.ABC=1 instead of (*ed).ABC = 1":-

Actually after following links to links to links in the FB help file (seems somewhat appropriate given that we are dealing with pointers) - I have managed to find the relevant help entry.  So ...:-

======
Pointers to user-defined types are defined and used like all other pointers. Accessing a member of a Type or Class requires one of the following two methods:

Type myType
    a As Integer
    b As Double
End Type

Dim x As myType
Dim p As myType Pointer = @x

'' 1) dereference the pointer and use the member access operator:
(*p).a = 10
(*p).b = 12.34

'' 2) use the shorthand form of the member access operator:
Print p->a
Print p->b

The first method uses Operator . (Member Access). This operator accesses members from references, so the pointer is dereferenced first. The member access operator has higher priority over the dereference operator, so parenthesis are needed to dereference the pointer before using it with the member access operator.
===================

I was using a user defined type - so this seemed relevant and does seem to work (whereas the lack of parenthesis does not).   But I am more than happy to be corrected.

Cheers
Barry