Yes, string is a native type with some special compiler magic added.
I don't know what operator overloading you would want. + and = already work as concatenation and equality operators.
However I've thought about doing something similar myself. It might work with a record type with implicit convertors and overloaded add and equals operators (in Win32 Delphi only records can have operator overloading. This is available in D2006 (?2005) only.)
I suspect there may be some performance hit as well.
The syntax would be something like the following:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TString = record
private
Value : string;
public
class operator Add(a, b: TString): TString;
class operator Implicit(a: Integer): TString;
class operator Implicit(const s: string): TString;
class operator Implicit(ts: TString): String;
function IndexOf(const SubStr : string) : Integer;
end;
var
Form1: TForm1;
implementation
class operator TString.Add(a, b : TString) : TString;
begin
Result.Value := a.Value + b.Value;
end;
class operator TString.Implicit(a: Integer): TString;
begin
Result.Value := IntToStr(a);
end;
class operator TString.Implicit(ts: TString): String;
begin
Result := ts.Value;
end;
function TString.IndexOf(const SubStr : string) : Integer;
begin
Result := Pos(SubStr, Value);
end;
class operator TString.Implicit(const s: string): TString;
begin
Result.Value := s;
end;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
ts : TString;
begin
ts := '1234';
ShowMessage(ts);
ShowMessage(IntToStr(Ts.IndexOf('2')));
end;
end.
Apparently you can have "record helpers" as well, but I've never tried it myself.