2

I am using Synapse for Delphi, but when during HTTP downloads, of course, the GUI freezes. Looking at the documentation, they suggest using the OnHeartbeat method.

(See http://www.ararat.cz/synapse/doku.php/public:howto:heartbeat )

Unfortunately, they don't actually give any code example, and while the concept is simple, the usage is non-obvious.

Is this a per socket (object) setting, or a per application (class) setting? Also, The callback procedure itself is defined as an object, which is a bit unusual. Is anyone who has actually used this willing to share a sample code snippit?

Thom A
  • 88,727
  • 11
  • 45
  • 75
Noah
  • 998
  • 1
  • 12
  • 22

1 Answers1

2

Although I would suggest running your download in a seperate thread, reading the documentation you'd have to hook a event handler to the OnHeartBeat event.

In that event handler, you could call Application.ProcessMessages() but that is just dangerous due to the possibility of events being fired before you'd actually want them. I would use a custom method to invoke the Paint routine only. You could just pass the handle of your form as parameter, or cast any control to a TWinControl and use the handle property. This will just repaint the form/control, but not allow mouse/keyboard interaction.

procedure AllowRepaints(h: HWND);
var
  m: tMsg;
begin
  while PeekMessage(m, h, WM_PAINT, WM_PAINT, PM_REMOVE) do
    DispatchMessage(m);
end;
Davy Landman
  • 15,109
  • 6
  • 49
  • 73
  • Heh, I've had issues getting threads to work reliably across Windows/MacOS/Windows sometimes, so I took the simpler way and went even farther, and just use another *process* for the internet calls, but thank you for the sample, I think many people will find it useful. – Noah Mar 03 '11 at 02:26
  • "..., reading the documentation you'd have to hook a event handler to the OnHeartBeat event." This is exactly what I was looking for code to do. (Note that I am not using the visual components). – Noah Mar 21 '11 at 12:07