Witam szanownych forumowiczów,
mam następujący problem, chcę utworzyć wątek który będzie co określony interwał czasu zapisywał dane do bazy danych w programie mam jeden obiekt klasy TAdoConnection, chciałbym go przekazywać w czasie tworzenia nowego wątku jako parametr, robię z pewnością coś nie tak jak być powinno bo dostaję Access Violation, zamieszczam unit z całym kodem, bardzo bym prosił o sugestię jak rozwiązać ten problem.
unit xthread;
interface
uses
Classes, ADODB, SysUtils;
type
ThreadFotoSave = class(TThread)
private
{ Private declarations }
FADOConnection: TADOConnection;
ADOQuery: TADOQuery;
protected
procedure Execute; override;
public
constructor Create(ADOConnection: TADOConnection);
destructor Destroy; override;
end;
implementation
constructor ThreadFotoSave.Create(ADOConnection: TADOConnection);
begin
inherited Create(False);
FreeOnTerminate := True;
FADOConnection:=ADOConnection;
ADOQuery.Create(nil);
ADOQuery.Connection:=FADOConnection;
ADOQuery.SQL.Add('insert into tab1 (czas)values(:CZAS)');
end;
destructor ThreadFotoSave.Destroy;
begin
ADOQuery.Free;
inherited;
end;
procedure ThreadFotoSave.Execute;
var
I:integer;
begin
ADOQuery.Close;
ADOQuery.Parameters.ParamByName('CZAS').Value:=Date+Time;
ADOQuery.ExecSQL;
end;
end.