Jump to content
uniGUI Discussion Forums
Sign in to follow this  
lucas.dolberth

Problems SGCWebSocket

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?

 

Share this post


Link to post
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(...).

Share this post


Link to post
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

Share this post


Link to post
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;

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×