[fpc-devel] Trying to patch TGuid

Дмитрий Померанцев pda2 at yandex.ru
Thu Dec 22 22:07:58 CET 2016

I tried to add the comparison operator and the method that returns the empty GUID to the TGuid type, as is done in Delphi. I thought that this would not be any problems, because that type is declared rtl/inc/objpash.inc file which is included in rtl/inc/systemh.inc and the systemh.inc have a {$modeswitch advancedrecords} line.

Unfortunately, it seems to rewrite the system modules is not so easy. After making the changes that are described by this patch:
Index: rtl/inc/objpas.inc
--- rtl/inc/objpas.inc	(revision 35175)
+++ rtl/inc/objpas.inc	(working copy)
@@ -1000,6 +1000,27 @@
+                               TGUID
+    class operator TGuid.=(const left, right : TGuid) : boolean;
+      begin
+        result:=IsGUIDEqual(left,right);
+      end;
+    class operator TGuid.<>(const left, right : TGuid) : boolean;
+      begin
+        result:=not(IsGUIDEqual(left,right));
+      end;
+    class function TGuid.Empty : TGuid;
+      begin
+        FillChar(result,SizeOf(result),0);
+      end;
Index: rtl/inc/objpash.inc
--- rtl/inc/objpash.inc	(revision 35175)
+++ rtl/inc/objpash.inc	(working copy)
@@ -132,6 +132,9 @@
        PGuid = ^TGuid;
        TGuid = packed record
+          class operator =(const left, right : TGuid) : boolean; {$ifdef SYSTEMINLINE} inline; {$endif}
+          class operator <>(const left, right : TGuid) : boolean; {$ifdef SYSTEMINLINE} inline; {$endif}
+          class function Empty : TGuid; static; {$ifdef SYSTEMINLINE} inline; {$endif}
           case integer of
              1 : (
                   Data1 : DWord;

I was get the following error (I use the source code from svn, revision #35175):

C:/FPC/3.1.x/source/compiler/ppc1.exe -Ur -Xs -O2 -n -Twin32 -Pi386 -Fi../inc -Fi../i386 -Fi../win -FE. -FUC:/FPC/3.1.x/source/rtl/units/i386-win32 -di386 -dRELEASE -Us -Sg system.pp -Fi../winobjpash.inc(453,70) Error: $ENDIF expected for $IFDEF FPC_HAS_FEATURE_CLASSES defined in objpash.inc line 1550
Fatal: No memory left

Quite a strange message, that it is difficult to understand where that was. But I got it. At the line 453 of file rtl/inc/objpash.inc:

IObjectInstance: TGuid = '{D91C9AF4-3C93-420F-A303-BF5BA82BFD23}';

So the my code is interfere of constant assignment.

And at the in line 1550 of file rtl/inc/systemh.inc we can see:

{$i objpash.inc}

Here is I stuck. Can anyone suggest what is wrong here? The compiler does not allow include operator overloading or record methods in the system modules? Or is it some kind of a bug?

Dmitriy Pomerantsev.

More information about the fpc-devel mailing list