procedure ExportChainToCMSStream(AStream: TStream; EndIndex: Integer; Sort: Boolean; IncludeRoot: Boolean);