Delphi Timer

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Delphi Timer

Mesaj gönderen mia »

can i not disable timer until all procedure has been done ? i have added time into my project with sql data like this

Kod: Tümünü seç

procedure Tusers.sqlrecordTimer(Sender: TObject);
var
 item: TListItem;
begin
  with connectionmo.userslq do
  begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT * FROM `users`');
    Open; // open the query
    LVU.Items.Clear;
    LVU.Items.BeginUpdate;
    try
    while not Eof do begin
    item := LVU.Items.Add;
    Item.Caption := connectionmo.userslq['username'];
  with Item.SubItems do begin
  Add(connectionmo.userslq['item']);
    end;
  Next;
end;
finally
LVU.Items.EndUpdate;
Close; 
sqlrecord.Enabled := False;
end;
end;
end;
i want to not disable timer until all sql record has been added i mean if i have 100000 record or something timer will be finished before grab all data how to avoid that ?
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mussimsek
Admin
Mesajlar: 7603
Kayıt: 10 Haz 2003 12:26
Konum: İstanbul
İletişim:

Re: Delphi Timer

Mesaj gönderen mussimsek »

You could use like this :

Kod: Tümünü seç

try
  Timer1.Enabled := False;
  ...//your sql data codes
finally
  Timer1.Enabled := True;
end;  
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: Delphi Timer

Mesaj gönderen mrmarman »

@mussimsek is right. Regards to him.

Let me say something about database access inside timer event.
Not to do that. :)

I believe you need this, I will show you another way.
- How the handle it without disable Timer. With ByPass timer... :idea:

Kod: Tümünü seç

procedure TForm1.Timer1Timer(Sender: TObject);
Const
{$j+}
  boolWorkDone : Boolean = True; // this is the hatch :)
{$j-}
var
  item: TListItem;
begin
  if NOT boolWorkDone then Exit; // While Database Access working this prevents timer event work until next interval.

  // Hatch closed
  boolWorkDone := FALSE; // this is the trickshot. Provides EXIT command, has seen above.

  with connectionmo.userslq do
  begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT * FROM `users`');
    Open; // open the query
    LVU.Items.Clear;
    LVU.Items.BeginUpdate;
    try
      while not Eof do
      begin
        item := LVU.Items.Add;
        Item.Caption := connectionmo.userslq['username'];
        with Item.SubItems do
        begin
          Add(connectionmo.userslq['item']);
        end;
        Next;
      end; // While
    finally
      LVU.Items.EndUpdate;
      Close;
      sqlrecord.Enabled := False;
    end; // try
  end; // With

  // Hatch opened
  boolWorkDone := True; // this is the trickshot
end;
What is the trick...

Kod: Tümünü seç

Const
{$j+}
  boolWorkDone : Boolean = True; // this is the hatch :)
{$j-}
Be prepared to be confused; with {$j+} and {$j-} directives gives you constant but variable constant.
That means, you may change value of this constant. When the next event interval you have an opportunity to see, the value will be keeping inside the procedure. Like global variables but only this procedure wise. 8)
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: Delphi Timer

Mesaj gönderen mia »

thank you very much guys that's great help and great resource
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Cevapla