As I mentioned previously, I have been experimenting with integrating our application with Maximizer CRM. Working with their SDK, it doesn’t take long to figure out that the com interfaces were designed with VB and C++ programmers in mind. Most of it works with VFP, but there are a few exceptions. I ran into a problem with an interface that accepts a variant variable by reference. I was surprised to find out that Fox can’t create a variant.
Shirley I can’t be serious? Everyone knows that all variables in Fox are variants. While that may be true, Fox can’t create a variable of type variant that can be passed to com components. Fox always assigns a type to a variable. Even a simple local myvariable statement creates a logical variable. Attempting to pass the variable by reference to a com component may result in a “type mismatch” error.
This isn’t entirely Fox’s fault. After all, should a COM component assume that the calling environment can create a variant? Microsoft concedes this is a problem in C++ with MFC components and recommends using ATL instead (see link below).
So, what can you do if you run into this situation? Ideally, the COM interface would be changed not to use variants, but I doubt Maximizer will change their interfaces, in place for years, just so I can use VFP. VB does allow you to create variables of type variant, so I created a VB wrapper component. VFP passes a string to the VB component, the VB component converts that to a variant and passes it to the Maximizer component. It’s not an ideal solution, but it works.
Prb: ActiveX controls passing variant* back to VFP cause error
I ran across something interesting (albeit of limited use) recently. We are considering integrating Maximizer CRM with our software, and I’ve been doing some proof-of-concept work along those lines. One thing about CRM software creators is they know they won’t be replacing your core line of business applications, so they make sure there are plenty of ways to integrate with those apps. Maximizer is no exception, and being around for quite a few years now, it includes some old-school (but new to me) integration techniques.
The first thing I wanted to do was import some Fox data into Maximizer. While older products often included native support for dbase and FoxPro 2.x tables, virtually no products supported Visual FoxPro natively, so I was surprised to see FoxPro 3.0 in the list. I use VFP 9.0, but I haven’t made use of any of the new database features added in versions 7.0 – 9.0. So, I gave it a try and it worked like a charm. “Wow, that was easy”, I thought, “I wish Microsoft products supported their own database this well.”
Well, it turns out, they used to. To my surprise, this all led me to the fact that DAO 3.5 had native support for Visual FoxPro tables. DAO (data access objects) was Microsoft’s data technology that preceded ado (ActiveX data objects) and was popular with access and VB developers at the time. It is now deprecated, but some access developers still favor it over newer technologies. It has been my assumption that Microsoft access got its name because it could “access” multiple databases in addition to its own jet database. It has done this by means of “ISAM filters” for other databases, including FoxPro. DAO 3.5 included a filter for Visual FoxPro.
Eventually, ado came along and superseded DAO as the recommended way to access data. The ISAM filters became part of the Microsoft jet 4.0 engine, but the FoxPro filters were no longer included in the package. WTF? Yet another slight against our beloved Fox? Perhaps, but also consider this: the ISAM filters suck. While I am sure they work fine for FoxPro 2.x data, the VFP filters are limited and give you read-only access to data. Compared to the FoxPro ODBC drivers, which give full read/write access as well as much improved performance, it became apparent that ODBC was the preferred way to access FoxPro data and I assume that’s why the ISAM filters were removed.
While I would never recommend DAO for new development, we often find ourselves working with older systems and technology. It’s interesting what you run across.
Here’s a little goodie for readers of my blog. I have several grids that contain a checkbox column to select items in the grid. I wanted an easy, consistent way to select/deselect all checkboxes in the column, so I created a custom grid header class to do that. hdrCheckBox.zip is attached (Download).
I initially tried to use a standard checkbox. VFP doesn’t let you put a control inside a header, so I tried to overlay it on the grid. That turned out to be too flaky and limited, so I opted to use pictures of a checked and unchecked box, which VFP does do. The only downside is that the checkbox is a themed control, and Windows XP checkboxes may look slightly different than pictures of the Windows Vista checkboxes I used. Still, I think the checkbox will look good in any theme.
Another limitation is that the header cannot receive focus like a real checkbox, so no keyboard support. To get around that, the header Click() is performed when the user presses “A” while the grid column has focus. I actually tried to use Ctrl+A, but KeyPress() would not detect that combination, I assume because it’s already assigned to the Edit menu.
To make sure the user would know that they could check the box, I put a tooltip on the grid header. Header tooltips don’t work in VFP9 SP2, so I had to put some workaround code in the class to make the grid tooltip appear. Hopefully, Microsoft will eventually release a fix for this, but I’m not holding my breath.
To use the class:
- Change the column HeaderClass to hdrCheckBox in hdrCheckBox.prg. You may already be done.
- If you want the box to be checked initially, change the Value property to .T. Even though this is a PRG-based class, you can use the property sheet and override methods on the form just like you would with any class. NOTE: Setting this initial value will not check all the boxes in the grid. You will need to do that in the Grid.RecordSource query.
- If you want to change the header checkbox back to its original value (for example, if you requery the grid), then call the Reset() method on the class.
- Another VFP9 SP2 bug! If you open this form from the menu, you have to use the menu “Procedure” to open the form instead of “Command”. Otherwise, VFP9 will crash when you open the form. See Emerson Reed’s blog entry for more info.
Here are the requirements to use the class (which, of course, you could change):
- Grid.RecordSource is required.
- Column.ControlSource is required.
- The column field must be a logical field.
- Column.CurrentControl must be a checkbox.
Disclaimer: This code is provided AS-IS. If it doesn’t work for you, fix it!
Rewind to 2004 when VFP 9.0 was in beta. Microsoft added the ability to bind to windows events from FoxPro. The first thing that came to my mind was the ability to hook into VFP IDE windows. I like to work with my code windows maximized and with several windows open at the same time. Constantly going to the VFP window menu to switch windows got tedious. If I could create something like the windows task bar for the VFP ide, that would make life easier and probably be valuable to other people as well. So, I started to ask around about how this could be accomplished. Calvin Hsia put together a sample that he showed at his advisor DevCon (2004?) session. It is now part of the VFP 9 solution samples. I used that as the basis for my utility, and “FoxTaskbar” was born.
I learned a lot about windows events and the FoxPro window system, but I also learned how to crash VFP frequently. Alas, I couldn’t get FoxTaskbar to function stably. After several attempts, I eventually retreated from binding to windows events and tried to use fox’s standard windowing system. I couldn’t get that to work well either, so FoxTaskbar never saw the light of day.
Fortunately, Scott Scovell and Craig Bailey were working on an almost identical tool called “FoxTabs”. Even the internal architecture was similar to FoxTaskbar. I guess great minds think alike <g>, but greater minds actually make it work, and that’s what Scott and Craig did. FoxTabs does exactly what I wanted with FoxTaskbar, and as a bonus, it doesn’t crash VFP every 30 seconds <g>.
In the meantime, Craig and Scott have moved on to other things (Craig is currently looking for his next big adventure), so FoxTabs hasn’t been in development for a couple of years. I had some issues with it, so I recently contacted Craig to see if FoxTabs was still in development. Neither Craig nor Scott has time to continue working on it, so they graciously offered to turn the project over to VFPX. I volunteered to be the project manager, and FoxTabs is now in development again.
FoxTabs 0.5 is now available on the VFPX web site. Please download and start using this handy little utility and help us get to a 1.0 release. I’ve already received bug reports from several developers (that’s a good thing <g>) and progress is being made. Please report any bugs you find on the VFPX issue tracker, and be sure to include “FoxTabs” in the title.
After the excitement of the Southwest Fox conference, I decided to get more involved in VFP community efforts and start a blog. Confession… That was how I felt after SW Fox 2007. A year and another excellent SW Fox conference later, I’m finally getting around to doing it. So, here it is. The content will be mostly fox related, forward looking, and hopefully relevant to you. If I have my way, it will be updated on a regular basis. Enjoy!