How to use

Just add the unit at the TOP of your .dpr uses clause, just after FastMM4 (if you use it, and you should!) i.e. before all other units used by your program.
It should be initialized before any WideString is allocated.

Then the patch will be applied at runtime.
Nothing to recompile!

WARNING

  USING THIS UNIT MAY BREAK COMPATIBILITY WITH OLE/COM LIBRARIES !

You won't be able to retrieve and release WideString/BSTR variables from an OleDB / ADO database provider, or any COM object.
Do not use this unit if you are calling such external call!

In practice, if you only send some BSTR content to the provider (e.g. if you use our SynOleDB unit without stored procedure call, or if you use TWideStringField for most SynDBDataSet classes), it will work. As far as we tested.
You would have issues if you retrieve a BSTR from the COM object, or expect the COM object to change the BSTR size, e.g. with a var WideString parameter or a COM method returning a WideString

The following method should work, since it is using a WideString as input parameter:

type
_Catalog = interface(IDispatch)
function Create(const ConnectString: WideString): OleVariant; safecall;
But the following won't, since it returns a WideString value, which will fail to be released by our SynFastWideString unit, since it is a true BSTR instance allocated by the COM library, and not an AnsiString allocated via FastMM4:
type
_Catalog = interface(IDispatch)
function GetObjectOwner(const ObjectName: WideString; ObjectType: OleVariant;
ObjectTypeId: OleVariant): WideString; safecall;

In this case, you could use the WideStringFree() procedure, as defined in the SynFastWideString unit, to release such an instance.

This unit is for educational purpose only, and/or if you are 100% sure that your code will stay self-contained, under Delphi 7 or Delphi 2007, and need use of WideString instead of string AnsiString.

   YOU HAVE BEEN WARNED - USE AT YOUR OWN RISK !

Feedback is welcome, e.g. on Google+ this time!