Jump to content

Problems SGCWebSocket


masterdeveloper

Recommended Posts

 
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?

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...