Jump to content

Change at Runtime uniPanel.Caption


irigsoft

Recommended Posts

Hi all,

I make application on mobile device and check battery status with this on Timer event:

  WebForm.JSForm.JSCode ('navigator.getBattery().then(function(battery) {'
                      + ' document.getElementById(''' + MyPanel.JSId + ''').innerText= battery.level * 100;'
                      + '});');  - This change innerText, but when I try to read (from other component) MyPanel.Caption is empty.

 

I have a problem to change uniPanel.Caption on my Top Form to uniPanel.Caption := Battery.level

I see (with F12) that html of uniPanel is div -> div -> div -> table -> tr -> unipanel .Caption

Link to comment
Share on other sites

I was able to change the value of the table -> tr to Battery Level, but uniPanel.Caption is still blank when read by another component

  WebForm.JSForm.JSCode ('navigator.getBattery().then(function(battery) {'
                      + ' document.getElementById(''' + uniMyPanel.JSId + ''')'
                      + '.querySelector("#_td").innerText'
                      + ' = battery.level * 100;'
                      + '});');

In mainform uniPanel.Caption (table -> tr ) show battery lever, but Value of Caption is empty, why ?

Link to comment
Share on other sites

2 hours ago, irigsoft said:

Professional 1513

Thanks.

1 hour ago, irigsoft said:

I was able to change the value of the table -> tr to Battery Level, but uniPanel.Caption is still blank when read by another component

Can you please make a simple app to see what do you want to achieve?

Link to comment
Share on other sites

I will try to explain:
1. I have a uniform , unipanel and unitimer in it.
The timer checks every minute for the battery level by performing the function:

WebForm.JSForm.JSCode ('navigator.getBattery().then(function(battery) {'
                      + ' document.getElementById(''' + uniMyPanel.JSId + ''')'
                      + '.querySelector("#_td").innerText'
                      + ' = battery.level * 100;'
                      + '});');

and save in uniPanel.Caption the battery level.

Another uniTimer checks every 5 minutes for the value in the unipanel.Caption and when a certain value is reached it must send a message to the server (Save on database).

I use uniPanel.Caption as a variable in which to store the value of the battery and thus the other components of the unimainmodule will have access to its values.

I was able to achieve with the function of visualizing the battery, reading by changing the program code in html, but this does not change the value of the unipanel component.

I thought that changing the value in html would allow the other components in the form to get the Caption value (by Delphi code), but I'm obviously wrong.
Now I'm looking for Javacode (or another method) to change the value of a certain element on the screen so that the other components can read it with Delphi code.

Link to comment
Share on other sites

Start session, Timer1 start and check battery, save level on uniPanel every one minute.

on UniTimer1Timer

    WebForm.JSForm.JSCode ('navigator.getBattery().then(function(battery) {'
                      + ' document.getElementById(''' + uniMyPanel.JSId + ''')'
                      + '.querySelector("#_td").innerText'
                      + ' = battery.level * 100;'
                      + '});');

 

Timer2 check every 5 minutes uniPanel.Caption,

on UniTimer2Timer

    if uniPanel.Caption = '5' then AdoQuery.Add (Insert on BAtteryLevelLow (SessionID,Level) values (''' + uniSessionID + '','' + uniPanel.Caption +'));

or ( Ext.toast('LowBattery level : Panel_BatteryLevel.Caption!','Message');)

Link to comment
Share on other sites

40 minutes ago, irigsoft said:

I will try to explain:

procedure TMainForm.UniTimer1Timer(Sender: TObject);
begin
  Self.WebForm.JSInterface.JSCode(
    'navigator.getBattery().then(function(battery) {'+
    '  ajaxRequest('+ UniPanel1.JSName +', "setcaption", ["level=" + battery.level * 100])'+
    '});'
  )
end;
procedure TMainForm.UniPanel1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName = 'setcaption' then
  begin
    (Sender as TUniPanel).Caption := Params.Values['level'];
  end;

end;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...