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

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

码:

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)

10-08 15:53