【Delphi】中使用消息Messages(六)总结及Demo原代码

本文对比分析了Delphi中RTL(TMessageManager)、Windows消息及Dispatch消息的不同特性,包括平台适用性、使用灵活性及实现方式,并给出了具体使用建议。

目录

一、平台适用性:

二、使用灵活性:

三、引用单元:

四、使用方式总结:

五、下载:演示源代码

一、平台适用性:

RTL(TMessageManager)所有平台都可以,包括:Windows、android、iOS、macos等
Windows消息只能使用在Windows平台,使用Winapi.Messages单元
Dispatch消息所有平台都可以,包括:Windows、android、iOS、macos等

二、使用灵活性:

消息类别绑定窗口对象绑定对象支持广播需要指针传递参数
RTL(TMessageManager)不需要不需要不需要
Windows消息需要需要不支持需要
Dispatch消息不需要需要不支持不需要

三、引用单元:

RTL(TMessageManager)System.Messaging
Windows消息Winapi.Messages
Dispatch消息无需引用专门单元

四、使用方式总结:

RTL(TMessageManager)

//订阅消息
MessageManager := TMessageManager.DefaultManager;
SubscriptionId := MessageManager.SubscribeToMessage(...);
//广播消息
Message := TMessage<UnicodeString>.Create(Edit1.Text);
MessageManager.SendMessage(Sender, Message, True);
//取消订阅

MessageManager.Unsubscribe(System.Messaging.TMessage<UnicodeString>,
    SubscriptionId1);

Windows消息

const
  WinMessageID      = WM_USER + 1;   //WM_USER 在Winapi.Messages中定义

//Winapi.Messages 中的消息响应事件
    procedure OnWinMessage(var Message); message WinMessageID;  //定义一个消息ID对应的消息处理函数过程

//发送消息

SendMessage或者PostMessage

Dispatch消息Self.Dispatch(Student2);  //Self 表示某个对象

RTL(TMessageManager)是按照消息类别来进行消息订阅的,所以与对象无关,只要订阅了某个消息类别,如果有消息广播(发送),所有订阅者都会同时收到消息;windows消息是windows平台约定的,专门针对windows平台的。

根据以上的对比,使用建议:

除了必须在windows的窗体对象上需要使用消息而使用Windows消息机制外,其余都使用RTL(TMessageManager)消息机制。

五、下载:演示源代码

Delphi- Message演示源代码

至此,关于Delphi的消息原理已经介绍完成,从下节开始,介绍Delphi开发android时候的系统消息处理。

下一节:【Delphi】中使用消息Messages(七)android 系统消息​​​​​​​

Creating Windows CreateMDIWindow CreateWindow CreateWindowEx RegisterClass RegisterClassEx UnregisterClass Message Processing BroadcastSystemMessage CallNextHookEx CallWindowProc DefFrameProc DefMDIChildProc DefWindowProc DispatchMessage GetMessage GetMessageExtraInfo GetMessagePos GetMessageTime GetQueueStatus InSendMessage PeekMessage PostMessage PostQuitMessage PostThreadMessage RegisterWindowMessage ReplyMessage SendMessage SendMessageCallback SendMessageTimeout SendNotifyMessage SetMessageExtraInfo SetWindowsHookEx TranslateMessage UnhookWindowsHookEx WaitMessage Window Information AnyPopup ChildWindowFromPoint ChildWindowFromPointEx EnableWindow EnumChildWindows EnumPropsEx EnumThreadWindows EnumWindows FindWindow FindWindowEx GetClassInfoEx GetClassLong GetClassName GetClientRect GetDesktopWindow GetFocus GetForegroundWindow GetNextWindow GetParent GetProp GetTopWindow GetWindow GetWindowLong GetWindowRect GetWindowText GetWindowTextLength IsChild IsIconic IsWindow IsWindowEnabled IsWindowUnicode IsWindowVisible IsZoomed RemoveProp SetActiveWindow SetClassLong SetFocus SetForegroundWindow SetParent SetProp SetWindowLong SetWindowText WindowFromPoint Processes and Threads CreateEvent CreateMutex CreateProcess CreateSemaphore CreateThread DeleteCriticalSection DuplicateHandle EnterCriticalSection ExitProcess ExitThread GetCurrentProcess GetCurrentProcessId GetCurrentThread GetCurrentThreadId GetExitCodeProcess GetExitCodeThread GetPriorityClass GetThreadPriority GetWindowThreadProcessId InitializeCriticalSection InterlockedDecrement InterlockedExchange InterlockedIncrement LeaveCriticalSection OpenEvent OpenMutex OpenProcess OpenSemaphore PulseEvent ReleaseMutex ReleaseSemaphore ResetEvent ResumeThread SetEvent SetPr
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海纳老吴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值