can I use the Indy Command TIdThreadSafe to make a class MyPrivateClass threadsafe if I define a new Class
MyNewIndyClass = Class(TIdThreadSafe)
FLocal : MyPrivateClass
create
......
end;
My MyPrivateClass is not Threadsafe as I access TList and TBitmap items inside this class
If I change the TCPServer.Onexecutde Code to to following style
......
aNewIndyClass := MyNewIndyClass.Create;
aNewIndyClass.FLocal.CallFuntionA;
aNewIndyClass.FLocal.CallFuntionB;
......
Idea for this approach : Keep MyPrivateClass code unchange, just add the request for the Indy Server onexecute in a separate class
You should use Lock() and Unlock() methods of TIdThreadSafe class. For example in TCPServer.OnExecute() call aNewIndyClass's methods like this:
Also it's better to use properties (i.e. getter/setter) for accessing private or protected members of your MyNewIndyClass class.
By the way if you are using Delphi 2009 and newer you can get advantage of Generics. A short example implementation of a generic thread safe class may be:
Usage: