title: Passing pointer to an object in BeginThread method
body: <p>I have basic classes like following: </p>
  
  <pre><code>Type
  Test = class
  
  end;
  
  TestIpl = class (Test)
  
  end
  </code></pre>
  
  <p>Then I create object: </p>
  
  <pre><code>obj = TestIpl.Create();
  </code></pre>
  
  <p>Now I would like to pass this object to BeginThread, which goes like this: </p>
  
  <pre><code>BeginThread(nil, 0, @mtd, obj, 0, Threadinfo.ThreadId);
  </code></pre>
  
  <p>In method: mtd I would like to use created object, so I cast this like this: </p>
  
  <pre><code>var 
    obj: Test;
  begin
  obj :=  Test(DataParameter);
  </code></pre>
  
  <p>Am I doing this correctly, but what's more important. Can it be done like this?
  I am anxious about the line which casts pointer to its original object. Will it work this way?</p>
  
  <p>Currently, I get AV when I want to use overloaded method in testIpl.
  Thanks</p>
  
  <p>EDIT</p>
  
  <pre><code>function mtd(DataParameter: Pointer): DWORD; stdcall;
  </code></pre>
  
  <p><strong>TEST CASE</strong></p>
  
  <pre><code>unit Unit2;
  
  interface
  
  Type
    Test = class
    protected
      function Test(): Integer; virtual;
    end;
  
    TestIpl = class (Test)
    protected
      function Test(): Integer; override;
    end;
  
  procedure TestCase;
  
  implementation
  
  function RunThread(Parameter: Pointer): Integer;
  var
    x: Test;
    Rslt: Integer;
  begin
    x := Test(Parameter);
  
    Rslt := x.Test();
  end;
  
  
  procedure TestCase;
  var
    test: TestIpl;
    ThreadId: Cardinal;
  begin
    test := TestIpl.Create;
  
    BeginThread(nil, 0, Addr(RunThread), Addr(test), 0, ThreadId);
  end;
  
  { Test }
  
  function Test.Test: Integer;
  begin
    Result := 1;
  end;
  
  { TestIpl }
  
  function TestIpl.Test: Integer;
  begin
    Result := 2;
  end;
  
  end.
  </code></pre>