4

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.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Brian Frost
  • 13,334
  • 11
  • 80
  • 154

4 Answers4

1

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.

frogb
  • 2,040
  • 15
  • 22
1

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.

Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128
1

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.
Cosmin Prund
  • 25,498
  • 2
  • 60
  • 104
1

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

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • UnicodeString was introduced in Delphi 2009. If you write applications or components that depend on Unicode, your best bet is to do exactly what VirtualTreeView did: use UnicodeString everywhere and define a type alias for WideString in versions of Delphi that don't have it. – afrazier Jun 13 '11 at 14:50
  • This doesn't really fix the problem, because Delphi 7 is not smart enough to realize that UnicodeString means WideString in this case. It still generates the same error. – Frederik Slijkerman Jun 18 '13 at 13:18
  • @FrederikSlijkerman Delphi 5 (what i use) is smart enough to figure out it. It's odd that Delphi 7 would have regressed. – Ian Boyd Jun 18 '13 at 14:50