Jump to content
uniGUI Discussion Forums
Sign in to follow this  
docjones

Unitimer Error + firebird events

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

Share this post


Link to post
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
      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.

Share this post


Link to post
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.

Share this post


Link to post
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.

 

 

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

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×