Skip to content

Class to facilitate the creation of Anonymous Threads in your project

License

Notifications You must be signed in to change notification settings

adrianosantostreina/CustomThread

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CustomThread

CustomThread

Class to facilitate the creation of Anonymous Threads in your project

Installation

Just register in the Library Path of your Delphi the path of the SOURCE folder of the library, or if you prefer, you can use Boss (dependency manager for Delphi) to perform the installation:

boss install github.com/adrianosantostreina/CustomThread

⚡️ Quickstart

The CustomThread unit has a TLib class that implements the CustomThread method. It has the following parameters:

class procedure TLib.CustomThread(
      AOnStart, 
      AOnProcess, 
      AOnComplete: TProc; 
      AOnError: TProcedureExcept;
  const ADoCompleteWithError: Boolean
);
  • AOnStart = Processes to run before the main process
  • AOnProcess = Main Process
  • AOnComplete = Processes to run after the main process
  • AOnError = Process to run if errors occur
  • ADoCompleteWithError = Fired exception message if error occurs

Use

Declare Loading in the Uses section of the unit where you want to make the call to the class's method.

uses
  CustomThread,
procedure TForm2.Button1Click(Sender: TObject);
begin
  TLib.CustomThread(
    procedure()
    begin
      //Processes to run before the main process
    end,
    procedure()
    begin
      //Main Process
    end,
    procedure()
    begin
      //Processes to run after the main process
    end,
    procedure(const AException: string)
    begin
      //Process to run if errors occur
    end,
    True
  );
end;

Like This

[...]
private
    { Private declarations }
    StepUnit: Single;
    Step : Single;
[...]


procedure TForm2.FormCreate(Sender: TObject);
begin
StepUnit := 0;
Step := 0;
recProgress.Width := 0;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
TLib.CustomThread(
procedure()
begin
    //Processes to run before the main process
    StepUnit := (recBack.Width / 10);
    recProgress.Width := Step;
end,
procedure()
begin
    //Main Process
    repeat
    Step := Step + StepUnit;
    TThread.Synchronize(
        TThread.CurrentThread,
        procedure ()
        begin
        Sleep(100);
        recProgress.Width := Step;
        end
    );
    until recProgress.Width >= recBack.Width;
end,
procedure()
begin
    //Processes to run after the main process
    Step := 0;
end,
procedure(const AException: string)
begin
    //Process to run if errors occur
end,
True
);
end;

Video

Watch the video

Documentation Languages

English (en)
Português (ptBR)

⚠️ License

CustomThread is free and open-source library licensed under the MIT License.

About

Class to facilitate the creation of Anonymous Threads in your project

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages