Saturday, June 21, 2008

ti Object persistance framework updated

What's up?

v2.50 of tiOPF is now available at http://tiopf.sourceforge.net/

So what's tiOPF?

tiOPF is a Object Persistence Framework. That is, it is a framework based around saving your objects to, and loading them from, databases and/or flat files. See the overview for more details.

In a nutshell it lets you do things like:

var
user: TMyuser;
userList: TUserList;
...

user:= Tuser.CreateNew;
user.FirstName:= 'Sean';
user.LastName:= 'cross';

user.Save;

...
userList:= TUserList.Create;
userList.Load;

for user in userList do
...


tiOPF handles the saving and loading of objects to databases and flat files. You can swap between databases by initialising a new persistence layer.


Why should I care?

  • tiOPF lets you code in objects rather than datasets (you can still use data aware controls though). This gives you more object orientated code
  • tiOPF provides database independance
  • Better code reuse. Because the persistance is separated out, you can use the same code across different databases and structures
  • Easier unit testing (in my experience anyway). I find it much easier to setup objects and test them that to setup databases and test.

Links

Home page: http://tiopf.sourceforge.net/
Overview: http://tiopf.sourceforge.net/Doc/overview/index.shtml
Newsgroups: http://tiopf.sourceforge.net/Support.shtml

Thursday, June 12, 2008

" Connection is busy with results for another hstmt"

One of the problems with working on the same program for years, is that you always end up paying for your sins. In my case the sin in question is still using the bde and odbc.

"Connection is busy with results for another hstmt" is a common error when connecting to ODBC databases. It occurs because an OBDC connection can only have one active cursor at a time. By default, odbc only retrieves the first 20 records for a query. If the query contains more than 20 records, the rest are retrieved on demand. That's all very well, but when you open a second query using same connection/session you get the dreaded hstmt error.

I thought I had beaten it years ago, but my latest set of changes have resulted in the error reappearing.

There are a few possible solutions to this error:
  1. Use TTable components. These don't have the error as they open a new connection each time. Not a very pretty solution :(
  2. Put a FetchAll after each Open. This forces the retrieval of all records. Not practical in my case as I have around 250 tquery components to check.
  3. Use multiple connections. Also not practical for me.
  4. Replace the BDE with something else that doesn't have the problem. In progress but...
  5. Cheat. Set the odbc rowset size to a larger number. If you set it to 200, then the first 200 records will be returned. If you set it to -1 then ALL records will be returned. This could have dire effects on performance if your queries return a lot of records.
This time round I discovered, and went with option 5.

To set the rowset size with the BDE, do the following:
  1. Click on your TDatabase component
  2. In the object inspector, expand Params
  3. Put in a Key of "ROWSET SIZE"
  4. Put in the desired value
Changing the rowset size should work with other odbc connection components as well.

Update: As Otto has pointed out, the error can also be resolved, if you are using sql server 2005 or later, by using the SQL Native Client drivers. See Multiple Active Record Sets for more details. Doesn't help me though :(

Sunday, June 8, 2008

Coverflow update

TMS GUIMotions

TMS Software have released their 3d animation component, GUIMotions. It includes a number of animations including a coverflow effect. More info is available here.

My GLScene example

I have updated my coverflow example. I have included mirroring, multiple rows, vertical layout and a few other changes making easier to be reused. I have also shown how to use standard vcl controls.

You can download the latest version from here.






Using an editable TMemo control


2x2, Transitioning from horizontal to vertical layout


Vertical layout, 2 across


Horizontal layout 2 across

Links
GuiMotions
GLScene coverflow demo
GLScene