Quantcast
Channel: Delphi – The Wiert Corner – irregular stream of stuff
Viewing all articles
Browse latest Browse all 1440

Delphi: “Override method %s.%s should match case of ancestor %s.%s (H2365)”

$
0
0

If you write consistent code, you will never see [WayBackOverride method %s.%s should match case of ancestor %s.%s (H2365), but a long while ago I bumped into a project where some the developers had trouble using their shift key and failed to use code completion in quite a few parts of the source code.

So next a lot of lines containing things like Begin, whIle, repeaT, wrong indentations (not just at the wrong level, but even getting things indented at the same level wrong).

Code formatted like this was no exception, not even for methods bound to events:

procedure  TForm1.Button1CLick(SendeR  : TOBJect ) ;
 Begin
  Button2Click  (Sender );
end;

You cannot disable this hint individually as it is not on the list at [WayBack] Delphi XE2’s hidden hints and warnings options | Marc Durdin’s Blog, so you either have to fix the code (which I prefer), or disable all hints with {$ HINTS OFF} as per [WayBackcompiler construction – Can specific Delphi hints be disabled? – Stack Overflow (thanks Lars Truijens).

The above occasion was the first and only time I saw the hint H2365 until recently when I again bumped into a project that had grown over a long time needing some maintenance.

This reminded me I should have blogged about it, found back [Archive.is] H2365 Override method %s.%s should match case of ancestor %s.%s (Delphi) Today was the first time I have ever seen this compiler hint. Why does Delphi… – Graeme Geldenhuys – Google+ and dug a bit deeper.

TheH2365 was – until [Archive.isH2365 … – RAD Studio XE3 – documented as “No further information is available for this error or warning.” which luckily changed with in [Archive.is] H2365 …  – RAD Studio XE4 got documented starting with the quotes below.

It still doesn’t explain the origin of the hint, but luckily there is [WayBack] compiler construction – It seems that sometimes Delphi is case-sensitive – override method should match case of ancestor – Stack Overflow:

  • It’s a hint that’s in place to protect your code when cooperating with 3rd party code.
    This hint was introduced with the addition of Delphi for .net, because some other .net platforms are case-sensitive.

It is complements to my initial thoughts on which case sensitivity topics are related to the hint:

  • case sensitivity was introduced for unit names that for a while now must match the filenames
  • some Windows API functions are case sensitive
  • some .NET languages are case sensitive, so .NET or COM interop could be related (I’m not sure if there is case sensitivity there: too long ago I did tat)
  • the infamous “Register” procedure for component registration is case sensitive

From the documentation:

H2365 Override method %s.%s should match case of ancestor %s.%s (Delphi)

When overriding a method, the best practice is to match the case of the ancestor method. This prevents any downstream failure that would not be anticipated by a Delphi user, who expects case-insensitivity.

Example

Hint H2365 is emitted in the following case:

type
  TClass1 = class
    procedure VirtualMethod; virtual; abstract;
  end;
 
  TClass2 = class(TClass1)
    procedure virtualmethod; override; 
  end;
 
procedure TClass2.virtualmethod;
begin
end;

Here are some situations in which Delphi is case-sensitive:

It then goes on explaining a few places where Delphi is case-sensitive, but fails to explain why the hint is actually important.


Viewing all articles
Browse latest Browse all 1440

Trending Articles