Board index » delphi » VAR x:string - D1/D2

VAR x:string - D1/D2

For a component designed in D1, I made up an event with, among other things, a
"VAR X : String" parameter. Now when I want to have code compability between D1
& D2, I can't seem to satisfy more than one of them at a time. If the component
& event is used in a D1 project, D2 will barf with a 'illegal parameter' error
(D1 declares the event string type as Openstring in the unit using the
component). I tried manipulating the Open parameter compiler setting, but it
didn't seem make any difference.

In short, what is needed to be able to use a VAR string in in an event
procedure declaration in both D1 & D2?

(Hm... repeat after me: single click compile... single click compile... :-))

--
Mr.Hillbilly (eiv...@infolink.no) http://www.sn.no/~eivind
 tHyperSoft HyperReader 1.0t

 

Re:VAR x:string - D1/D2


Quote
Eivind Bakkestuen wrote:

> For a component designed in D1, I made up an event with, among other things, a
> "VAR X : String" parameter. Now when I want to have code compability between D1
> & D2, I can't seem to satisfy more than one of them at a time. If the component
> & event is used in a D1 project, D2 will barf with a 'illegal parameter' error
> (D1 declares the event string type as Openstring in the unit using the
> component). I tried manipulating the Open parameter compiler setting, but it
> didn't seem make any difference.

> In short, what is needed to be able to use a VAR string in in an event
> procedure declaration in both D1 & D2?

I've had this exact same problem before, and I don't think there is a
good solution. Even the standard components supplied with D1/D2 has this
problem (i.e. the GetText event of the TDataField components). The only
"solution" I've found is to use {$IFNDEF} in the form's unit and
then only change the form in Delphi 1. Use D2 only to recompile the
project.

For instace:

  {$IFDEF VER80}
    procedure MyStringEvent(Sender: TObject; var S: OpenString);
  {$ELSE}
    procedure MyStringEvent(Sender: TObject; var S: String);
  {$ENDIF}

The clue is that the source code scanner used at designtime is not
clever enough to recognize the IFDEFs, so this code will only be
useful at designtime in D1. In D2 the scanner will barf at the
OpenString parameter. But it will compile in both versions.
Shame is that the users of your component will have to write these
ugly $IFDEFs themselves.

Another approach is to use a function instead of a procedure:

    procedure MyStringEvent(Sender: TObject): string;

The problem with this, of course is that you cannot give the event
a default string (unless you add another parameter for that) and
you cannot know if the event actually returns a valid value...

Oh, well... :-C

--
Hallvard Vassbotn

Other Threads