<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">Could it be because you do not zero out
      the allocated memory?<br>
      <br>
      <br>
      Le 04/06/2024 à 10꞉54, Hairy Pixels via fpc-pascal a écrit :<br>
    </div>
    <blockquote type="cite"
      cite="mid:E91629D8-E202-4C98-AD70-7B01F1E4AACD@gmail.com">
      <pre class="moz-quote-pre" wrap="">In the manual it at <a class="moz-txt-link-freetext" href="https://www.freepascal.org/docs-html/ref/refse38.html">https://www.freepascal.org/docs-html/ref/refse38.html</a> it says "Calling the constructor will provoke a call to the virtual class method NewInstance, which, in its default implementation, calls GetMem, to allocate enough space to hold the class instance data, and then zeroes out the memory."

I'm trying this like below but it crashes. Is this correct? The fact NewInstance returns TObject instead of Pointer doesn't make sense to me and suggests this isn't correct.

  class function TDataObject.NewInstance: TObject;
  begin
    result := TObject(GetMem(InstanceSize));
  end;

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  <a class="moz-txt-link-abbreviated" href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a>
</pre>
    </blockquote>
    <br>
    <div id="grammalecte_menu_main_button_shadow_host" style="width:
      0px; height: 0px;"></div>
  </body>
</html>