开发者

TVirtualStringTree compatibility between Delphi 7 and Delphi 2010 - 'Parameter lists differ'

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.


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.


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.


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