It's strange that one app is functioning properly while the other one returns an empty string even though the code i exactly the same. Is the application running on another PC? Did you check the version number of the edge chromium installed on that PC?
It is the same PC, same Delphi-version, same components, just another project.
Can it be that it is a diference in dll's in the projectflder, or maybe the uses-clause ?
Are you copying the DLLs in the output exe directory? If so, it can be that this is the reason. Please check if the DLLs are the latest version available in the installation directory of TMS VCL UI Pack.
It seems the cause was a combination of different things.
There was a method called in an TActionUpdate-event that caused the memo to be empty again. Also I did not understand the fact that ExecuteJavascript was asynchroon.
I now have a repeat-until loop with application.processmessages in it, that repeats until the memo.lines are not empty.
QUESTION: Is there a better way to do this ?
(I would like to have a function that returns the innerHtml as a result.)
Also, what could be the equivalent of the event OnCommandStateChange of the TWebBrowser-component ? I used this to udpate the data after the marker was moved. I tried many thins (like mouseup, documentComplete etc..) but no event is triggered after I moved the marker in the map.
In the latest version, we have added ExecuteJavaScriptSync, which synchronously returns the value from the JavaScript function, so you can actually replace the code with
or at least the form declaration variable (above the implementation section). Right now, I see you are using the form class type instead of the actual variable.
But what is the next step ? I am not familiar with this technique, so sorry if it is a simple question.
I thought :
the code you put in the FormCreate, I placed that in the procedure where I do the navigation: each time after the URL is set. Is that correct ?
Also, If I put a breakpoint in "TCoreWebView2HistoryChangedEventHandler", that is never executed.
Where should I place my code to read the new html ( to extract the new location of the marker ) ?
You should place the code inside the FormCreate, then it should be triggered when navigating. If the history is not updated, then there is a need for another event. Can you elaborate on the technique that you are using to update the marker? Is the URL updated? Alternatively, you can start a timer, and read out the marker using JavaScript or read out the URL.
Thank you, but this does not work --> the event is not triggered when moving the marker.
Let me try to explain how it works:
When the marker is moved around, javascript functions call the google API and the GPS-location and the nearest adress is shown.
The URL is not updated.
In TwebBrowser, the event OnCommandStateChange is triggered when moving the marker around.
in the OnCommandStateChange event, I enable a timer to read the (changed) html after 100ms.
I double check the state (moving or not) , and if the marker is not moving, I extract the new adres from the html.
Additionaly : I tried to mimmick the old behaviour with TAdvWebBrowser-events like mousemove, mousedown, mouseUp... but these events are also not triggerd when I move the mouse over the map...
What is the purpuse of these events since they never get triggered ?
They are inherited from a base control. They are currently not triggered, we'll add this on our list for investigation. I'm currently looking into the marker update event question. Will update this post with a sample on how to achieve this.
So what you can do to communicate with the client from a web-page, is installing a bridge. This involves adding an object, that implements the IAdvCustomWebBrowserBridge. This allows you to call the object from JavaScript and send a message back to the client. The important part is: