I'm preparing some parts of a Delphi 2007 project to easily migrate to Delphi XE7.
I've switched a parameter's type of an event handler from string
to AnsiString
(This particular event handler must work with AnsiString
).
Runtime package:
TMyAnsiStringFunction = function(const APar : AnsiString) : AnsiString of object;
TMyTestComponent = class(TComponent)
private
FMyAnsiStringFunction : TMyAnsiStringFunction;
published
property MyAnsiStringFunction : TMyAnsiStringFunction read FMyAnsiStringFunction write FMyAnsiStringFunction;
end;
Designtime package:
procedure Register;
begin
RegisterComponents('MyComponents', [TMyTestComponent]);
end;
When I doubleclick on the MyAnsiStringFunction
from the Object Inspector, it automatically creates a function with a string
param and a string
resulting type instead of AnsiString
:
TForm1 = class(TForm)
MyTestComponent1: TMyTestComponent;
function MyTestComponent1MyAnsiStringFunction(const APar: string): string;
private
{ Private declarations }
public
{ Public declarations }
end;
If I manually change the param and resulting type from string
to AnsiString
, then I get the following error while saving changes:
The MyTestComponent1MyAnsiStringFunction method referenced by MyTestComponent1.MyAnsiStringFunction has an incompatible parameter list. Remove the reference?
Why is this happening and is there a way to force the AnsiString
type?
string
isAnsiString
in D2007, so it makes sense for a pre-D2009 IDE to substitutestring
in forAnsiString
, they are the same type. Butstring
isUnicodeString
in D2009+, so a post-D2007 IDE should not be doing that substitution forAnsiString
, only forUnicodeString
. – Remy Lebeau