Do I have The chance to test some variable, which contain text by using value from editable field without using onevent? I have found out, that very probably really no. Because no if then condition work. Even The condition which detect if some variable is '', condition block simply do not work. So really, I can not use condition blocks which will examine some variable which contain text from editable fied without using events?
Mailing lists / pas2js / 2020-09
onevent question
8 messages · 3 people · –
- MMgr. Janusz Chmiel 4
- MMichael Van Canneyt 3
- JJean SUZINEAU 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Mgr. Janusz Chmiel wrote 6 lines
I don't understand your question ?
var
Edt : TJSHTMLInputElement;
begin
If Edt.Value'' then
DoSomething;
end;Always works.
Michael.
OK. Here is my important part of The code.
var
o1: TTextInputWidget;
after begin word
There is long code but. Can be condition block after refreshing all objects such as
FMyPage.Refresh;
If yes, here is conditional block
if o1.value ='Ofélie' then window.alert('Správně, Ofélie.'); But condition block do not react and I have correctly typed Ofélie
word on The firstly created editable input box.
So is it possible to detect value on run-time if TTextInputWidget object is used?
Or I would had to use other variable data type such as TJSHTMLInputElement I have my long code with 36 successfully created input boxes with labels but now, when I Enter values on some of it, condition blocks do not work.
Mgr. Janusz Chmiel wrote 14 lines
Yes, after you did Refresh of your object.
Michael.
Yes, I have placed if then block after lash object refresh. The next important aspect is, if value do not return also other English words than only typed characters to The editable field. I have used writeln and I have found out, that there are some English words even if editable ifeld is empty and variable should be also empty.
Mgr. Janusz Chmiel wrote 5 lines
I'm very sorry, but I really do not understand what you're trying to say. Please post the *exact* code that does not work for you.
Michael.
Do I have The chance to test some variable, which contain text by using value from…
I guess you are not used to using components.
The code below is working for me. The visual aspect is not very good, it would be necessary to add line breaks between the questions.
============================
program project1;
{$mode objfpc}
uses
browserapp, JS, Classes, SysUtils, Web, webwidget, htmlwidgets;
type
TMyApplication
=
class(TBrowserApplication)
procedure doRun; override;
end;{ TQuestion }
TQuestion
=
class
l: TLabelWidget;
ti:TTextInputWidget;
Question, Answer: String;
constructor Create( _ba: TBrowserApplication; _wp: TWebPage;
_Question, _Answer: String);
procedure tiInput( _Sender : TObject; _Event : TJSEvent);
end;{ TQuestion }
constructor TQuestion.Create( _ba: TBrowserApplication; _wp: TWebPage;
_Question, _Answer: String);
begin
Question:= _Question;
Answer := _Answer;
ti:=TTextInputWidget.Create(_ba);
l:=TLabelwidget.Create(_ba);
l.Text:=_Question;
l.LabelFor:= ti;
// Order is important.
l .Parent:= _wp;
ti.Parent:= _wp;
ti.OnInput := @tiInput;
//ti.OnChange:= @tiInput;
l .Refresh;
ti.Refresh;
end;
procedure TQuestion.tiInput( _Sender: TObject; _Event: TJSEvent);
begin
if ti.value = Answer
then
window.alert( 'Success, answer to question '+Question+' is
'+Answer);
end;
procedure TMyApplication.doRun;
var
wp: TWebPage;
begin
wp:=TWebPage.Create(Self);
wp.Parent:=TViewPort.Create(Nil);
TQuestion.Create( Self, wp, 'Question 1', 'Answer 1');
TQuestion.Create( Self, wp, 'Question 2', 'Answer 2');
TQuestion.Create( Self, wp, 'Question 3', 'Answer 3');
wp.Refresh;
Terminate;
end;
var
Application : TMyApplication;
begin
Application:=TMyApplication.Create(nil);
Application.Initialize;
Application.Run;
//Application.Free;
end.aOh dear MR
SUZINEAU
Wonderful example!!! I have done big error. I have tried to bypass The fact, that it is necessary to create more procedures and that it is necessary to detect events.
Pascal is not simple Basic language. Thank you for yours example. I will be able to begin from scratch by using yorus code sample. Thank you very much.
