FMX has two ways to implement message processing, one is to use Tmessagemanager to implement custom messages, and the other is an implementation in the Tedit that directly declares the message method

Source: Internet
Author: User

Looking at the FMX code, there are two ways to implement message processing, one is to implement a custom message with Tmessagemanager, and the other is to declare the message method as an implementation in Tedit.

  Earlier, read the article said Tmessagemanager usage, available to the time, and can not find, had to do their own hands.   My application scenario is this:  the current frame pops up a dialog frame, when the Action dialog box, want to let the current frame should sound, let the user see the results of the operation, such as the dot large and small font, the following topic will change the font:  Referring to the FMX code, try to implement the message mechanism: 1. Declaring the message class: Type  tfontchangemessage = Class (System.Messaging.TMessage <INTEGER>); This message class With an integer value that represents the size of the selected font  2. Declares the receiving method of a message     procedure Fontchangehandler (const sender:tobject; const Msg:System.Messaging.TMessage); The prototype of this method is like this, can not be changed, can only change the name Fontchangehandler receive the message method implementation: procedure Texamframe.fontchangehandler (const sender:tobject; const Msg:System.Messaging.TMessage); begin//tfontchangemessage (MSG). Value is preferable to the message returned by//with this value to change the size of the control font on the interface, the code is omitted ... end; 3. Subscribe to this message using Tmessagemanager:   ffontchangemessageid : = TMessageManager.DefaultManager.SubscribeToMessage (Tfontchangemessage, Fontchangehandler); Ffontchangemessageid is a return handle to the subscription message that cancels the two parameters of the subscribetomessage, which are defined by the message class and method 4 that receives the message. Unsubscribe Message    TMessageManager.DefaultManager.Unsubscribe (Tfontchangemessage, Ffontchangemessageid, True); arguments are messagesClass, and the last true of the message handle returned when subscribing to a message, indicating whether to cancel, see the code, and decide whether to remove it from a list of Tmessagemanager at the time of cancellation.  1, 2, 3, and 4 steps are ready to receive a message from the dialog frame in the question frame. Next, prepare the message in the dialog box: (in order to share the declaration of the first step Tfontchangemessage message class, I used a single unit with the cell name Exam.const.pas.)   Send a message in the dialog frame: 1. Refer to the Exam.const unit first, ready to use the message class declared in it 2. Create and send a message, see the following code: Var  amessage:tfontchangemessage ;//Declare your own message instance begin  if radiobutton1.ischecked then    ffontsize: = 13;  if radiobutton2.ischecked then    ffontsize: = 15;  if RadioButton3.IsChecked then     ffontsize: = 17;  amessage: = Tfontchangemessage.create (FFontSize);//Build Message    TMessageManager.DefaultManager.SendMessage (nil, amessage);//Send Message End; tmessagemanager There is also a way to subscribe to the message, you can directly subscribe to the anonymous method , I have not tried, and so on to try to fill up. function subscribetomessage (const amessageclass:tclass; const alistener:tmessagelistener): Integer; Overload, my friend told me that in the official WiFi, useful information on anonymous methods, here Http://docwiki.embarcadero.com/CodeExamples/Berlin/en/System.Messaging_ ( Delphi), written in great detail. &nBSP; Also note that the message sent, all Subscribers will receive, as I have shown above, in fact, only the currently displayed frame received can be, so to avoid this situation, there are two ways: one in the message receiving method processing, and the other is to cancel the subscription.

Http://blog.sina.com.cn/s/blog_44fa172f0102wfwl.html

FMX has two ways to implement message processing, one is to use Tmessagemanager to implement custom messages, and the other is an implementation in the Tedit that directly declares the message method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.