From Clomosy Docs
We use AddNewEvent when we want an event to occur. This occurrence triggers the execution of a procedure called an event handler. In this way, the transaction takes place. Example; Like a button click prompt.
AddNewEvent(TControl, TBasisEvent, String)
TControl: In its first parameter we will write what will trigger it. For example, take action when a button is clicked.
TBasisEvent: The second parameter is an actuation state. In other words, when the user makes a move, for example, when he clicks the button, proceed with the action.
You can look at the TBasisEvent constants that can be given to this parameter on the TBasisEvent page.
String: We need to determine what will show when clicked. It can show a sample message or go to a procedure.
Sample:
Let's understand better with an example. In the example, when the button is clicked, the code will be scanned and this read barcode code will be written on edit.
For this, TClButton, TclEdit and then to create a form.
Var
MyForm:TFrmClomosyBasisForm;
testBtn : TClButton;
testEdit : TclEdit;
After creating the definitions, when the button is clicked, a procedure should go and read the barcode in this procedure and write the barcode code in the edit. For this we need to define the following code.
procedure BtnOnClick;
begin
MyForm.CallBarcodeReader(testEdit);
end;
Now that the definitions and procedure have been created, let's start coding. Let's define our form.
MyForm := TFrmClomosyBasisForm.Create(Self);
Then, let's make the settings of the variable we defined as "testEdit" to show the barcode code on the screen after the barcode is read. So let's create it by saying "AddNewEdit" and then determine its position and height. Let's assign its position to the top of our screen by saying "alTop".
testEdit := MyForm.AddNewEdit(MyForm,'testEdit','Barcode here ...');
testEdit.Align := alTop;
testEdit.Height := 40;
Let's define our button and create its design. In order for it to be in the middle of our screen, we need to define it as "alCenter".
testBtn := MyForm.AddNewButton(MyForm,'testBtn','Scan Barcode...');
testBtn.Align := alCenter;
testBtn.Height := 100;
testBtn.Width := 200;
Now that we have finished all the stages, let's use our "AddNewEvent" feature. We will perform a transaction. So when the button is clicked go to the procedure and read the barcode. Then write the code in "edit".
When "testBtn" is clicked, it will go to the "BtnOnClick" procedure.
MyForm.AddNewEvent(testBtn,tbeOnClick,'BtnOnClick');
Finally, we need to run our form. If this code is not written, the application screen will not appear.
MyForm.Run;
Code:
Var MyForm:TFrmClomosyBasisForm; testBtn : TClButton; testEdit : TclEdit;
procedure BtnOnClick; begin MyForm.CallBarcodeReader(testEdit); end;
begin MyForm := TFrmClomosyBasisForm.Create(Self); testEdit := MyForm.AddNewEdit(MyForm,'testEdit','Barcode here ...'); testEdit.Align := alTop; testEdit.Height := 40;
testBtn := MyForm.AddNewButton(MyForm,'testBtn','Scan Barcode...'); testBtn.Align := alCenter; testBtn.Height := 100; testBtn.Width := 200; MyForm.AddNewEvent(testBtn,tbeOnClick,'BtnOnClick'); MyForm.Run;
end;
Output: