« August 2006 | Main | October 2006 »
September 30, 2006
Enhanced Delphi DBImage replacement (handles wmf, emf and jpg)
Sebastian Mayora has created an excellent replacement for the DBImage control. EDBImage handles all the image formats that DBImage does PLUS jpg, wmf and emf as well. Download it here.
Posted by daen at 09:19 AM | Comments (0)
Catching dataset updates in Delphi
When you navigate away from an inserted or edited record in a DataSet in Delphi, an implicit post will occur before the navigation. Sometimes, it's useful to be able to trap that and handle it in different ways. For example, you might want to ask the user if they want to save or discard the changes, or cancel the navigation and keep making changes to the current record (they might just have hit the wrong key or clicked on the wrong spot with the mouse). The bad news is that it's far from clear how to do this in the Delphi documentation. The good news is that it turns out to be pretty simple to do.
The trick lies in using a special exception called EAbort (defined along with a load of other exceptions in SysUtils). EAbort is special because it doesn't display a dialog message in the default exception handler - it's "silent". The place to do this is in the DataSet's BeforePost event handler. Throwing the EAbort simply pulls the rug from under the whole record update machinery. There's a handy procedure called Abort which will throw EAbort for you.
procedure TForm1.CDSBeforePost(DataSet: TDataSet);
begin
with DataSet as TClientDataSet do
begin
if DataSet.Modified then
begin
case MessageDlg('Save (yes) discard (no)'+
'or continue editing (cancel)?',
mtWarning,mbYesNoCancel,0) of
mrNo:
begin
Cancel;
Abort;
end;
mrCancel:
begin
Abort;
end;
end;
end;
end;
end;
There's one extra twist (not shown here) where implicit posts (generated by navigation and insert/delete events) need to be handled differently from explicit posts. This requires a boolean ExplicitPost flag that is set anytime before you call DataSet.Post from your code, and in the DBNavigator.BeforeAction event handler for the nbPost button. The flag is cleared in a transition to dsEdit or dsInsert which can be done in DataSource.OnStateChange. Then, in the DataSet.BeforePost event handler, the flag is checked and if set, the warning message is not displayed. This is not so clean, because you need to remember to set this flag before every explicit Post.
Thanks to Zarko Gajic at delphi.about.com for writing the article that put me on the right track.
Posted by daen at 08:47 AM | Comments (0)
September 27, 2006
Lookalikes #3
![]() |
![]() |
| Mr Incredible | Jan Gintberg |
Posted by daen at 10:57 PM | Comments (0)
September 25, 2006
Game Tester
IO Interactive are advertising for game testers. This is a job that I would have killed for 20 years ago. Being paid by the hour to test new games. How come these things never come up when you want them to? I don't have the interest or the concentration these days ...
GAME TESTER for Hardware Compliance and NetworkIO is looking for a game tester for an upcoming new title with specific responsibilities for hardware compliance and network testing (PC). You don't have to be a hardcore gamer, but an interest in games is clearly an advantage. You are hourly paid with various working hours as required.
Several Dilbert strips come to mind for this ...
Posted by daen at 07:08 PM | Comments (0)
September 11, 2006
Tycho Brahe's moose
Tycho Brahe once owned a pet moose which died after it drank too much beer at a party and fell down the castle steps.
Posted by daen at 10:44 PM | Comments (0)

