Reputation: 73
[dcc32 Error] MSSQLQuery.pas(29): E2037 Declaration of 'DataEvent' differs from previous declaration
I have done some research and found that this issue is caused during function overriding, if the declaration in super class and sub class are different
DataEvent is a library function and Ive checked the library and found that the declaration in code is correct ,but Im not sure why this compilation error occurs
I have also confirmed that there is only one DataEvent function in this class
I am new to Delphi So please help me in resolving this error
This is the class I have defined
TMSSQLQuery = Class (TADOQuery)
Private
FAutoNoLock : Boolean;
Protected
procedure DataEvent(Event: TDataEvent; Info: Longint); override;
Public
Constructor Create (AOwner : TComponent);Override;
Destructor Destroy;Override;
End;
This is the procedure definition
Procedure TMSSQLQuery.DataEvent(Event: TDataEvent; Info: Longint);
Begin
{ Call inherited method }
Inherited DataEvent (Event, Info);
If Event in [deConnectChange, dePropertyChange]
Then RefreshParams;
End;
Upvotes: 1
Views: 1259
Reputation: 125757
Note: After your recent edit, the issue is clear.
You've declared your DataEvent handler with a second parameter of LongInt
:
procedure DataEvent(Event: TDataEvent; Info: Longint); override;
The VCL defines it as NativeInt
(see the documentation):
procedure DataEvent(Event: TDataEvent; Info: NativeInt); override;
NativeInt
and LongInt
are not the same in that declaration, and therefore the descendant class definition does not match that of the ancestor you're attempting to override. (See the next section of my answer).
This error occurs if you have a declaration in the implementation section that is different from the interface declaration.
type
TSomeClass=class(TSomething)
procedure DoThisThing(const AParameter: TSomeParamType);
end;
implementation
// Note difference in parameter name
procedure TSomeClass.DoThisThing(AParam: TSomeParamType);
begin
end;
// This would cause the same error - note the missing 'const'
procedure TSomeClass.DoThisThing(AParameter: TSomeParamType);
begin
end;
// This can cause the same error - note different param type
procedure TSomeClass.DoThisThing(AParameter: TDiffParamType);
The easiest solution to the problem is to use Class Completion to write the implementation definition for you. Type the declaration in the interface
, and then (while still in that class definition) use Ctrl+Shift+C. It will generate the proper method stub in the implementation section for you.
(You can generate several at the same time; just declare them all before using the keystroke combination. Using Ctrl+Shift+UpArrow (or DownArrow) helps you move back and forth between the implementation and interface sections.)
The documentation (see below) indicates that this error message also occurs when you try to override a virtual method, but the overriding method has a different parameter list, calling convention etc. This code is from that linked documentation:
type
MyClass = class
procedure Proc(Inx: Integer);
function Func: Integer;
procedure Load(const Name: string);
procedure Perform(Flag: Boolean);
constructor Create;
destructor Destroy(Msg: string); override; (*<-- Error message here*)
class function NewInstance: MyClass; override; (*<-- Error message here*)
end;
For more info, see the Delphi documentation for E2037.
Upvotes: 2