Tokay Posted April 26, 2020 Share Posted April 26, 2020 I was constantly missing feature of find defined session. It very important in some cases. I show you idea (if I understand all properly): unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Uni, uniGUITypes, uniGUIAbstractClasses, uniGUIClasses, uniGUIRegClasses, uniGUIForm; //this case shows how to run a long query without stopping the interface //additional thread for query type THelpThread = class(TThread) private FQuery: TUniQuery; FSessionName: string; protected procedure Execute; override; public property Query: TUniQuery Read FQuery Write FQuery; property SessionName: string Read FSessionName Write FSessionName; end; type TMainForm = class(TUniForm) UniQuery1: TUniQuery; UniDataSource1: TUniDataSource; UniDBGrid1: TUniDBGrid; private FThread: THelpThread; procedure Thread1Finish(Sender: TObject); procedure StartCalcThread(const s: string); procedure AssignDataSet; { Private declarations } public { Public declarations } end; function MainForm: TMainForm; implementation {$R *.dfm} uses uniGUIVars, MainModule, uniGUIApplication; function MainForm: TMainForm; begin Result := TMainForm(UniMainModule.GetFormInstance(TMainForm)); end; { THelpThread } procedure THelpThread.Execute; begin inherited; if Query.State <> dsInactive then Query.Close; if not Query.Transaction.Active then Query.Transaction.StartTransaction; Query.Open; end; { TMainForm } procedure TMainForm.StartCalcThread(const s: string); begin //startin of query thread if not Assigned(FThread) then begin //the query UniQuery1.SQL.Clear; UniQuery1.SQL.Add('select MAPS.MAPS_SOURCE,'); UniQuery1.SQL.Add(s); UniQuery1.SQL.Add('from MAPS'); UniQuery1.SQL.Add('group by MAPS_SOURCE'); UniQuery1.SQL.Add('union'); UniQuery1.SQL.Add('select "all",'); UniQuery1.SQL.Add(s); UniQuery1.SQL.Add('from MAPS'); //off the grid DataSource UniDBGrid1.DataSource := nil; FThread := THelpThread.Create(True); FThread.Query := UniQuery1; FThread.OnTerminate := Thread1Finish; FThread.FreeOnTerminate := True; //store the session ID {!!!!} FThread.SessionName := UniSession.SessionId; //start querying FThread.Start; end; end; procedure TMainForm.Thread1Finish(Sender: TObject); begin //sync assigned of dataset with the grid TThread.Synchronize(nil, AssignDataSet); FThread := nil; end; procedure TMainForm.AssignDataSet; var Session: TUniGUISession; lMainModule: TUniMainModule; begin //find session by ID {!!!!} Session := UniServerModule.GetSession(FThread.SessionName); //get defined MainModule of session lMainModule := TUniMainModule(Session.UniApplication.UniMainModule); //get defined MainForm of session with TMainForm(lMainModule.GetFormInstance(TMainForm)) do //assigne dataset and DataSource with grid UniDBGrid1.DataSource := UniDataSource1; end; initialization RegisterAppFormClass(TMainForm); end. 2 Quote Link to comment Share on other sites More sharing options...
Freeman35 Posted April 27, 2020 Share Posted April 27, 2020 Thank you. Quote Link to comment Share on other sites More sharing options...
Tokay Posted April 27, 2020 Author Share Posted April 27, 2020 If I understand correctly, it could fix old and ugly issue "Attempt to access nil session reference". At least partially. You can store your current session ID and get it later in any code. Quote Link to comment Share on other sites More sharing options...
Freeman35 Posted April 27, 2020 Share Posted April 27, 2020 I'll try send message session to session. maybe can chat application . Quote Link to comment Share on other sites More sharing options...
Tokay Posted April 27, 2020 Author Share Posted April 27, 2020 It's very interesting and usefull! Quote Link to comment Share on other sites More sharing options...
eduardosuruagy Posted April 28, 2020 Share Posted April 28, 2020 On 4/26/2020 at 6:38 PM, Tokay said: I was constantly missing feature of find defined session. It very important in some cases. I show you idea (if I understand all properly): unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Uni, uniGUITypes, uniGUIAbstractClasses, uniGUIClasses, uniGUIRegClasses, uniGUIForm; //this case shows how to run a long query without stopping the interface //additional thread for query type THelpThread = class(TThread) private FQuery: TUniQuery; FSessionName: string; protected procedure Execute; override; public property Query: TUniQuery Read FQuery Write FQuery; property SessionName: string Read FSessionName Write FSessionName; end; type TMainForm = class(TUniForm) UniQuery1: TUniQuery; UniDataSource1: TUniDataSource; UniDBGrid1: TUniDBGrid; private FThread: THelpThread; procedure Thread1Finish(Sender: TObject); procedure StartCalcThread(const s: string); procedure AssignDataSet; { Private declarations } public { Public declarations } end; function MainForm: TMainForm; implementation {$R *.dfm} uses uniGUIVars, MainModule, uniGUIApplication; function MainForm: TMainForm; begin Result := TMainForm(UniMainModule.GetFormInstance(TMainForm)); end; procedure TMainForm.StartCalcThread(const s: string); begin //startin of query thread if not Assigned(FThread) then begin //the query UniQuery1.SQL.Clear; UniQuery1.SQL.Add('select MAPS.MAPS_SOURCE,'); UniQuery1.SQL.Add(s); UniQuery1.SQL.Add('from MAPS'); UniQuery1.SQL.Add('group by MAPS_SOURCE'); UniQuery1.SQL.Add('union'); UniQuery1.SQL.Add('select "all",'); UniQuery1.SQL.Add(s); UniQuery1.SQL.Add('from MAPS'); //off the grid DataSource UniDBGrid1.DataSource := nil; FThread := THelpThread.Create(True); FThread.Query := UniQuery1; FThread.OnTerminate := Thread1Finish; FThread.FreeOnTerminate := True; //store the session ID {!!!!} FThread.SessionName := UniSession.SessionId; //start querying FThread.Start; end; end; procedure TMainForm.Thread1Finish(Sender: TObject); begin //sync assigned of dataset with the grid TThread.Synchronize(nil, AssignDataSet); FThread := nil; end; procedure TMainForm.AssignDataSet; var Session: TUniGUISession; lMainModule: TUniMainModule; begin //find session by ID {!!!!} Session := UniServerModule.GetSession(FThread.SessionName); //get defined MainModule of session lMainModule := TUniMainModule(Session.UniApplication.UniMainModule); //get defined MainForm of session with TMainForm(lMainModule.GetFormInstance(TMainForm)) do //assigne dataset and DataSource with grid UniDBGrid1.DataSource := UniDataSource1; end; initialization RegisterAppFormClass(TMainForm); end. I tried to simulate your example here, but I didn't find this TUniQuery component Quote Link to comment Share on other sites More sharing options...
picyka Posted April 28, 2020 Share Posted April 28, 2020 9 minutes ago, eduardosuruagy said: I tried to simulate your example here, but I didn't find this TUniQuery component Unidac. Quote Link to comment Share on other sites More sharing options...
eduardosuruagy Posted April 28, 2020 Share Posted April 28, 2020 3 minutes ago, picyka said: Unidac. Is this example complete? Quote Link to comment Share on other sites More sharing options...
picyka Posted April 28, 2020 Share Posted April 28, 2020 1 minute ago, eduardosuruagy said: Is this example complete? TUniQuery switch to TFDQuery for example Quote Link to comment Share on other sites More sharing options...
eduardosuruagy Posted April 28, 2020 Share Posted April 28, 2020 At what time do I run the query Quote Link to comment Share on other sites More sharing options...
Tokay Posted April 28, 2020 Author Share Posted April 28, 2020 37 minutes ago, eduardosuruagy said: At what time do I run the query At what you need. For example: at show time. Quote Link to comment Share on other sites More sharing options...
eduardosuruagy Posted April 28, 2020 Share Posted April 28, 2020 18 minutes ago, Tokay said: At what you need. For example: at show time. I tried to make your code work but I was unsuccessful. I changed TUniQuery to TFDQuery and it still didn't work. Quote Link to comment Share on other sites More sharing options...
Tokay Posted April 28, 2020 Author Share Posted April 28, 2020 Hmmm, It's strange. I'll try with TFDQuery here. Quote Link to comment Share on other sites More sharing options...
eduardosuruagy Posted April 28, 2020 Share Posted April 28, 2020 Thank you!! Quote Link to comment Share on other sites More sharing options...
Tokay Posted April 28, 2020 Author Share Posted April 28, 2020 I forgot the Execute Method, and have added to the code. Works fine here with TFDQuery too Quote Link to comment Share on other sites More sharing options...
eduardosuruagy Posted April 29, 2020 Share Posted April 29, 2020 On 27/04/2020 at 08:18, Freeman35 said: Vou tentar enviar uma mensagem para outra. talvez possa conversar aplicativo. Were you able to chat with another application? Quote Link to comment Share on other sites More sharing options...
Freeman35 Posted April 29, 2020 Share Posted April 29, 2020 22 hours ago, eduardosuruagy said: //find session by ID {!!!!} Session := UniServerModule.GetSession(FThread.SessionName); //get defined MainModule of session lMainModule := TUniMainModule(Session.UniApplication.UniMainModule); You have enough info and access code. I'm not test yet. Quote Link to comment Share on other sites More sharing options...
Freeman35 Posted May 1, 2020 Share Posted May 1, 2020 small test, in trail 1526 Not tested in hyperserver, but this will not work. 'cos node not access to another nodes, but if work on this, can work too. via db share. and next century server farm procedure TMainForm.BTN_1Click(Sender: TObject); var SS: TUniGUISession; lMainModule: TUniMainModule; SId : string; Hooked: TMainForm; begin //find session by ID {!!!!} SId := ClientDataSet1.FieldByName('sessionid').AsString; if (SId = '') or (SId = UniSession.SessionId) then Exit; SS := UniServerModule.GetSession(SId); //get defined MainModule of session lMainModule := TUniMainModule(SS.UniApplication.UniMainModule); //get defined MainForm of session Hooked:= TMainForm(lMainModule.GetFormInstance(TMainForm, False)); if Hooked<>nil then Hooked._InComeMessage:= '[' +UniSession.SessionId +' To: ' +SId +']-->' +EDT_1.Text; end; procedure TMainForm.Set_InComeMessage(const Value: string); begin F_InComeMessage := Value; MEM_1.Lines.Add(FormatDateTime('hh:mm:ss',now) +' InCome message : '+ F_InComeMessage); //MEM_1: TUniMemo; just screen not updated, son on screenshot, I moved form. just visual problem end; Quote Link to comment Share on other sites More sharing options...
zilav Posted May 14, 2020 Share Posted May 14, 2020 websockets work fine Quote Link to comment Share on other sites More sharing options...
Freeman35 Posted May 14, 2020 Share Posted May 14, 2020 3 hours ago, zilav said: websockets work fine What Mean ? can you explain? 1 Quote Link to comment Share on other sites More sharing options...
zilav Posted May 14, 2020 Share Posted May 14, 2020 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.