masterdeveloper Posted March 21, 2018 Share Posted March 21, 2018 I am developing a chat in an application using the SGCWebSocket library, I was able to do the exchange of messages and the list of my users when connecting and disconnecting in the system, however I am encountering some problems when accessing objects in the client application when I try to access the objects in an event of the SGC protocols, generating an access violation, for example: groChat: = TIDSiGrowl.Create (null); groChat.Text: = text; groChat.Title: = FieldByName ('NAME'). As rope; groChat.Show; using the above code in the onEvent of the protocol, it explodes the error in the show when it goes addJS. Another example would be when trying to access a selected item from treeView: if treeView.Selected.Text = FieldByName ('NAME') AsString then imelog.Lines.Text: = FieldByName ('TEXT') AsString; I can only solve by running the above codes on events and methods that are not from the SGC components, however I have the need to display notifications and load the message on screen at the moment I receive and without using a timer Someone who used this library and can help me solve these problems? Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted March 21, 2018 Share Posted March 21, 2018 I think you must send in OnEvent a message to the websocket in browser and there you can use javscript and/or ajaxRequest(...). Quote Link to comment Share on other sites More sharing options...
masterdeveloper Posted March 21, 2018 Author Share Posted March 21, 2018 I think you must send in OnEvent a message to the websocket in browser and there you can use javscript and/or ajaxRequest(...). the posted source code runs on onEvent and exactly does occur when trying to add a javaScript myself, I think that's what I meant, if you have any examples with something like that working with SGCWebSocket it would help a lot. thank you Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted March 21, 2018 Share Posted March 21, 2018 I don't understand what you are doing exactly. I have no example because I use long polling. Quote Link to comment Share on other sites More sharing options...
masterdeveloper Posted March 22, 2018 Author Share Posted March 22, 2018 I don't understand what you are doing exactly. I have no example because I use long polling. below has the source code that I use in the onEvent of the message protocol, the commented lines is where error occurs, that is when trying to select an item from the treeview and when trying to display a notification on the screen: procedure TfrChat.WSProtClientEvent(Connection: TsgcWSConnection; const Channel, Text: string); var oJSONMsg: TsgcJSON; groChat : TIDSiGrowl; begin oJSONMsg := TsgcJSON.Create(nil); try oJSONMsg.Read(Text); with cdtConversa do begin if Locate('ID',oJSONMsg.item[0].JSONObject.Item[0].JSONObject.Node['ID'].Value, []) then begin Edit; FieldByName('TEXT').AsString := FieldByName('TEXT').AsString + #13 + oJSONMsg.item[0].JSONObject.Item[0].JSONObject.Node['MESSAGE'].Value; Post; // if tvwMenu.Selected.Text = FieldByName('NAME').AsString then // imeConversa.Lines.Text := FieldByName('TEXT').AsString; groChat := TIDSiGrowl.Create(nil); groChat.Text := Text; groChat.Title := FieldByName('NAME').AsString; // groChat.Show; end; end; finally FreeAndNil(oJSONMsg); end; end; Quote Link to comment Share on other sites More sharing options...
masterdeveloper Posted March 22, 2018 Author Share Posted March 22, 2018 the error in the treeview was resolved by changing the code as follows: procedure TfrChat.WSProtClientEvent(Connection: TsgcWSConnection; const Channel, Text: string); var oJSONMsg: TsgcJSON; tndItem : TUniTreeNode; begin oJSONMsg := TsgcJSON.Create(nil); try oJSONMsg.Read(Text); with cdtConversa do begin if Locate('OPECONVERSA',oJSONMsg.item[0].JSONObject.Item[0].JSONObject.Node['CODIGO'].Value, []) then begin Edit; FieldByName('TXTCONVERSA').AsString := FieldByName('TXTCONVERSA').AsString + #13 + oJSONMsg.item[0].JSONObject.Item[0].JSONObject.Node['MENSAGEM'].Value; Post; tndItem := tvwMenu.Items.FindNodeByCaption( FieldByName('NOMEOPE').AsString); if tndItem.Selected then imeConversa.Lines.Text := FieldByName('TXTCONVERSA').AsString; groChat := TIDSiGrowl.Create(nil); groChat.Text := Text; groChat.Title := FieldByName('NOMEOPE').AsString; // groChat.Show; end; end; finally FreeAndNil(oJSONMsg); end; end; but I'm still having trouble displaying the notification by TIDSiGrowl 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.