From Clomosy Docs

No edit summary
No edit summary
Line 1: Line 1:
The sleepAndCall function represents a function that waits for a specific duration and then executes a specified callback function. This type of function can be used to wait for the completion of a specific task and then proceed to execute another function.
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
procedure Clomosy.SleepAndCall(millisecond:Integer,BeforeSleep,AfterSleep:String);
</div>


Clomosy.SleepAndCall(millisecond,<nowiki>'',''</nowiki>);
The sleepAndCall function represents a function that waits for a specific duration and then executes a specified callback function. This type of function can be used to wait for the completion of a specific task and then proceed to execute another function.<br>


The first parameter specifies the duration to wait (in milliseconds). The second parameter represents the action to be triggered before the waiting process. The third parameter executes the specified callback function after the waiting process is completed.
The first parameter specifies the duration to wait (in milliseconds). The second parameter represents the action to be triggered before the waiting process. The third parameter executes the specified callback function after the waiting process is completed.<br>


'''Example:'''<br>
<b>Example</b><br>
:'''Base Syntax'''
<b>TRObject Syntax</b><br>
var
<pre>
var
   MyForm:TclForm;
   MyForm:TclForm;
   sleepBtn : TclButton;
   sleepBtn : TclButton;
 
Procedure getAfterSleep;
void getAfterSleep;
begin
{
  sleepBtn.Text = 'AFTER SleepAndCall';
}
 
void getBeforeSleep;
{
  sleepBtn.Text = 'BEFORE SleepAndCall';
  //MyForm.StartProcessMessages(5000);
  Clomosy.SleepAndCall(3000,'','getAfterSleep');
}
 
{
  MyForm = TclForm.Create(Self);
  sleepBtn= MyForm.AddNewButton(MyForm,'sleepBtn','Click');
  sleepBtn.TextSettings.Font.Size=30;
  sleepBtn.Align = alCenter;
  sleepBtn.Height = 70;
  sleepBtn.Width = 200;
  MyForm.AddNewEvent(sleepBtn,tbeOnClick,'getBeforeSleep');
 
  MyForm.Run;
}
</pre>
<b>Base Syntax</b><br>
<pre>
var
  Form1:TclForm;
  sleepBtn : TclButton;
 
Procedure getAfterSleep;
begin
   sleepBtn.Text := 'AFTER SleepAndCall';
   sleepBtn.Text := 'AFTER SleepAndCall';
end;
end;
 
Procedure getBeforeSleep;
Procedure getBeforeSleep;
begin
begin
   sleepBtn.Text := 'BEFORE SleepAndCall';
   sleepBtn.Text := 'BEFORE SleepAndCall';
   //MyForm.StartProcessMessages(5000);
   //Form1.StartProcessMessages(5000);
   Clomosy.SleepAndCall(3000,<nowiki>''</nowiki>,'getAfterSleep');
   Clomosy.SleepAndCall(3000,'','getAfterSleep');
end;
end;
 
begin
begin
   MyForm := TclForm.Create(Self);
   Form1 := TclForm.Create(Self);
   sleepBtn:= MyForm.AddNewButton(MyForm,'sleepBtn','Click');
   sleepBtn:= Form1.AddNewButton(Form1,'sleepBtn','Click');
   sleepBtn.TextSettings.Font.Size:=30;
   sleepBtn.TextSettings.Font.Size:=30;
   sleepBtn.Align := alCenter;
   sleepBtn.Align := alCenter;
   sleepBtn.Height := 70;
   sleepBtn.Height := 70;
   sleepBtn.Width := 200;
   sleepBtn.Width := 200;
   Form1.AddNewEvent(sleepBtn,tbeOnClick,'getBeforeSleep');
   MyForm.AddNewEvent(sleepBtn,tbeOnClick,'getBeforeSleep');
 
   Form1.Run;
   MyForm.Run;
end;
</pre>
end;


:'''TRObject Syntax'''
<h2> See Also </h2>
var
* [[Clomosy_Class#System_Function | System Functions]]
MyForm:TclForm;
sleepBtn : TclButton;
void getAfterSleep;
{
sleepBtn.Text = 'AFTER SleepAndCall';
}
void getBeforeSleep;
{
sleepBtn.Text = 'BEFORE SleepAndCall';
//MyForm.StartProcessMessages(5000);
Clomosy.SleepAndCall(3000,<nowiki>''</nowiki>,'getAfterSleep');
}
{
MyForm = TclForm.Create(Self);
sleepBtn= MyForm.AddNewButton(MyForm,'sleepBtn','Click');
sleepBtn.TextSettings.Font.Size=30;
sleepBtn.Align = alCenter;
sleepBtn.Height = 70;
sleepBtn.Width = 200;
MyForm.AddNewEvent(sleepBtn,tbeOnClick,'getBeforeSleep');
MyForm.Run;
}

Revision as of 12:30, 15 October 2024

The sleepAndCall function represents a function that waits for a specific duration and then executes a specified callback function. This type of function can be used to wait for the completion of a specific task and then proceed to execute another function.

The first parameter specifies the duration to wait (in milliseconds). The second parameter represents the action to be triggered before the waiting process. The third parameter executes the specified callback function after the waiting process is completed.

Example
TRObject Syntax

var
  MyForm:TclForm;
  sleepBtn : TclButton;

void getAfterSleep;
{
  sleepBtn.Text = 'AFTER SleepAndCall';
}

void getBeforeSleep;
{
  sleepBtn.Text = 'BEFORE SleepAndCall';
  //MyForm.StartProcessMessages(5000);
  Clomosy.SleepAndCall(3000,'','getAfterSleep');
}

{
  MyForm = TclForm.Create(Self);
  sleepBtn= MyForm.AddNewButton(MyForm,'sleepBtn','Click');
  sleepBtn.TextSettings.Font.Size=30;
  sleepBtn.Align = alCenter;
  sleepBtn.Height = 70;
  sleepBtn.Width = 200;
  MyForm.AddNewEvent(sleepBtn,tbeOnClick,'getBeforeSleep');
  
  MyForm.Run;
}

Base Syntax

var
  Form1:TclForm;
  sleepBtn : TclButton;

Procedure getAfterSleep;
begin
  sleepBtn.Text := 'AFTER SleepAndCall';
end;

Procedure getBeforeSleep;
begin
  sleepBtn.Text := 'BEFORE SleepAndCall';
  //Form1.StartProcessMessages(5000);
  Clomosy.SleepAndCall(3000,'','getAfterSleep');
end;

begin
  Form1 := TclForm.Create(Self);
  sleepBtn:= Form1.AddNewButton(Form1,'sleepBtn','Click');
  sleepBtn.TextSettings.Font.Size:=30;
  sleepBtn.Align := alCenter;
  sleepBtn.Height := 70;
  sleepBtn.Width := 200;
  Form1.AddNewEvent(sleepBtn,tbeOnClick,'getBeforeSleep');
  
  Form1.Run;
end;

See Also