<p>A little example</p>

<pre><code>TTest&lt;T&gt; = class
private
  f : T;
public
  function ToString : string;
end;
</code></pre>

<p>If  is an object then this should work</p>

<pre><code>TTest&lt;T&gt;.ToString;
begin
  Result := f.ToString;
end;
</code></pre>

<p>But what happens when  is say an integer? This would be ok in .net. of course.</p>

<p>I know it won't work, but how do I code this to work with objects AND simple types?</p>

The last example will not work. You need to add a constraint in order to use methods. In this case TObject will be enough:
```
```
TTest<T: TObject>.ToString;
begin
  Result := T.ToString;
end;
```
```
You can use simple types with unrestrained generics, but you are very limited in the use. Because the only valid operations are assignment and comparison (equal and not equal).
In Delphi simple types are no classes, so they don't have methods.
But you can do the following:
```
```
type
  TToString<T> = reference to function(const AValue: T): string;
  TGenContainer<T> = class
  private
    FValue: T;
    FToString : TToString<T>;
  public
    constructor Create(const AToString: TToString<T>);

    function ToString: string;

    property Value: T read FValue write FValue;
  end;

constructor TGenContainer<T>.Create(const AToString: TToString<T>);
begin
  FToString := AToString;
end;

function TGenContainer<T>.ToString: string;
begin
  Result := FToString(FValue);
end;

procedure TForm2.Button1Click(Sender: TObject);
var
  gen : TGenContainer<Integer>;
begin
  gen := TGenContainer<Integer>.Create(
    function(const AValue: Integer): string
    begin
      Result := IntToStr(AValue);
    end);
  try
    gen.Value := 17;
    Memo1.Lines.Add(gen.ToString);
  finally
    gen.Free;
  end;
end;
```
```
This works fine.