@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...
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.
