Jump to content

eduardosuruagy

uniGUI Subscriber
  • Posts

    831
  • Joined

  • Last visited

  • Days Won

    10

Posts posted by eduardosuruagy

  1. There is no websocket component in Unigui yet, but you may be able to use socket.io with node.js:

    const
      socketToken = 'mySpecialToken';
    
    procedure TMainForm.myHtmlFrameAjaxEvent(Sender: TComponent; EventName: string;
      Params: TUniStrings);
    begin  
      if eventname='doSocketAuth' then 
      begin
        UniSession.AddJS('socket.emit("authenticate", {token: "' + socketToken + '"});');
      end;
      if eventname='gotData' then 
      begin
        //myData:=strtointdef(Params.Values['mydata'], 0);
        //do something with it
      end;
    end;
    
    //to broadcast some data
    procedure TMainForm.socketPush(myData:integer);
    begin
       UniSession.AddJS('if(socket !== undefined)socket.emit("'+companyName+'", ' + inttostr(myData) + ');');
    end;
    
    //some JS to run somewhere to setup the socket connection and catch the incoming data
    if(socket === undefined){
      var socket = io('http://127.0.0.1:3000/?company=' + companyName, {
      reconnection: true, 
      reconnectionDelay: 3000, 
      reconnectionAttempts: 20, 
      forceNew: false,
      secure: true
    });
    }
    
    socket.on('connect', function(){
      ajaxRequest(MainForm.myHtmlFrame, ["doSocketAuth"], { });
    });
    
    socket.on(companyName, function(data){ 
      ajaxRequest(MainForm.myHtmlFrame, ["gotData"], { mydata : data }); 
    });
      
    //node.js script to run an https socket io server
    var fs = require('fs');
    var https = require('https');
    var app = require('express')();
    var options = {
      key: fs.readFileSync('c:/my.key'),
      cert: fs.readFileSync('c:/my.crt')
    };
    var serverPort = 3000;
    var server = https.createServer(options, app);
    var io = require('socket.io')(server);
    
    io.on('connection', function(socket){
      companyName=socket.handshake.query.company;
      socket.auth = false;
      socket.on('authenticate', function(data){
        if(data.token == 'mySpecialToken'){
          socket.auth = true;
        }
      });
     
      setTimeout(function(){
        if (!socket.auth) {
          socket.disconnect('unauthorized');
        }
      }, 1000);
    	
      socket.on(companyName, function(msg){
        if (socket.auth)io.emit(companyName, msg);
      });
    });
    
    server.listen(serverPort, function(){
      console.log('Socket.io https server listening on port ' + serverPort);
    });
    
    

    You will also need to add socket.io.js to the CustomFiles in servermodule and of course set up the node server.

     

    Would you have any examples?

  2. Before I used this option to sort the columns but now I can not do this, has anything changed?

     

    function headerclick (ct, column, e, t, eOpts)

    {

       Frame.ClientDataSet.getStore (). Sort (column.dataIndex);

    }

     

    function store.afterCreate (sender)

    {

       sender.remoteSort = false;

    }

  3. You are using client side alignment.  Which means rules must be set correctly.

    In your case you need to set Flex property of Grid -> 1 , so it will occupy all empty client area of container.

     

    Ours worked perfect, thank you !! I'd like to better understand client-side alignment settings. Do you have any material that explains this?

  4. I have a problem in dbgrid, when I click on the column to sort LoadMask appears at the time of the click but it does not undo, with the screen stuck and the column does not sort. I'm using the option of our friend Mohammad.

     

    function headerclick (ct, column, e, t, eOpts)

    {

       Frame.dbgrid.getStore (). Sort (column.dataIndex);

    }

     

    function store.afterCreate (sender)

    {

       sender.remoteSort = false;

    }

  5. Hi,

    I create like this way:

    use click on dbgrid selected row -> show small form with buttons -> onbuttonclick get dbgrid row data -> work with data.

    Form showing dinamically OnDBGridClick.

     

    You can show form  by OnHover.

     

    Can create dbgrid column with control -> Panel with buttons and so on.

     

    Can you show me an example?

×
×
  • Create New...