modGtk3 for Xojo

Linux has always been kind of an odd duck when it comes to Xojo.  If you create Linux applications with the IDE running in Linux the default sizes for controls is 26 which is different than MacOS or Windows since their default control height is 22.  See the initial screenshot:  the controls in Linux just don’t look right at the default Mac/Win control height.

The standard answer for many years was to subclass your controls and modify the height of the controls in Linux.  This was okay but it hard to make your UI look good on all three target platforms.

Xojo 2017 R2 changed the drawing system it uses.  The switch to GTK3 made it possible to modify the CSS of your application theoretically making it possible to make all platforms look and behave the same.

Just because you can modify the CSS means it’s a trivial task.  Several long time Xojo community members Jim McKay and Jürg Otter stepped up to the plate and put in the time to figure it out.  The result is at https://bitbucket.org/pidog/modgtk3/src/master/.

In this screenshot you can see that everything looks as you’d expect.

Implementing this in your own project is simple.  Download the BitBucket repository, open the project in Xojo and copy the GTK3 folder into  your own project.  Then in the App.Open event put these three lines in:

modGTK3.initGtkEntryFix
modGTK3.initGtkWidgetHeightFix
modGTK3.InitGlobalGTK3Style

That’s it.  Voila!  Now your app looks better in Linux and there’s no need to subclass your controls.  I realize this isn’t magic but it sure seems like it.

BKS Shorts 2.0.9

Today we released BKeeney Shorts 2.0.9.  This is a free update to all version 2.0.x users.  

Shorts is the award winning reporting tool for Xojo applications.  Shorts allows a Xojo developer to embed a report designer inside in a desktop application, view reports in any resolution on desktop or web applications, save report files to file or to a database, and to export reports to HTML, CSV, and PDF (requires the DynaPDF plugin from MBS).  Shorts works with SQLite, CubeSQL, PostgreSQL, MySQL, MS SQL Server, ODBC, and Informix (requires the SQL plugin from MBS).     Shorts comes as 100% unencrypted Xojo source code.    

