irigsoft Posted August 29, 2020 Share Posted August 29, 2020 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 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 29, 2020 Share Posted August 29, 2020 Hello, Sorry, are you still using the trial edition!? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted August 29, 2020 Author Share Posted August 29, 2020 No, Professional 1513 Quote Link to comment Share on other sites More sharing options...
irigsoft Posted August 29, 2020 Author Share Posted August 29, 2020 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 ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 29, 2020 Share Posted August 29, 2020 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? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted August 29, 2020 Author Share Posted August 29, 2020 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. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 29, 2020 Share Posted August 29, 2020 9 minutes ago, irigsoft said: uniPanel.Caption I.e. you have a desktop application, right? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted August 29, 2020 Author Share Posted August 29, 2020 No, unigui server as StandAlone. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted August 29, 2020 Author Share Posted August 29, 2020 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');) Quote Link to comment Share on other sites More sharing options...
Sherzod Posted August 29, 2020 Share Posted August 29, 2020 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; Quote Link to comment Share on other sites More sharing options...
irigsoft Posted August 29, 2020 Author Share Posted August 29, 2020 10x, i try with this but error ocured: uniPanel.JSInterface.JSCall ('element.setcaption',['battery.level']); I will try with Your code Quote Link to comment Share on other sites More sharing options...
irigsoft Posted August 29, 2020 Author Share Posted August 29, 2020 Thanks, everything is working properly. Today I looked at a similar example, but I wanted to avoid using AjaxEvent, everything goes through Javascript, but this is a solution. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.