views:

340

answers:

3

Hi, 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.

+1  A: 

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
+1  A: 

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.

TOndrej
Delphi does not seem to like this. I thought of that. Try it and see.
Brian Frost
Try it without the extra 'type' specifiers so they are simple aliases and not unique data types: type VTString = WideString; type VString = String;
Remy Lebeau - TeamB
@Remy: IT must be Delphi 7 that does not like the VTSTring in the event declaration - it triggers the 'parameter lists differ' message, even though as you say its a simple alias.
Brian Frost
It seems you didn't rebuild your IDE packages.
TOndrej
+1  A: 

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
Useful suggestions, thanks.
Brian Frost