Archive
Messages in Smart Mobile Studio
If you have missed message coding from Delphi under Smart Pascal then you are in for a treat. The QTX library now supports application-wide messages in the browser; allowing you to send and subscribe to as many messages as you like. More or less duplicating the stuff you are used to under WinAPI.
In fact, you can subscribe to the same message in the same object as many times as you want — and also instantiate as many subscription objects as you like.
Receiving messages
Here is how you would create and setup a message-subscription for a form:
procedure TForm1.InitializeObject; begin inherited; {$I 'Form1:impl'} //create our message subscriber object FMsgPort:=TQTXMessageSubscriber.Create; // subscribe to message-type $100 FMsgPort.Subscribe($100,procedure (Message:TQTXMessageData) begin writeln("Data received:" + message.data); end); // subscribe to message-type $200 FMsgPort.Subscribe($200,procedure (Message:TQTXMessageData) begin writeln("Data received:" + message.data); end); end;
To send real objects through messages, simply use JSON to serialize it, then de-serialize it in your message handler.
Sending messages
The simplest way to send messages are through the two API methods:
- QTX_SendMessage(Message:TQTXMessageData);
- QTX_BroadcastMessage(Message:TQTXMessageData);
Alternatively, although highly unpractical, you could create your own message-port. The whole message system uses just a single message-port so you would never really create these yourself. If all you want to do is send and receive messages – you have more or less the same support as Delphi as for WinAPI messages — but simpler and easier to use!
Practical uses
Messages have been a part of Windows since the beginning, and it’s also hard-coded into Delphi. Their uses are almost limitless and you can use then to notify changes across controls and forms, transport data from one place to another — it’s really only creativity that sets the bounds.
What is cool about Smart Mobile Studio – is that you now have the same system under JavaScript. It works in every browser and allows your HTML5 forms and controls to communicate indirectly.
The technology is based on the HTML5 message system, which is a part of modern browsers. It’s extremely efficient and very reliable.
Recent
The vatican vault
- January 2022
- October 2021
- March 2021
- November 2020
- September 2020
- July 2020
- June 2020
- April 2020
- March 2020
- February 2020
- January 2020
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- September 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- February 2013
- August 2012
- June 2012
- May 2012
- April 2012
You must be logged in to post a comment.