Forum > General

TFORM ON CREATE WITH IF CONDITION

(1/2) > >>

Root2:
Dear community, I am trying to display a message every time a value changes to 1, the condition is that the program should run even when the window is not focused something similar to a daemon but from a form, for that I have this code.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormCreate(Sender: TObject);begin   ShowMessage('frm creado');  if Tag2.Value=1 then;  begin     ShowMessage('value changed to 1');  endend; 
However, when executing it sends me directly the messages, it is as if it was not evaluating the condition.

The condition that I am evaluating is a value that I receive from a PLC controller.

Thank you very much for your kind attention.

Best regards.

dseligo:

--- Quote from: Root2 on June 17, 2022, 07:00:49 pm ---The condition that I am evaluating is a value that I receive from a PLC controller.

--- End quote ---

How do you receive this value? Can't you show message from there?

Handoko:
Not fully know what OP want to achieve but here are some general advises:

* Form's OnCreate event is for initializing variables, objects or states only. You should not do any heavy calculation nor long duration file loading, and should not perform any screen displaying, in your case showing a message box.

* To make it less annoying, consider using Form1.Caption := 'something'; instead of using a ShowMessage.

* You can consider putting your code for evaluating the value inside a TTimer's event.

Lansdowne:

--- Quote from: Root2 on June 17, 2022, 07:00:49 pm ---Dear community, I am trying to display a message every time a value changes to 1, the condition is that the program should run even when the window is not focused something similar to a daemon but from a form, for that I have this code.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormCreate(Sender: TObject);begin   ShowMessage('frm creado');  if Tag2.Value=1 then;  begin     ShowMessage('value changed to 1');  endend; 
However, when executing it sends me directly the messages, it is as if it was not evaluating the condition.

The condition that I am evaluating is a value that I receive from a PLC controller.

Thank you very much for your kind attention.

Best regards.

--- End quote ---

You have a typo.
You have
if Tag2.Value=1 then;

The semicolon ";" should not be present. 

Zaxxon:
You can try:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormCreate(Sender: TObject);begin  Startup:=True;end;

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormShow(Sender: TObject);begin  if Startup then begin    Startup:=False;    ShowMessage('frm creado');    if Tag2.Value=1 then begin      ShowMessage('value changed to 1');    end;  end;end; 

Navigation

[0] Message Index

[#] Next page

Go to full version