uniGUI & WebSockets
BroadcastMessage('update');procedure TMainForm.UniFormBroadcastMessage(const Sender: TComponent;
const Msg: string; const Params: TUniStrings);
begin
if Msg = 'update' then
begin
UniLabel1.Caption := Query1.RecordCount.ToString;
end;
end;1
Updating the client directly using a JavaScript event handler
procedure BroadcastMessage(const Msg: string; const Args: arrayofconst; ClientOnly: Boolean = False);BroadcastMessage('update_grid',
[
'row', IntToStr(Random(GRD_ROW) + 1),
'col', IntToStr(Random(GRD_COL) + 1),
'value', Random(1000)
],
[boClientOnly]);function form.socketmessage(sender, msg, params, eOpts)
{
if (msg == 'update_grid') {
var row, col;
var grd = MainForm.UniStringGrid1;
for (prop in params) {
var p = params[prop];
if (prop == 'row') {
row = grd.store.getAt(p); // row number
} elseif (prop == 'col') {
col = p; // col number
} elseif (prop == 'value' && row && col) {
row.set(col, p);
}
}
}
}
2
Updating the client using server-side code
BroadcastMessage('message', ['text', UniEdit1.Text]);procedure TMainForm.UniFormBroadcastMessage(const Sender: TComponent;
const Msg: string; const Params: TUniStrings);
begin
if Msg = 'message' then
begin
ShowMessage(Params['text'].AsString);
end;
end;