OmniThreadLibrary Example #1: Beep, world!
Start by creating a new Delphi VCL application. Drop a button on the form and write OnClick handler. procedure TfrmTestOTL.btnBeepClick(Sender: TObject); This will create a threaded task with name 'Beep' and main method Beep. Then the code will create a new thread and start executing this task in the context of the newly created thread. That's all, folks! To make the example fully functional, add OtlTask unit to the uses list and write the Beep method. procedure TfrmTestOTL.Beep(task: IOmniTask); Run the program, click the button. It will beep! If you don't believe that the code is executed in a secondary thread, place a breakpoint on the MessageBeep call and check the Thread Status window. It will clearly indicate that the breakpoint was triggered from a secondary thread. This example is included in the OTL repository in folder tests/0_Beep. Labels: Delphi, multithreading, OmniThreadLibrary, open source, programming, source code, work in progress |