Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LOCATE VS REFRESH 1

Status
Not open for further replies.

PERMAL

Programmer
Jul 8, 2011
2
IT
I need to continuosly check a table record to find whether a column be modified from outside.

MY ENVIRONMENT IS Delphi5
PrMod is TCB4Table
Data are stored in DB3 Table


As far as I conceive I have two chanches

1) first locate and then loop refresh

PrMod.Locate('POSTAZIONE',isKeyPrmod,[]);
while (PrMod.FieldByName('COMANDO').AsString='X') do begin
PrMod.Refresh;
Application.ProcessMessages;
Sleep(20);
end;

2) Continuosly locate

repeat
PrMod.Locate('POSTAZIONE',isKeyPrmod,[]);
Application.ProcessMessages;
Sleep(20);
until (PrMod.FieldByName('COMANDO').AsString='X');



which of the two less charges my Server ?
 
Does your database support views? If so, connect PrMod to a view which pulls only the data you need, rather than the entire table. Depending on how many records are in the table, this may make the refresh much faster. Although I cannot tell you which methods will cost less without actually testing each methods...

Also, I'd say your sleep(20) is rather extreme. There are two sleep routines in Delphi (one each in SysUtils and Windows units, the one it uses probably depends on which one appears first in your uses clause) both take the number of milliseconds to sleep. With 1000 milliseconds in 1 second, that means the routine will run 50 times each second.

if the 20 ms is so that your application remains responsive, (assuming this code runs in the main thread) what you can do instead is combine a counter with the sleep.

Code:
var
   I:  integer;
begin
   I := 0;
   while (PrMod.FieldByName('COMANDO').AsString='X') do 
   begin
      if I = 50 then
      begin
         PrMod.Refresh;
         I := 0;
      end
      else
         Inc(I);
      Application.ProcessMessages;
      Sleep(20);
   end;
end;

Now the refresh only executes ~ once per second, and your application still remains responsive..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top