Initial Stages of Porting PopTrayU to Lazarus

Yesterday I started working on trying to port PopTrayU to Free Pascal/Lazarus. The built-in converters seemed to do a good job for the most part, though they did leave hundreds of errors for me to clean up before I could even say it compiled, and its pretty far from, well, working.

But here’s where we’re at right now:

This is the main screen, and it does look fairly close to what it’s supposed to look like, but as you’ll notice, a few key UI items (the toolbars and list of messages) are missing.

On the options screen, things look even worse:

Though I’d be willing to bet that in the end, the problems with the options screen turn out to mostly be cosmetic (a list that needs to be manually repopulated), and that the main screen will turn out to be way more work to get working.

So what issues have I been running into as I port? Thanks for asking.

The CoolTrayIcon component that PopTrayU relies on for the tray icon in the windows tray is super-broken to the point where it was easier to comment out everything relating to the tray icon rather than cobble the Tray Icon component into running skeleton code. The Tray icon relies heavily on Application.Handle and Application.Hook methods to get references to the application to do snazzy things like minimizing to the tray. Those methods are conveniently not available in Lazarus. So I’m going to have to do more research about workarounds for that, because there doesn’t appear to be a straightforward “just do this instead” option.

When the Lazarus porting guide said most of the things that aren’t implemented are “things that are very windows specific” it turns out to be quite the list, and some of those components that are “wontfix” missing components are ones that the app uses.

For example, THotKey has no equivalent. THotKey is a class that hooks into the system settings to set system wide hotkeys to control PopTrayU when you’re using other programs. That’s not to say it can’t be done, but if it can be done the code is probably going to look a lot more ugly. But that’s a low-priority feature compared to say, checking your email and the tray icon being also broken.

I actually came across this handly list that shows which Delphi components do and do not have equivalents in Lazarus. Unfortunately for me, the “not included” list includes TActionManager, TActionToolBar, TPopUpActionBar, and TCustomizeDlg. I may be forgetting others. So basically, in Delphi, all the menus and toolbars used to use Actions to link the menu items to the code it runs when you click on them, and then you could drag and drop menu items into toolbars and vice versa and fully customize the toolbars, which is a really nice to have but not essential feature. Having menus and toolbars is, however, an essential feature, so I’m going to have to check out TToolbar, TActionList (that is available) and TPopupMenu which are candidate replacement classes.

Some of the more straightforward replacements that the auto-code-fixer couldn’t figure out for me were things like:

  • TTabSet -> replace with TTabControl
  • TColorBox -> add import ColorBox
  • GetTime() in SysUtils -> replace w/ Time()

There were also a couple type (struct) definitions that I had to manually add (related to hotkeys), which wasn’t a big deal other than figuring out what was missing.

One of the tricks I found handy for fixing things was keeping Delphi open at the same time and using the “Browse Symbol at Cursor” feature to plug in the name of whatever it was complaining was missing to find out where that was defined, so I could figure out whether it’s an import name that’s missing or something from one of the dependencies or delphi or wherever it’s from.

But overall, most of the issues have been with UI stuff and NOT indy stuff, so it’s looking optimistic that this is a feasible port worth continuing to pursue. I was having a couple minor issues with indy, but I think they’re minor, figuring out where to store the data.

On with the porting!