Jump to content

Unitimer Error + firebird events


docjones
 Share

Recommended Posts

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  IBDatabase1.DatabaseName:=UniServerModule.FilesFolderPath+'TEST.FDB';
  IBDatabase1.LoginPrompt:=FALSE;
  IBDatabase1.Params.CLEAR;
  IBDatabase1.Params.Add('user_name=SYSDBA');
  IBDatabase1.Params.Add('password=masterkey');
  IBDatabase1.Params.Add('lc_ctype=ISO8859_1'); //CHARSET.
  IBDatabase1.Open;
  IBQuery1.open;
  IBEvents1.Registered:=true;
end;



procedure TMainForm.btn_insertClick(Sender: TObject);
var q:TIBQuery;
begin
  //insert a record, then event new_data fired
  try
    q:=TIBQuery.Create(self);
    q.Database:=IBDatabase1;
    q.SQL.add('insert into data (name,author,street) values (:name,:author,:street)');
    q.ParamByName('name').Value:='record '+FormatDateTime('dd/mm/yy hh:nn:ss:zzzz',now);
    q.ParamByName('author').Value:='unigui';
    q.ParamByName('street').Value:='';
    try
      q.ExecSQL;
      q.Transaction.CommitRetaining;
    except
      on e:exception do begin
        ShowMessage('Error '+e.Message);
      end;
    end;

  finally
      q.Free;
  end;

end;



//firebird event. when insert data, start unitimer and refresh data.
procedure TMainForm.IBEvents1EventAlert(Sender: TObject; EventName: string;
  EventCount: Integer; var CancelAlerts: Boolean);
begin
  if EventName='new_data' then begin
      UniTimer1.Enabled:=true;

  end;
end;



procedure TMainForm.UniTimer1Timer(Sender: TObject);
begin
  UniTimer1.Enabled:=falsE;
  //new record inserted, refresh data
  IBQuery1.Close;
  IBQuery1.Open;
end;

Hi

I'm traying refresh query when firebird event is fired. (the firebird event is fired when a record is inserted to table).

 

when firebird event fired,  i call unitimer1.enabled:=true,  to refresh query, but an error ocurrs, see attached error.

 

Unigui pro 0.99.0.1169

ibx components to connect firebird database and manage firebird event. (tested with ibdac and same problem).

firebird 2.5.2 versión.

codegear xe2.

 

i attach a simple example, press button to insert a record, then firebird event is fired.

 

 

post-454-0-74931000-1430204332_thumb.jpg

UNIFBEVENTS.rar

Link to comment
Share on other sites

  • Administrators
//firebird event. when insert data, start unitimer and refresh data.
procedure TMainForm.IBEvents1EventAlert(Sender: TObject; EventName: string;
  EventCount: Integer; var CancelAlerts: Boolean);
begin
  if EventName='new_data' then begin
      UniTimer1.Enabled:=true;
  end;
end;

 

 

IBEvent runs asynchronously in a separate Thread. When there is an event  it tries to send that event to VCL "MainThread" which causes this issue. This method is not compatible with multi-threaded apps.

 

uniGUI components can only be accessed from uniGUI generated events or other events which run within context of an uniGUI generated event.

Link to comment
Share on other sites

//firebird event. when insert data, start unitimer and refresh data.
procedure TMainForm.IBEvents1EventAlert(Sender: TObject; EventName: string;
  EventCount: Integer; var CancelAlerts: Boolean);
begin
  if EventName='new_data' then begin
      LocalFlag:=true
  end;
end;

procedure TMainForm.UniTimer1Timer(Sender: TObject);
begin

  if LocalFlag then begin
      LocalFlag:=False;
      IBQuery1.Close;
      IBQuery1.Open;
  end;

end;

Thanks Farshad, i see... Then to solve this problem, the  easy way is using a local flag, testing it in unitimer.

Link to comment
Share on other sites

  • 2 years later...
//firebird event. when insert data, start unitimer and refresh data.
procedure TMainForm.IBEvents1EventAlert(Sender: TObject; EventName: string;
  EventCount: Integer; var CancelAlerts: Boolean);
begin
  if EventName='new_data' then begin
      LocalFlag:=true
  end;
end;

procedure TMainForm.UniTimer1Timer(Sender: TObject);
begin

  if LocalFlag then begin
      LocalFlag:=False;
      IBQuery1.Close;
      IBQuery1.Open;
  end;

end;

Thanks Farshad, i see... Then to solve this problem, the  easy way is using a local flag, testing it in unitimer.

 

 

//firebird event. when insert data, start unitimer and refresh data.
procedure TMainForm.IBEvents1EventAlert(Sender: TObject; EventName: string;
  EventCount: Integer; var CancelAlerts: Boolean);
begin
  if EventName='new_data' then begin
      LocalFlag:=true
  end;
end;

procedure TMainForm.UniTimer1Timer(Sender: TObject);
begin

  if LocalFlag then begin
      LocalFlag:=False;
      IBQuery1.Close;
      IBQuery1.Open;
  end;

end;

Thanks Farshad, i see... Then to solve this problem, the  easy way is using a local flag, testing it in unitimer.

 

 

 

//firebird event. when insert data, start unitimer and refresh data.
procedure TMainForm.IBEvents1EventAlert(Sender: TObject; EventName: string;
  EventCount: Integer; var CancelAlerts: Boolean);
begin
  if EventName='new_data' then begin
      LocalFlag:=true
  end;
end;

procedure TMainForm.UniTimer1Timer(Sender: TObject);
begin

  if LocalFlag then begin
      LocalFlag:=False;
      IBQuery1.Close;
      IBQuery1.Open;
  end;

end;

Thanks Farshad, i see... Then to solve this problem, the  easy way is using a local flag, testing it in unitimer.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...