我有几个Delphi程序维护与数据库的连接(某些Oracle,某些Firebird。)如果程序在Windows进入睡眠模式时正在运行,则与数据库的连接将丢失。处理这种情况的最佳方法是什么?有没有办法在网络进入睡眠模式之前接收事件,这样我可以尝试更好地处理这种情况?
答案 0 :(得分:6)
要详细说明RRUZ,您需要以下内容:
procedure WMPowerBroadcast(var AMessage: TMessage); message WM_POWERBROADCAST;
在您的表单中。然后WMPowerBroadcast
将是:
procedure TMyForm.WMPowerBroadcast(var AMessage: TMessage);
const
PBT_APMSUSPEND = 4;
PBT_APMRESUMESUSPEND = 7;
begin
case AMessage.WParam of
PBT_APMSUSPEND:
begin
// save your DB stuff. NOTE: IIRC you are pretty limited in the time
// you get to do this - 2 seconds ? may be the limit
end;
PBT_APMRESUMESUSPEND:
begin
// restore your DB connection
end;
else
// you're going to want to handle PBT_APMRESUMECRITICAL (XP and older systems) and PBT_APMRESUMEAUTOMATIC differently
// IIRC you did not get notification of the suspend in this case
end;
end;