Permalink
Browse files

JclStringBuilder should know about TObject.ToString

  • Loading branch information...
1 parent 7f02e09 commit 0466d218aaf6b8a327c9572a5284295d38ba0a32 @the-Arioch the-Arioch committed with ahausladen Feb 12, 2013
Showing with 9 additions and 3 deletions.
  1. +1 −0 jcl/source/common/JclResources.pas
  2. +8 −3 jcl/source/common/JclStrings.pas
@@ -1773,6 +1773,7 @@ interface
RsDotNetFormatNullFormat = 'Format string is null';
RsArgumentIsNull = 'Argument %d is null';
RsDotNetFormatArgumentNotSupported = 'Argument type of %d is not supported';
+ RsDotNetFormatObjectArgumentNotSupported = 'Argument type (%s) of %d is not supported';
RsArgumentOutOfRange = 'Argument out of range';
RsTabs_DuplicatesNotAllowed = 'Duplicate tab stops are not allowed.';
RsTabs_StopExpected = 'A tab stop was expected but not found.';
@@ -424,7 +424,7 @@ ArgumentOutOfRangeException = class(EJclError);
// The TStringBuilder class is a Delphi implementation of the .NET
// System.Text.StringBuilder.
// It is zero based and the method that allow an TObject (Append, Insert,
- // AppendFormat) are limited to IToString implementors.
+ // AppendFormat) are limited to IToString implementors or Delphi 2009+ RTL.
// This class is not threadsafe. Any instance of TStringBuilder should not
// be used in different threads at the same time.
TJclStringBuilder = class(TInterfacedObject, IToString)
@@ -3983,10 +3983,15 @@ function DotNetFormat(const Fmt: string; const Args: array of const): string;
Dec(TInterfacedObjectAccess(V.VObject).FRefCount);
end
else
- if InheritsFrom(V.VObject.ClassType, 'TComponent') and V.VObject.GetInterface(IToString, Intf) then
+ if (V.VObject is TComponent) or (V.VObject is TInterfacedPersistent) and V.VObject.GetInterface(IToString, Intf) then
Result := Intf.ToString
+ {$IFDEF RTL200_UP}
else
- raise ArgumentNullException.CreateResFmt(@RsDotNetFormatArgumentNotSupported, [Index]);
+ Result := V.VObject.ToString;
+ {$ELSE}
+ else
+ raise ArgumentNullException.CreateResFmt(@RsDotNetFormatObjectArgumentNotSupported, [V.VObject.ClassName, Index]);
+ {$ENDIF RTL200_UP}
vtClass:
Result := V.VClass.ClassName;
vtWideChar:

0 comments on commit 0466d21

Please sign in to comment.