Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TIdSync vs TThread.Synchronize
#1
Hi, just wondering: does TIdSync nowadays still work in the latest Indy version?  I see a warning saying it is deprecated and suggest to change to use TTThread.Synchronize, however in and old "indy indepth" doc, it introduces TIdSync as following

TIdSync
TThread has a Synchronize method, but it does not support the ability to pass parameters to
synchronized methods. TIdSync allows for synchronizations with the ability to pass parameters to the
synchronized methods as well. TIdSync also allows for return values to be returned from the main
thread.


I use TIdsync a lot with passed in paramteres and return value (mainly to read property value of a UI component on the main form).
Now, if I switch to use TTThread.Synchronize, is it really as easy as using TIdsync to allow pass parmater to and get return value? 
And if I keep the code as is (using TIdsync), what would be a potential risk of this in future considering it is now "deprecated"? 

Thank you very much.
Reply
#2
(02-19-2021, 08:08 AM)happyzj Wrote: Hi, just wondering: does TIdSync nowadays still work in the latest Indy version?

Yes, it is still fully implemented. As is TIdNotify.

(02-19-2021, 08:08 AM)happyzj Wrote: I see a warning saying it is deprecated and suggest to change to use TTThread.Synchronize

Only in versions of Delphi/C++Builder/FreePascal that support the public TThread.Synchronize() that takes an anonymous procedure as input.

(02-19-2021, 08:08 AM)happyzj Wrote: however in and old "indy indepth" doc, it introduces TIdSync as following

That doc is OLD, it predates a lot of changes to Indy's internals.

(02-19-2021, 08:08 AM)happyzj Wrote: I use TIdsync a lot with passed in paramteres and return value (mainly to read property value of a UI component on the main form).
Now, if I switch to use TTThread.Synchronize, is it really as easy as using TIdsync to allow pass parmater to and get return value? 

It is easier, using an anonymous procedure, for example:

Code:
var TheResult: TheType;
TThread.Synchronize(nil,
  procedure
  begin
    TheResult := DoSomethingWith(parameters);
  end
);

(02-19-2021, 08:08 AM)happyzj Wrote: And if I keep the code as is (using TIdsync), what would be a potential risk of this in future considering it is now "deprecated"? 

It will not be removed in Indy 10, but it will likely be removed in Indy 11 with other deprecated features, whenever that eventually gets released.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)