There is a thread class:
TNewThread = class(TThread) private procedure Parser_auto_info(var MLQuery: TADOQuery; MTable: TADOTable); protected procedure Execute; override; public MPersent, StartRegion, EndRegion, idHandle: integer; StartThread: boolean; end;
And three instances of these are declared in the public section of the form variables:
var NewThread, NewThread2, NewThread3: TNewThread;
The start of the stream goes like this:
// поток 1 NewThread := TNewThread.Create; with NewThread do begin FreeOnTerminate:=true; Priority:=tpLower; Resume; idHandle:=1; StartRegion:=pos1Region; //1; EndRegion:=54; StartThread:=true; end;
I put the following code on the Close
event of the form:
if NewThread.StartThread then try TerminateThread(NewThread.Handle, 0); finally NewThread.Free; end;
He throws a memory error. I tried to close the stream with the form:
if not Assigned(NewThread) then NewThread.Terminate; FreeAndNil(NewThread);
I tried to register in the destroy event of the form:
NewThread.Free;
But this does not help either. Errors are persistent, due to the fact that the thread (s) closes incorrectly. How to beat this error? Immediately I say that the stream is still working with the database, outputting data to the form (counters and download progress).