यह प्रश्न प्रारंभिक रूप से कल्पना की तुलना में बहुत अधिक जटिल है; जो इसे एक अच्छा सवाल बनाता है।
प्रारंभ में मैंने सोचा था कि एप्लिकेशन.प्रोसेसेमेसेस सही तरीका था, हालांकि यह एक संभावित खनन क्षेत्र है जब तक कि आप सावधान न हों (धन्यवाद @skamradt इसे इंगित करने के लिए धन्यवाद)। यह एक अवरुद्ध कॉल के साथ भी मदद नहीं करता है।
एक पृष्ठभूमि थ्रेड की आवश्यकता निम्नानुसार है: ( त्रुटियों को इंगित करने के लिए धन्यवाद @mghie अब हल हो गए हैं)। डेटाबेस थ्रेड को अलग-अलग धागे में कॉल करने के साथ अभी भी समस्याएं हो सकती हैं - इसलिए पृष्ठभूमि थ्रेड को इस ऑपरेशन के लिए अपना डेटाबेस कनेक्शन होना चाहिए (यदि व्यावहारिक हो)।
नीचे दिए गए उदाहरण में मैंने विशेष रूप से प्रगति विंडो बनाने और नष्ट करने के लिए कोड नहीं दिखाया है क्योंकि यह कोड को और भी लंबा कर देगा, और यह करना आसान है।
सबसे पहले पृष्ठभूमि धागा प्रश्न पर कार्रवाई करने:
तो हम दो वस्तुओं ऐसा करने की जरूरत है।
unit BackgroundProcess;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, windows;
const
WM_MY_BACKGROUNDNOTIFY = WM_USER + 555; { change this }
NOTIFY_BEGIN = 22;
NOTIFY_END = 33;
type
TBackgroundQueryThread = class(TThread)
private
hwndnotify : HWND;
protected
procedure Execute; override;
public
constructor Create(owner: TForm);
end;
implementation
constructor TBackgroundQueryThread.Create(owner: TForm) ;
begin
inherited Create(False);
hwndnotify := owner.Handle;
FreeOnTerminate := true;
resume;
end;
procedure TBackgroundQueryThread.Execute;
begin
PostMessage(hwndnotify, WM_MY_BACKGROUNDNOTIFY, NOTIFY_BEGIN, 0);
Sleep(2000); (* Query goes here. *)
PostMessage(hwndnotify, WM_MY_BACKGROUNDNOTIFY, NOTIFY_END, 0);
end;
end.
रूप है कि क्वेरी का आह्वान:
unit mainform;
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls, windows, BackgroundProcess;
type
TForm1 = class(TForm)
private
frm : tFrmPopupElapsed;
{ private declarations }
procedure OnMyBackgrounNotify(var Msg: TMessage); message WM_MY_BACKGROUNDNOTIFY;
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
procedure TForm1.OnMyBackgrounNotify(var Msg: TMessage);
begin
if (msg.WParam = NOTIFY_BEGIN) THEN
BEGIN
if (frm = nil) THEN
BEGIN
frm := tFrmPopupElapsed.Create(nil);
frm.Init; // this procedure enables the timer
frm.Show();
END;
END;
if (msg.WParam = NOTIFY_END) THEN
BEGIN
if (frm <> nil) THEN
BEGIN
frm.Close;
END;
END;
end;
end.
क्या डेटाबेस? कम से कम एक जिसे मैं जानता हूं (डीबीआईएसएएम/एलिवेट डीबी) उनके क्वेरी घटक पर एक बहुत ही आसान ऑनप्रोशेशन इवेंट प्रदान करता है। आप अपने समय में रिपोर्ट कर सकते हैं, प्रतिशत पूर्ण, आदि –
छोटे सुझाव: मैं 'frm.Init' – mjn
से पहले 'try' डाल दूंगा नोट करें कि' frm.Close' को कॉल करने से फॉर्म मेमोरी लीक हो जाएगा एक 'ऑनक्लोस' हैंडलर है जो 'caFree' सेट करता है। 'Frm.Release' का उपयोग करना अधिक सुरक्षित होगा। – mghie