TVirtualStringTree Compatibility Between Delphi 7 and Delphi 2010 - “Parameter Lists Differ”

I created a form containing TVirtualStringTree that works in Delphi 7 and Delphi 2010. I notice that as I move between the two platforms, I get the message "list of options ... different from" on tree events and that the row type Bewteen TWideString (D7) and string (D2010) changes. The only trick I found to work on suppressing 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 repeat this when the events are realized. Am I missing a simple solution? Thanks.

+4
source share
4 answers

The simplest solution would be to support separate source and component folders for D7 and D2010. This will save time and headaches at the end.

+1
source

You can also try declaring a new type in VirtualTrees :

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

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

+1
source

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

  • Do the same as you (IFDEF is for compilation) and assign an event handler at runtime. You change your code only, your list of requirements remains unchanged. Bad decision.
  • Create a new component derived from TVirtualTree (e.g. TMyVirtualTree) that exposes your own version of the OnGetText event that has the same signature on both platforms. For example, I would just use "string". Advantage: your code will work on both D7 and D2010, you do not change the VirtualTree code, but if any other developer wants to open your code, they will need to install your hacked component TMyVirtualTree.
  • Change TVirtualTree itself, change it so that it uses the same type (string) for D7 and D2010. It would also make your code work with both D7 and D2010, your code would work on D2010 with vanilla TVirtualTree, but if any new developer wants to open your code using D7, they will need to rebuild VirtualTree from your hacked sources .
+1
source

I think this old question was resolved as VirtualTrees.pas was converted to using UnicodeString , with a definition 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 that string is currently an alias for UnicodeString (a bad WideString , nobody likes it - I know how it feels).

+1
source

Source: https://habr.com/ru/post/1307452/


All Articles