Delphi 7 和 Delphi 2010 之间的 TVirtualStringTree 兼容性 - “参数列表不同”

发布于 2024-08-29 05:09:35 字数 610 浏览 4 评论 0原文

我制作了一个包含在 Delphi 7 和 Delphi 2010 中工作的 TVirtualStringTree 的表单。我注意到,当我在两个平台之间移动时,我在树事件上收到消息“...参数列表不同..”,并且字符串类型在 TWideString (D7) 和 string (D2010) 之间变化。我发现可以抑制此错误的唯一技巧是使用编译器指令,如下所示:

{$IFDEF TargetDelphi7}
procedure VirtualStringTree1GetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: WideString);
{$ELSE}
procedure VirtualStringTree1GetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: string);
{$ENDIF}

并在实现事件的地方重复此操作。我是否缺少一个简单的解决方案? 谢谢。

I've made a form containing a TVirtualStringTree that works in Delphi 7 and Delphi 2010. I notice that as I move between the two platforms I get the message '...parameter list differ..' on the tree events and that the string type is changing bewteen TWideString (D7) and string (D2010). The only trick I've found to work to suppress this error is to use compiler directives as follows:

{$IFDEF TargetDelphi7}
procedure VirtualStringTree1GetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: WideString);
{$ELSE}
procedure VirtualStringTree1GetText(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
  var CellText: string);
{$ENDIF}

and to repeat this where the events are implemented. Am I missing a simple solution?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

帅的被狗咬 2024-09-05 05:09:35

最简单的解决方案是为 D7 和 D2010 维护单独的源文件夹和组件文件夹。最终会节省时间并减少头痛。

The simplest solution would be to maintain separate source and component folders for D7 and D2010. It will save time and headaches in the end.

咽泪装欢 2024-09-05 05:09:35

您还可以尝试在 VirtualTrees 单元中声明一个新类型:

{$IFDEF TargetDelphi7}
type
  VTString = type WideString;
{$ELSE}
type
  VTString = type string;
{$ENDIF}

并更改所有事件签名以使用此新类型,这将使​​您能够保持 .dfm 文件兼容且不受这些条件的影响。

You could also try declaring a new type in VirtualTrees unit:

{$IFDEF TargetDelphi7}
type
  VTString = type WideString;
{$ELSE}
type
  VTString = type string;
{$ENDIF}

and change all event signatures to use this new type which should enable you to keep your .dfm files compatible and free of these conditionals.

成熟稳重的好男人 2024-09-05 05:09:35

我可以建议 3 个解决方案。对于我自己的代码,我使用解决方案 (1),因为对于我的应用程序,需要在 Delphi 7 和 Delphi 2010 之间共享的代码很少。

  1. 按照您的操作(IFDEF-it 进行编译)并在运行时分配事件处理程序。您只需更改代码,您的需求列表保持不变。这不是一个好的解决方案。
  2. 创建一个从 TVirtualTree 派生的新组件(例如 TMyVirtualTree),该组件提供您自己的 OnGetText 事件版本,该事件在两个平台上具有相同的签名。例如,我只是让它使用“字符串”。优点:您的代码可以在 D7 和 D2010 上运行,您无需更改 VirtualTree 代码,但如果任何其他开发人员想要打开您的代码,他们将需要安装您被黑的 TMyVirtualTree 组件。
  3. 修改 TVirtualTree 本身,对其进行更改,以便它对 D7 和 D2010 使用相同的类型(字符串)。这也将使您的代码在 D7 和 D2010 上工作,您的代码可以在使用普通 TVirtualTree 的 D2010 上工作,但如果任何新开发人员想要使用 D7 打开您的代码,他们将需要从您被黑的源代码重建 VirtualTree。

I can suggest 3 solutions. For my own code I used solution (1) because for my applications very little code needs to be shared between Delphi 7 and Delphi 2010.

  1. Do as you did (IFDEF-it to compile) and assign the event handler at run-time. You only change your code, your requirements list stays the same. Not a nice solution.
  2. Create a new component derived from TVirtualTree (for example TMyVirtualTree) that provides your own version of the OnGetText event that has the same signature on both platforms. For example I'd simply make it use "string". Advantage: your code would work on both D7 and D2010, you don't alter VirtualTree code BUT if any other developer wants to open your code, they'll need to install your hacked TMyVirtualTree component.
  3. Modify the TVirtualTree itself, change it so it uses the same type (string) for both D7 and D2010. This would also make your code work on both D7 and D2010, your code would work on D2010 with the vanilla TVirtualTree but if any new developer wants to open your code with D7 they would need to rebuild VirtualTree from your hacked sources.
捂风挽笑 2024-09-05 05:09:35

我认为这个老问题已经解决了,因为 VirtualTrees.pas 已转换为使用 UnicodeString,并为旧编译器进行了定义:

{$ifndef COMPILER_12_UP}
type
  UnicodeString = WideString;
{$endif COMPILER_12_UP}

我不知道什么时候 UnicodeString引入了,但我知道 string 现在是 UnicodeString 的别名(可怜的 WideString,没人爱他 - i知道他的感受)。

i think this old question has been resolved, as VirtualTrees.pas was converted to use UnicodeString, with a define for older compilers:

{$ifndef COMPILER_12_UP}
type
  UnicodeString = WideString;
{$endif COMPILER_12_UP}

i don't know when UnicodeString was introduced, but i know string is nowadays an alias for UnicodeString (poor WideString, nobody loves him - i know how he feels).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文