【问题标题】:How to properly implement a Custom Locked State Image in cxgrid in Delphi?如何在 Delphi 的 cxgrid 中正确实现自定义锁定状态图像?
【发布时间】:2019-02-21 11:13:49
【问题描述】:

我正在使用 Delphi 10.2 Tokyo,并希望在 Tcxgrid (DevExpress VCL 18.2) 的后代中实现自定义“锁定状态图像”。

我尝试如下覆盖DoPrepareLockedStateImage protected 方法:

function TZcxGrid.DoPrepareLockedStateImage: Boolean;
begin
   Result: = False;

   if Assigned (OnPrepareLockedStateImage) then
     OnPrepareLockedStateImage (Self, LockedStatePaintHelper.GetImage, Result)
   else
     DoLockedStateImage (Self, LockedStatePaintHelper.GetImage, Result);
end;

上述实现的方法导致堆栈溢出,因为LockedStatePaintHelper.GetImage 从网格调用DoPrepareLockedStateImage

这是实现此功能的方式吗?

注意:我没有在支持中心或 DevExpress 常见问题上找到主题。刚刚找到一个题目解释如何使用cxgrid的OnPrepareLockedStateImage方法

【问题讨论】:

  • 谢谢,但我需要调用我的抽屉“DoLockedStateImage”

标签: delphi devexpress vcl tcxgrid


【解决方案1】:

问题是在准备状态图像期间使用TcxLockedStatePaintHelperGetImage 会导致您遇到的堆栈溢出。这是因为在图像完全准备好之前,调用GetImage 将导致图像准备好(在这种情况下一次又一次)。

通过使用访问器直接访问受保护的Bitmap 属性,可以规避这种情况。使用DoLockedStateImage(您绘制另一张图像的实现)您的方法将如下所示:

type
  TcxLockedStatePaintHelperAccess = class(TcxLockedStatePaintHelper);

function TZcxGrid.DoPrepareLockedStateImage: Boolean;
begin
  DoLockedStateImage(Self, TcxLockedStatePaintHelperAccess(LockedStatePaintHelper).Bitmap, Result);
  Result := inherited DoPrepareLockedStateImage;
end;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-10
    • 2013-07-21
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多