delphi - 使用 fontdialog 和 RichEdit 更改事件控件

标签 delphi dialog delphi-xe2

我从 Delphi v7 迁移到 Delphi XE2。我正在尝试使用带有两个 dbrichedit 和一个 dbedit 控件的 fontdialog。我用来完成任务的代码在 Delphi v7 中运行良好,但不适用于 XE2。我想这一定是我忽略了一些简单的事情。我已经解决这个问题一个多星期了,但我认为我离问题太近了,看不到它。

我使用了一个按钮来执行 fontdialog 和一个应用事件来操作文本。

代码:

if ActiveControl is TDBEdit then 
  with ActiveControl as
  TdbEdit do
    Font.Assign(TFontDialog(Sender).Font)
else if ActiveControl is TDBRichEdit then 
  with ActiveControl as TDBRichEdit do
    SelAttributes.Assign(TFontDialog(Sender).Font)

没发生什么事。

是否有我忽略的 form1 属性?

最佳答案

您必须保存 ActiveControl 的值变量中的属性,在使用它之前,因为当 Vcl.Dialogs.TFontDialog.OnApply事件引发 ActiveControl返回当前事件控件,在这种情况下是您按下的按钮。检查这个样本 FontDialogOnApply (Delphi) .

关于delphi - 使用 fontdialog 和 RichEdit 更改事件控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9999452/

相关文章:

delphi - VirtualTreeView 的 Firemonkey 版本

delphi - 如何使用Delphi Mocks框架检查参数内容?

string - Delphi:调用名称存储在字符串中的函数

javascript - 如何使用 Bootstrap 模态对话框并获取返回值?

delphi - 一键执行两个过程

android - 物理设备上的错误 View DialogFragment

javascript - 检测任何对话框何时打开 jQuery

德尔福XE2风格: Main Menu Ignored

delphi - 为什么我的 Delphi IDE Expert 在使用 "Known IDE Packages" key 时没有初始化?

windows - 从开始屏幕而不是桌面运行 Delphi 应用程序需要什么 API