I was working on COM Interop, and I got troubled with creating a Guid record every time I need to call a function that needs one.
You see, a GUID is associated with an interface declaration, and since it's in the interface, why should I have to copy and paste the GUID, when I specify the type?
Here's an example of an interface declaration.
[ComImport, Guid('CB2F6722-AB3A-11D2-9C40-00C04FA30A3E'), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] ICorRuntimeHost = interface ... end;
So, I wrote a helper function that takes a given type, and returns the Guid declared on the type with the GuidAttribute.
function AttrToGuid(AType: System.Type): Guid;var Attrs: array of TObject;begin Attrs := AType.GetCustomAttributes(typeof(GuidAttribute), False); Result := System.Guid.Create(GuidAttribute(Attrs[0]).Value);end;
And here's how you call it...
AttrToGuid(typeof(ICorRuntimeHost));
While working on the code, I came across Oleg Lvovitch's Blog, about custom attributes.
In 2017, with the release of Delphi 10.2 Tokyo, Embarcadero introduced a specialized implementation of the Observer pattern into the System.Classes unit. While it has been in the wild for 9 years, it remains a "hidden" architecture for many, primarily because it serves as the invisible engine behind LiveBindings. Other than live bindings, you can also use the Observer pattern as a way to update component settings to the Windows registry, an .ini file, or persist it elsewhere.
System.Classes