First time attempting multithreading lazarus / 61-Beginners ---------------------------------------------------------------------- drallim33 · 2018-06-26 23:37 Is this cheating? Exactly which level of hell will I be banished to for spamming these getters/setters in every class I declare?  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 type  TMyProtectedInt = object  private    FTheInt : integer;    function GetTheInt: integer;    procedure SetTheInt(AValue: integer);  public  property Value : integer read GetTheInt write SetTheInt;  end; var  AutoLock : TCriticalSection; implementation function TMyProtectedInt.GetTheInt: integer;begin  AutoLock.Acquire;  result := FTheInt;  AutoLock.Release;end; procedure TMyProtectedInt.SetTheInt(AValue: integer);begin  AutoLock.Acquire;  FTheInt := AValue;  AutoLock.Release;end; initializationAutoLock := TCriticalSection.Create; finalizationAutoLock.Free; ---------------------------------------------------------------------- taazz · 2018-06-27 00:53 Quote from: drallim33 on June 27, 2018, 01:37:25 amIs this cheating? Exactly which level of hell will I be banished to for spamming these getters/setters in every class I declare?  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 type  TMyProtectedInt = object  private    FTheInt : integer;    function GetTheInt: integer;    procedure SetTheInt(AValue: integer);  public  property Value : integer read GetTheInt write SetTheInt;  end; var  AutoLock : TCriticalSection; implementation function TMyProtectedInt.GetTheInt: integer;begin  AutoLock.Acquire;  result := FTheInt;  AutoLock.Release;end; procedure TMyProtectedInt.SetTheInt(AValue: integer);begin  AutoLock.Acquire;  FTheInt := AValue;  AutoLock.Release;end; initializationAutoLock := TCriticalSection.Create; finalizationAutoLock.Free;No, its not cheating its a bad way to serialize access to a single resource, mostly because autolock will lock all variables based on TMyProtectedInt not only the one you try to access, but you can easily solve that by moving the autolock variable in the private section of your class (making sure you create and destroy it with your class as well). Then you have the most basic protection scheme there is. ---------------------------------------------------------------------- drallim33 · 2018-06-27 01:58 Good to know