Page 1 of 1
Best practics for programming crossplatform applications?
Posted: Thu Feb 18, 2016 6:13 pm
by Korolev Michael
How do you organize your code in case of developing crossplatform applications?
Creating separate modules?
Or declaring procedures depending of current compiler?
Or something else?
Re: Best practics for programming crossplatform applications
Posted: Thu Feb 18, 2016 6:41 pm
by infratec
Hi,
it only needs some CompilerIf which I directly use inside the code itself.
I have only one piece of code which completely load different inlcudefiles:
For accessing the serialport with unusual baud rateswhich is only possible with many different
API calls.
And in general:
If you use threads... never use SetGadget... or StatusBarText()
Use PostEvent to do all viewing stuff in the main program.
Else you run into different kinds of trouble.
Bernd
Re: Best practics for programming crossplatform applications
Posted: Fri Feb 19, 2016 4:13 am
by Lunasole
I think it is enough just to use compilerif, but not for any small part to avoid extra code trashing.
I.e. if there are for example OS-depended code inside of procedure, it is reasonable to make a copy of whole procedure and use conditional compilation with it, instead of using it inside procedure (especially several times).
The modules me personally still didn't liked enough, as for me they looking useless unless they are "class modules" ^^ Although without modules other problems with Include/XincludeFile raising, but currently it doesn't take much time to resolve such conflicts.
Re: Best practics for programming crossplatform applications
Posted: Fri Feb 19, 2016 4:27 am
by Keya
do you guys just use the one PBF file for each Dialog or do you have slightly-tweaked copies of each Dialog for each OS?
i ask because i find that forms designed in one OS often have controls at least slightly out of place or slightly too small/big when viewed in another OS, so it seems each control needs its own specific tweaking on each OS, but that would mean doing everything three times, and i cant use CompilerIf's because the Form Designer would overwrite them if i ever modified the form. Catch22²!
Re: Best practics for programming crossplatform applications
Posted: Fri Feb 19, 2016 6:14 am
by TI-994A
Keya wrote:...it seems each control needs its own specific tweaking on each OS, but that would mean doing everything three times, and i cant use CompilerIf's because the Form Designer would overwrite them if i ever modified the form.
Just one form file would suffice; simply tweak them in the code modules.

Re: Best practics for programming crossplatform applications
Posted: Fri Feb 19, 2016 6:49 am
by Keya
yes but making the manual recalculations for each control's x/y/width/height or constantly retweaking/executing/inspecting/retweaking/executing/inspecting until it looks right is very laborious/time consuming compared to using the Form Designer where you correct the look of a control in just a few clicks and confirm visual correctness immediately
Re: Best practics for programming crossplatform applications
Posted: Fri Feb 19, 2016 7:05 am
by TI-994A
Keya wrote:yes but making the manual recalculations for each control's x/y/width/height or constantly retweaking/executing/inspecting/retweaking/executing/inspecting until it looks right is very laborious/time consuming compared to using the Form Designer where you correct the look of a control in just a few clicks and confirm visual correctness immediately
So, use the form designer to get the desired layout metrics, then simply use the generated values.

Re: Best practics for programming crossplatform applications
Posted: Fri Feb 19, 2016 7:23 am
by Marc56us
You can use the Form Designer
And manual code without problems.
Make Form with the VD with size for your OS and resize for others
Put Resize() code immediatly
after OpenWindow().
Code: Select all
XIncludeFile "....pbf"
Zoom_Linux = ...
Zoom_Mac = ...
OpenWindow_0()
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
ResizeWindow(#Window_0, #PB_Ignore, #PB_Ignore, x * Zoom_Linux, y * Zoom_Linux
ResizeGadget(#
...
CompilerElseIf #PB_Compiler_OS = #PB_OS_Windows
ResizeWindow(#Window_0
...
CompilerEndIf
Repeat
...
Forever

Re: Best practics for programming crossplatform applications
Posted: Fri Feb 19, 2016 9:06 am
by Fred
For easy cross-plateform GUI, I would use the Dialog lib instead of using the form designer, as it will recalculate everything right depending of the OS default font.
Re: Best practics for programming crossplatform applications
Posted: Fri Feb 19, 2016 9:10 am
by Keya
But to generate that XML you still have to manually type in all the x/y/width/height etc for every control, using your imagination to visualize? time consuming and laborious... or is there an XML Form Designer (or converter)? also i see if you use XML you need to include MIT license/copyright info with your app, not major but perhaps not always desirable
Re: Best practics for programming crossplatform applications
Posted: Fri Feb 19, 2016 10:41 am
by Fred
No, you don't have to use x,y,width,height, you just define the layout. It's easier once you get used to it and takes care of all OS little variations. The IDE only use dialogs for its window, which allows to have perfect render on all OS.