Pointer Address to Class[SOLVED] lazarus / 21-General ---------------------------------------------------------------------- Schmitty2005 · 2025-08-19 02:16 I have a pointer to a class, and I want to use that pointer to set the address of a class in a procedure, and be able to use that class in the procedure.  What is the best way to do that in Delphi mode of FPC Pascal ? I am trying out the MTProcs library.  aPCM is a TMemoryStream Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  var   aPCM : TmemoryStream;begin  aPCM := TMemoryStream.Create;......aPCM is filled with data (16 bit PCM sine wave)......ProcThreadPool.DoParallel(@calcParTube, 0, (aPCM.Size * SizeOf(Int16)), aPCM);// I have also tried @aPCM  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure calcParTube(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem);var   anotherPCM : TmemoryStream;begin   anotherPCM  := Data;//Data Should be the pointer to the class passed by ProcThreadPool.DoParallel, but does not                           // seem to point properly   anotherPCM.Free(); This is just for fun and learning pascal.  I am likely missing something fundamental. Any Ideas ? Here is some sample code that works fine  to assign a class  using a pointer : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$MODE DELPHI}program Project1; uses  Classes; var  aPCM: TmemoryStream;  pnt: Pointer;  bPCM: TMemoryStream; begin  aPCM := TmemoryStream.Create;  aPCM.Write(pnt, sizeOF(pnt)); //Just to write some data  pnt := aPCM;  bPCM := pnt; //works  pnt := @aPCM;  bPCM := pnt;  //don't work  bPCM := aPCM;   //Works  aPCM.Free; //no need to free bPCM, no ref ?end. ---------------------------------------------------------------------- Wallaby · 2025-08-19 02:32 You’re freeing the stream in the worker, so it becomes invalid for the remaining iterations. Only free it after DoParallel returns, and pass the object reference: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure calcParTube(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem); var   anotherPCM : TmemoryStream absolute Data; begin //work with anotherPCM , it's already assigned via the "absolute" directive. end;  aPCM := TMemoryStream.Create;...ProcThreadPool.DoParallel(@calcParTube, 0, (aPCM.Size * SizeOf(Int16)), aPCM);... aPCM.Free; //<-free it after all iterations have run. ---------------------------------------------------------------------- Schmitty2005 · 2025-08-19 02:54 Thank you for that Answer!  It makes total sense.  I like the use of the absolute keyword!   For some reason, I am unable to simply even get the size of anotherPCM.  I get a segFault.  In the debugger, it shows this object as a TMultiThreadProcItem.   I have attached a few small screen snippets. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure calcParTube(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem); var  anotherPCM : TmemoryStream absolute Data;   sizer : Int64;begin  sizer:=   anotherPCM.Size;  //causes segfault   //aPCM.Free();end; ---------------------------------------------------------------------- Wallaby · 2025-08-19 10:26 The above code is correct (and the debugger is likely wrong) - please post the rest of your code here. ---------------------------------------------------------------------- Schmitty2005 · 2025-08-19 22:39 I got the code to work.  I was missing Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$ModeSwitch nestedprocvars}   as described here in the 'Do Parallel' section: https://wiki.freepascal.org/Parallel_procedures The debugger now shows anotherPCM as a TMemoryStream class, and the procedure will actually get the size. Thank you Wallaby for your assistance and pointing out that the code was correct and should work.