Jump to content


Photo

Unitimer Error + firebird events


  • Please log in to reply
3 replies to this topic

#1 docjones

docjones

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 101 posts

Posted 28 April 2015 - 07:10 AM

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.

 

 

Attached Files


  • 0

#2 Farshad Mohajeri

Farshad Mohajeri

    Administrator

  • Administrators
  • 10363 posts

Posted 28 April 2015 - 08:17 AM

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


  • 0

#3 docjones

docjones

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 101 posts

Posted 28 April 2015 - 02:46 PM

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


  • 0

#4 isam

isam

    Member

  • Members
  • PipPip
  • 12 posts

Posted 08 January 2018 - 01:34 PM

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

 


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users