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

Delphi: do NOT use duplicate GUIDs on interfaces

$
0
0

One of the things when fixing bugs in an old codebase is wading through technical debt.

A quick win is to get rid of duplicate GUIDs when interface portions have been copy-paste re-used:

  1. interfaces with the same GUID are treated the same with as casts even if they are different.
  2. the compiler does not warn about duplicate GUID values**

These searches help big time: it shows the duplicate GUIDs if they have been indented all the same way. Good enough for most situations.

grep -Sh "\[\'{" *.pas | sort

grep -rh "\[\'{" *.pas | sort

It depends which flavour of grep you use (gnu or regular) to specify recursion.

Note that findstr doesn’t cut it as it always shows the filename: [WayBackList files recursively showing only full path and file size from Windows Command Prompt – Super User

** this compiles without warning:

program NoWarningOnDuplicateInterfaceGUID;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

type
  IInterface1 = interface
    ['{ECF26C39-CBFF-488E-A3AB-2629726F1005}']
  end;

  IInterface2 = interface
    ['{ECF26C39-CBFF-488E-A3AB-2629726F1005}']
  end;

var
  Subject: IInterface;
begin
  try
    (Subject as IInterface1)._Release;
    (Subject as IInterface2)._release;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

–jeroen


Viewing all articles
Browse latest Browse all 1440

Trending Articles