New:

  • Align: Justify text! (#3627)
  • Report Designer can now copy and paste! (#3691)
  • Method to tell the DynaPDF renderer where to look for custom fonts
  • Report Designer bands with a Band Script now offer an indication in the designer (#3701)
  • Schema Zapper will remove the DB schema from the JSON for manual template changes (#3632)

Changes:

  • Running in HiDPI in Windows using Xojo 2018 R3 now shows report preview in proper clarity
  • Report Designer no longer nags about deleting items that can be undone
  • Designer window positioning suggested by container event for better scoping
  • Standardized naming on winReportDesigner
  • DesignCanvas.GetUniqueName is now more smart
  • DBWrapper.DatabaseFile is now DBWrapper.SQLiteDatabaseFile for consistency
  • ReportBKS no longer redundantly loads styles to the global styles dictionary
  • PAF_PrintKit.DictStyles is now protected for clarity in code

Fixes:

  • PreviewCC Mojave / 2018R3 & R4 graphical glitch workaround
  • Reports where the page header is empty no longer have multiple page positioning issues
  • Added Numeric and Decimal datatypes for PostgreSQL, maps to Double
  • Views now show up in the Manual Relations editor (#3731)
  • Designer window will no longer reposition if the report template positioning doesn’t fit onscreen (#3651)
  • Fixed localization mismatch in the navigator (#3851)
  • DBWrapper no longer assumes SQLite databases have a database file (#3694)

Removed:

  • PAFConfirm function, please use the modGlobals.Alert function instead
  • winReportDesigner no longer has a Placard control
  • PAF_DatabaseKit.CreateDatabaseFile function, it served no purpose in the Shorts project

For more pricing, demo versions, and training videos please visit http://www.bkeeney.com/allproducts/bkeeney-shorts/

Nil Recordset

The question on how to deal with nil RecordSets is OFTEN asked in the Xojo forums.  Either the original poster or a well meaning responder will do something like this:

dim rs as recordset 
rs = db.sqlselect(sql)
If rs <> Nil Then
     If Not rs.EOF Then
       // No Records in Table or bad querry?
     End If
End If

It works, but it only masks the real issue.  Why is rs nil in the first place?  The answer is because the SQL statement to get the RecordSet had an error!  What is that error?  We have no idea because the code doesn’t ask for the error.

Most of the time the database will give you an error message that will point you in the right direction.  How do you tell that the database had an error?  You check the Error property.

dim rs as recordset 
rs = db.sqlselect(sql)
if db.error then
     //Do something
end


The database can give you an error code but this varies from database to database so I don’t find it exceptionally useful.  However, there is an ErrorMessage property that gives you a human readable message.  

dim rs as recordset 
rs = db.sqlselect(sql)
if db.error then
     MsgBox “DB Error: “ + db.ErrorMessage
     Return
end


In this example I’m showing this to the user but this is probably not a great idea for most uses because you don’t want the average user to know what happened.  However, it’s great while debugging.

The error you get back might be a little mysterious.  SQL is a language specific to databases and the error message returned expects you know a little bit about databases.

The second part of my message to you is that if you’re using SQLSelect or SQLExecute in your code you should look at PreparedStatements.  They’re safer in that PreparedStatement have some security features and does the heavy lifting of taking the input data and putting it into the right format.  What do I mean by this?

In a normal SQL statement you would have an SQL statement like this:

dim sql as string
sql = “Select * from users where last_name = ‘Keeney’;”


This selects all users whose last name is ‘Keeney’.  If you were going to allow the user to search for whatever name they want you would end up doing something like this:

dim sName as string
sName = txtSearchField.Text
sql = “Select * from users where last_name = '“ + sName + “’;”


Note that I had to manually put the single quotes in before and after the name since the database column is text.  This works great until you enter an Irish name like O’Neil.  The database will choke on this because it has an extra apostrophe in the statement.  You can escape this data yourself but what a pain.  Instead, use a PreparedStatement.

dim ps as SQLitePreparedStatement
dim sql as string
sql = “Select * from users where last_name = ?”
ps = db.prepare(sql)
ps.bindtype(0, SQLitePreparedStatement.SQLITE_TEXT
ps.bind(0, txtSearch.text)
dim rs as Recordset
rs = ps.SQLSelect
if db.error then
     MsgBox db.errormessage
     return
end


Nowhere in the code do I have to put in apostrophe’s or escape any data.  It’s just handled and this is true if you have database columns that are text, date, or numeric.

PreparedStatements have a number of advantages besides the automatic formatting.  They help with security and SQL Injection attacks.  If you don’t know what those are just do a web search to learn more.  You can reuse PreparedStatements in code but in my testing it doesn’t save much time as it appears as if the database plugin saves them internally.  Regardless, there are so many reasons to be using PreparedStatements over straight SQL.

To recap:  A nil recordset always mean a database error has happened.  You need to check for for the error after every operation whether that be a Select, Insert, Update, or Delete statement.  Basically after every SQLSelect and SQLExecute statement.  Ideally you want to start moving all of your code to use PreparedStatements because of all of its advantages.

2018 Was a Weird Year

I hope everyone’s holiday season was good.  We’re approaching the end of 2018 and I find it nice to reflect on what’s happened and what we’ve accomplished this year.

Looking Back

Let’s start off with the blog posts.  I did 41 (well now 42) blog posts in 2018.  Five were about Xojo releases.  Four were BKeeney Software product releases.  Four posts were about the Xojo Developers Conference.  The rest were a variety of Xojo related topics.

The most highly commented blog post was from June called Chasing Xojo where I lamented that Xojo, at least until that point, seemed to be a less stable when it came to Windows and Linux due to major revamping of the drawing systems on both platforms.  In Windows, Xojo doesn’t flicker as much but the struggle to get speed was a concern for all of 2018.  In Linux, the switch to GTK 3 wasn’t as smooth as we could have hoped.

The most viewed blog post was from August called Xojo 2018 Release 2 where I did my usual review of the most recent release of Xojo.  I heavily criticized Xojo for their poor documentation in that release.  I received plenty of blowback on that one.  But I think the end result is that R3 and R4 documentation was much better.

We released two new products with BKS Report Studio and BKS Tab Control.  Report Studio is our reporting utility meant for end-users for macOS and Windows and it was built using the award winning Shorts reporting classes (also a blog post).  The Tab Control is a canvas subclass that replaces, and extends, the built-in Xojo tab control in many ways and was our attempt at replaced the old CustomTabControl that many use but is unusable for HiDPI apps.

The other major release of the year was ARGen 3.0.  ARGen is our utility to create Xojo projects that creates ActiveRecord objects.  Among the many changes was the ability to generate ActiveRecord objects for iOS projects, supporting GUID primary keys, and the ability to include Audit Trail, Localization, and Database Update modules that help in many products.  We use ActiveRecord in practically every project and having the ability to generate some basic desktop and web UI is a huge time saver.

2018 sure seemed like a mixed bag for Xojo.  The Windows drawing issues took up a good chunk of the year and I think R4 was the first solid Windows release (although I still have 2 client apps that won’t remote debug in R4).  I can’t imagine the amount of effort that Xojo and the community put into getting Windows drawing fixed.

64-bit remote debugging became a reality for all targets this year.  64-bit compiling isn’t the huge gain that many in the community hoped for but then we always want more.  We just have to remember that 64-bit doesn’t necessarily mean ‘faster’.  At least the debugger works and that’s not nothing.

Dark Mode came soon after the release of Mojave.  The IDE works in Dark Mode and we were given many of the tools to implement it in our own projects.  Dark Mode only works in MacOS but some are already clamoring for it in Windows too.  It’s still to early to tell if Dark Mode is a hit on Mojave much less in xojo.

Looking Forward

What is 2019 going to bring us?  For one, we’re almost finished with a fairly significant update to Formatted Text Control and after that’s released we’ll start with an even bigger version 4 update to the venerable word processing control to bring it up to date and extend its capabilities to make it even more powerful.

We have a number of large consulting projects that have been in gestation for many months and years.  It will be nice to have a big project or two to keep us busy.

With the release of Web 2.0 I will redo all of our Xojo training videos related to web.  They’ve been outdated for a while but it’s not worth redoing the videos until Xojo releases Web 2.0.  If they release Android I’ll start on at least some intro videos for that too.  This might finally be the year that I redo the remaining Real Studio videos.  No doubt I’ll redo them just before a major IDE change.  🙂

What do I expect from Xojo?  That’s a tough question to answer since they’re so damn secretive now.  I expect Web 2.0 to show up in time for XDC (so maybe release 2?).  I think it will be pretty solid in the first release but it wouldn’t expect it to be good until the following release.

I also think that at XDC we’ll get an alpha of InterOps but not anything other than another dog and pony show for Android.  Targeting another platform is long and tedious process and involves some serious IDE work.  How much of the iOS editors can they use?  I can only guess but at first blush I say not much.

Some of Android’s success may hinge on getting iOS to use the global framework and away from the Xojo Framework.  Nothing like rewriting an entire framework while keeping backwards compatibility.  The more I think about it the more I think the iOS rework is put on hold until Android is released.  

Which leads to API 2.0 in general.  We’ve already seen some of the first new controls to use API 2.0.  URLConnection was introduced in 2018 R4 with mixed success.  I would expect more API 2.0 controls to show up.

So what do you think?  Was 2018 a successful year for Xojo?  What do you see happening in 2019?

Xojo 2018 Release 4

Xojo 2018 Release 4 hit the internet this week.  This relatively small (84 bug fixes, 21 changes, 5 new items, and 11 doc and example changes) update is a nice end of year release that may or may not satisfy your Xojo dreams.  Let’s get into the highlights.

Of the new items list the big one is the new URLConnection class.  The URLConnection class works with the HTTP 1.1+ protocol and works with http and https connections.  This is a replacement for the Xojo.Net.HTTPSocket and brings back one of the things many developers missed about the old HTTPSocket class – Synchronous communications – using the SendSync method.  

SendSync is a concession by Xojo with the caveat that the application may appear to freeze while running this method.  The regular, and probably the better, Send method is asynchronous and does not freeze the app.  Admittedly the async way is the better way but for many developers the synchronous method is easier to implement and ‘good enough’ for their use.  Still, consider using the async method.

The Screen class now has the ScaleFactor property.  There are two new global constants: AppSupportsDarkMode and AppSupportsHiDPI  that are pretty self explanatory.

iOS builds now use the iOS 12.1 SDK.  macOS builds now use the 10.14 SDK for 64-bit builds.

There are couple of changes that are noteworthy.  The first being that the Windows IDE can now successfully build large projects for Linux 64-bit and ARM targets (frankly I didn’t know this was a problem but I bet that ‘large’ is the key word).  Any remaining threads are now killed after the app.close event (possibly a reason why some apps in macOS crash after they quit?).  EnableMenuItems no longer fires needlessly on every keypress in Windows.  Lingua and Remote Debugger Stub have been updated to work with Dark Mode on macOS.

There are 84 bug fixes in this release.  The more important ones (at least in my opinion):  The Build folder is properly emptied between build runs.  Remote Debugging to a Raspberry Pi no longer randomly crashes when stopping at a breakpoint.  Browsers that have disconnected from the web app will now reload the web app so they don’t appear frozen.  There are also a couple dozen IDE bug fixes to the Inspector, Navigator, Find & Replace and a number of the editors.

As with any new release you need to thoroughly test your projects before doing a public release.  It was noted during the beta period that the Einhugur Search Control didn’t work properly in Mojave but has since been fixed.  We had one large project not work when remote debugging from Mac to Windows but I haven’t had time to track it down.  If you have found any new issues with R4 please submit a Feedback report right away!

Happy coding!

XDC 2019 Session List

The session list for the 2019 Xojo Developers Conference (XDC) was released today at https://www.xojo.com/xdc/sessions/.  Take a look at this interesting list.

I’ve been attending Xojo developer conferences for twelve plus years (don’t remember what my first XDC was – maybe 2004?).  Each one is unique and the topics are usually interesting but do tend to be repetitive from year to year at times.  The session topics for XDC 2019 seem to be more unique than past years.

Obviously Geoff will do his keynote address and talk about what they’ve done in the past year, what they’re currently working, and what’s coming up (sometime) in the future.  There is a session each for Android, Web 2.0, API 2.0, beyond Linux, everything MS Windows, and more by the Xojo staff.

What’s left is an intriguing list of sessions that will be tough to figure out what I want to attend and which ones I can wait to see recorded (assuming they’re recorded again).  I can’t remember an XDC I’ve looked forward to more.

Carol is doing a session on Database Topics for Programmers and I’m doing one called “Xojo Mistakes We All Regret Later”.  My alternative title is “Thankfully time travel doesn’t exist otherwise my future self will no doubt come back to murder me for these stupid programming mistakes I’ve done.”

If you’ve never been to an XDC I highly recommend it.  You will get to meet some of the best Xojo developers on the planet, talk Xojo non-stop for 3 (or more) days on end, talk to Xojo staff, and have fun.  Of course that last point is mostly because of the first three.  You won’t find a bigger concentration of Xojo developers on the planet!

I hope to see you all in Miami in the first week of May.  What sessions are you excited about?

What Topics Do You Want Covered?

One of the joys of doing a blog for close to eleven years is that I feel like I’ve talked about a lot of topics and people ‘know me’ fairly well.  I always get a thrill when people tell me they’ve read this blog.  That is so cool and I thank you for your valuable time!

As many of you know I do a quick review of every Xojo release.  I often do a blurbs about updates to our own products.  Occasionally I even rant about things (you should see the posts where I never hit the Publish button!).

When I had a column in Xojo Developer magazine this blog was a convenient place to discuss the ideas from the column.  But writing a reoccurring column is tough.  Keeping a blog going for eleven years seems to be even harder.  I’ve been writing fewer and fewer posts and I’d like to change that trend.

At one point I thought about taking a topic in the Xojo Forums and talking about it in-depth  here.  We’ve been busy doing consulting work so I spend far less time on the forums than I used to but it might be an interesting way to generate new posts.

So, my fellow Xojo developers, what topics would you like to see me tackle?  Topics can include my opinions on the future of Xojo, how’s the 3rd party market doing, why did we choose <x> or <y> over <z>, or anything in between.  I’ll let you be in the drivers seat for while.

Some ground rules:

  • If you’re rude to me, my staff, or Xojo staff I’ll just delete the comment, ban you, and move on.
  • Keep it simple – this is a blog and not a magazine.  Though that doesn’t mean I can’t do a multi-part blog post.
  • I reserve judgement to make more rules as I think of them.  😉

So what topics do you have?

A Xojo Existential Crisis:  When Self is Nil

A couple of Formatted Text Control users found an interesting bug in the Xojo Windows 64-bit compiler.  If the user pasted anything into the control it would hard crash the Windows application.  I spent a couple of days trying to find a workaround and was flummoxed on how to fix.  Thankfully there’s an easy workaround thanks to Team Xojo.

In the Open event of the FTC control we create a new FTCUndoManager instance.  When the user pastes something into the control we pass the existing text into the Undo Manager so it can properly save the before state and allow an undo of the paste.

Pasting text calls the SavePaste method of the FTCUndoManager class.  This is where things start to go wrong.  This method passes Self into the constructor for the FTCUndoPaste class.  Stopping the debugger in this method shows us that self is nil!  What’s odd is several other passed in class objects are nil too (even though they are not at the control level).  That self is nil is indeed a problem since FTCUndoPaste needs the reference to the UndoManager for a variety of reasons.

How can self be nil?  After all this is a method in the class.  By definition self should be non-nil.  I think this would fall under ‘compiler problem’.  I submitted a private Feedback report to Xojo (53967)  and thankfully Xojo reviewed it quickly and were intrigued enough to look into it.  It was verified and a workaround was quickly found.

William from Xojo wrote this:  

There seems to be an issue with passing byval structure parameters (for 64-bit Window build), as a workaround you can pass these byref instead, i.e. MyFunction(…, Byref firstPa as ParagraphAttributes)

So I was able to change two methods, FTCUndoManager.savePaste and FTCUndoPaste.constructor, by using byRef for each object we pass into the Undo Manager into and in the Undo Paste class.  Voila!  Problem solved.

I suspect that FTC is big enough and complex enough to manifest some edge case for the 64-bit compiler.  If you run into an issue like this try this workaround.  And don’t forget to submit a Feedback report to Xojo since the more edge cases they can find the more likely it is they can determine the cause.

Happy Coding!

BKS Shorts 2.0.8

Today we released BKeeney Shorts 2.0.8.  This is a free update to all version 2.0.x users.
Shorts is the award winning reporting tool for Xojo applications.  Shorts allows a Xojo developer to embed a report designer inside in a desktop application, view reports in any resolution on desktop or web applications, save report files to file or to a database, and to export reports to HTML, CSV, and PDF (requires the DynaPDF plugin from MBS).  Shorts works with SQLite, CubeSQL, PostgreSQL, MySQL, MS SQL Server, ODBC, and Informix (requires the SQL plugin from MBS).
Shorts comes as 100% unencrypted Xojo source code.

New:
* DesignerCC.OpenReport now returns its success as a Boolean

Changes:
* Removed FTC and RTF support from Shorts (#3716)
* winReportDesigner.Visible is now default False
* Improvements to winReportDesigner toolbar / tool item handling
* DefaultStyle is now a function returning a consistent default style
* DesignerCC will no longer override the window title – it now raises an event
* Can no longer delete bands outside the band editor by defualt
* PrinterSetup simplifed to fix a UX issue (#3672)
* HandleExportHTML method rewritten to be sandbox friendly
* ReportBKS.ScrubSQLArray replaces conditions with RegEx for consistency
* DBWrapper ensures it’s DBInfo child has an instance of the DB (#3679)
* Designer window now has a File > Close (cmd-w) menu item (#3652)
* Report Template version number incremented due to a JSON change with styles
* Localizations updated

Fixes:
* SetToolbarItem can no longer cause OutOfBoundsException
* French translation of “Text” is no longer “Send a SMS”
* Navigator selection is not lost in rare cases (#3670)
* Changing paper setup no longer creates too many undo levels
* Can no longer enter negative page numbers in the report viewer (#3673)
* Contextual clicking outside of a single selection no longer causes NOE (#3676)
* Reports can no longer be run with no Database Fields to request data, preventing SQL errors
* Fixed image resolving issue (#3687)
* Fixed constant editor window title
* HandleExportHTML no longer causes uncaught exception when cancelling (#3698)
* Filter conditions no longer cause SQL errors with unescaped characters
* Backward compatible styles loading now more robust
* Corrected an issue with server constants and plugins
* Fixed a couple of Mojave drawing glitches.

For more pricing, demo versions, and training videos please visit http://www.bkeeney.com/allproducts/bkeeney-shorts/

Xojo 2018 R3

The latest version of Xojo hit the internet this week.  Release 3 has a number of important new features, some changes, and the usual assortment of big and small bug fixes.  So let’s get to the highlights!

The flashiest new thing in Xojo is that it natively supports macOS 10.14 Mojave.  This means that the entire IDE (as well as all of the peripheral apps like Feedback, Linqua, and the Remote Debug Stub) draws properly when the user has Dark Mode enabled in Mojave.  

Perhaps it’s my older eyes the IDE seems very ‘light’ in color in Light Mode – meaning that there’s a lot of white and grey and the contrast isn’t nearly as prominent as it was in R2 and earlier.  Where some buttons have a slight 3D effect the buttons in R3 are flat with no grey background.  Funny enough, I think the contrast of the IDE in Dark Mode is better.

2018 R2

2018 R3

As a long-time Mac user I’m not entirely sold on Dark Mode.  Some of that is change and that I’m just not used to it yet.  In some respects I feel like I’m reverting to my college PC where light text on a black screen was the norm.  I guess the more things change the more they stay the same.

A new property, SupportsDarkMode was added to the Build Properties section to build apps with Dark Mode enabled.  To help developers the application class has a new event named AppearanceChanged to let them know when the OS has switched between light and dark modes.  

Labels, TextFields, and TextAreas running on Mojave will now use the automatic system colors to get the correct appearance on light and dark modes when text is test to opaque black (0, 0, 0, 255) and backgrounds set to opaque white (255, 255, 255, 255).  In a similar fashion, FillColor, TextColor, and FrameColor now map to proper light/dark system colors.

Since there are many OS colors available than what Xojo provides natively, you might want to look at CSTrueColors by Ulrich Bogun at https://drive.google.com/open?id=1vg-sN8_7mz18zeu9XoRWZaBc8Tm-_Enb.  

Currently Xojo does NOT support Windows dark mode but is looking into it.  A Xojo blog post suggests that Microsoft has released several API’s for dark mode and another one is due in the near future.

Incremental compiling for LLVM/64-bit targets now works.  The first run can still take some time but after that it should only compile changes.  This should significantly reduce cycle times on debugging 64-bit applications.

In Windows Xojo updated the text rendering so that it matches Win32 controls.  I’m just guessing but if Xojo ever moves away from Win32 controls the text rendering will have to change to match.  

Windows is now using the native Win32 Label control.  Overall drawing seems to be significantly faster with this change.

Among the changes is one that might affect a lot of legacy projects (we have a number of these) is that drawing directly to the Graphics property is no longer allowed.  To be explicitly clear about the change this does not affect, in any way, the graphics parameters passed into a canvas or window Paint event, nor does it affect getting the Graphics object from a Picture object.  This only affects the graphics *property* on Canvas and Windows classes.  The fact that it’s continued to work for all this time says that it was definitely time to retire this ‘feature’. 

There is also a list of 79 bug fixes.  Some Windows, Mac, and Linux framework issues fixed.  A couple of changes to MySQLCommunityServer and Postgres.  SQLite was updated.

Xojo 2018 Release 3 isn’t just about Mojave dark mode.  The 64-bit incremental compiling is a most welcome feature.  The speed increases in Windows drawing is also well worth the upgrade.  As always, please test your projects fully before releasing them into the wild.

What is your favorite new feature, change, or bug fix?  Anything causing you problems?  What are your thoughts on Dark Mode and the contrast of colors in the IDE?