docjones Posted April 28, 2015 Posted April 28, 2015 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. UNIFBEVENTS.rar Quote
Administrators Farshad Mohajeri Posted April 28, 2015 Administrators Posted April 28, 2015 //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. Quote
docjones Posted April 28, 2015 Author Posted April 28, 2015 //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. Quote
isam Posted January 8, 2018 Posted January 8, 2018 //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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.