Best practics for programming crossplatform applications?
-
Korolev Michael
- Enthusiast

- Posts: 200
- Joined: Wed Feb 01, 2012 5:30 pm
- Location: Russian Federation
Best practics for programming crossplatform applications?
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?
Creating separate modules?
Or declaring procedures depending of current compiler?
Or something else?
Former user of pirated PB.
Now registered user :].
Now registered user :].
Re: Best practics for programming crossplatform applications
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
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
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.
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.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Re: Best practics for programming crossplatform applications
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²!
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
Just one form file would suffice; simply tweak them in the code modules.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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 
Re: Best practics for programming crossplatform applications
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
So, use the form designer to get the desired layout metrics, then simply use the generated values.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
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 
Re: Best practics for programming crossplatform applications
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().

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
...
ForeverRe: Best practics for programming crossplatform applications
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
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
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.


