MOGSY Posted December 30, 2021 Share Posted December 30, 2021 Hi I would appreciate an example of multi thread data base access example for Firedac. Regards Quote Link to comment Share on other sites More sharing options...
Tokay Posted December 30, 2021 Share Posted December 30, 2021 type THelpThread = class(TThread) private FSessionName: string; FDataSource: TDataSource; FSQL: string; protected procedure Execute; override; public property DataSource: TDataSource Read FDataSource Write FDataSource; property SessionName: string Read FSessionName Write FSessionName; property SQL: string Read FSQL Write FSQL; end; { THelpThread } procedure THelpThread.Execute; var Session: TUniGUISession; MainModule: TUniMainModule; i: integer; begin inherited; MakeQuery(FDataSource.DataSet as TFDQuery, FSQL, True); FDataSource.DataSet.Last; FDataSource.DataSet.First; Session := UniServerModule.GetSession(SessionName); MainModule := TUniMainModule(Session.UniApplication.UniMainModule); with TUniForm2(MainModule.GetFormInstance(TUniForm2)) do UniDBGrid1.DataSource := FDataSource end; This code works for me. Quote Link to comment Share on other sites More sharing options...
MOGSY Posted December 31, 2021 Author Share Posted December 31, 2021 Hi Tokay Thank you very much for your reply. Will the following function is running outside of the thread? MakeQuery(FDataSource.DataSet as TFDQuery, FSQL, True); Regards Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted December 31, 2021 Share Posted December 31, 2021 I think this code is not thread safe... Quote Link to comment Share on other sites More sharing options...
MOGSY Posted December 31, 2021 Author Share Posted December 31, 2021 I believe a working multi threaded Firedac code will be useful for all Unigui users. Quote Link to comment Share on other sites More sharing options...
rgreat Posted December 31, 2021 Share Posted December 31, 2021 Just create all firedac components from inside thread and work as usual. Quote Link to comment Share on other sites More sharing options...
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.