I think the same functions are in Lazarus as in Delphi right ?
i.e.

Somewhere global
var
  aThreadLock : TRTLCriticalSection ;

In any procedure that calls the treadlist or tread actions that must
finish before anny other actions take place you can use structures like
this.


        EnterCriticalSection(aThreadLock );
        try
          try
           tablo:=TSqlite3Dataset.Create(Nil);
           tablo.FileName:='db/services.db';
           tablo.SQL:= 'select type_name, server_ip from servers where
id='+ inttostr( record_id) ;
           tablo.Active:=True; 
           type_name:= tablo.FieldByName('type_name').AsString;
           server_ip:= tablo.FieldByName('server_ip').AsString;
          except 
 
main.StatusBar1.SimpleText:='thread1'+tablo.SqliteReturnString+tablo.SQL
;
          end;
        finally
          LeaveCriticalSection(aThreadLock );
        end;
 end;


I also gess lazars has the same Synchronize function like the one in
Delphi

There you get this hint tekst

"Important: Methods and properties of objects in visual components can
only be
  used in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure ADSLUpdThread.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end;"


Met vriendelijke groet, 
Pieter Valentijn
 
Delphidreams
http://www.delphidreams.nl
 


-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Verzonden: donderdag 18 januari 2007 10:59
Aan: [email protected]
Onderwerp: [lazarus] sqlite in thread


Hi,
Firstly sorry for waste of your time.
Sqlite working in thread very good.

here is the thread execute procedure.

Thanks. (specially luiz)


procedure TMyThread.Execute;
var
ping: TPingSend;
record_id : integer;
type_name, server_ip, result_string : String;
tablo: TSqlite3Dataset;

begin
record_id:= main.id;
result_string:='default';
server_ip:='default';

try
tablo:=TSqlite3Dataset.Create(Nil);
tablo.FileName:='db/services.db';
tablo.SQL:= 'select type_name, server_ip from servers where id='+
inttostr( record_id) ; tablo.Active:=True; type_name:=
tablo.FieldByName('type_name').AsString;
server_ip:= tablo.FieldByName('server_ip').AsString;
except
main.StatusBar1.SimpleText:='thread1'+tablo.SqliteReturnString+tablo.SQL
;
end;

//Controlling by type
//ping
if (type_name='ping') and (server_ip<>'default')  then
begin
     ping:=TPingSend.Create;
     try
        ping.ping(server_ip);
        result_string:= result_string +' - '+
IntTostr(ping.pingtime)+'ms';
     finally
        ping.Free;
     end;
end;

if result_string<>'default' then
begin
  try
   tablo.ExecSQL( 'update servers set status="'+ result_string +'" where
id='+ inttostr( record_id) );
  except
  main.StatusBar1.SimpleText:='thread2'+tablo.SqliteReturnString;
  end;
end;


tablo.Close;
tablo.Free;

end;


_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to