Jump to content
IElite

Code does not work in external chrome browser

Recommended Posts

I can't seem to get this one line to work in my external chrome browser (version 69.x). Works in default internal chrome browser as well as external browsers (IE, Firefox, Safari)

 TCounty(Application.FormByName('County')).FillData;

 

 

Share this post


Link to post
Share on other sites

I even tested with the following code changes

 TCounty(Forms[TCounty]).FillData;

OR

  (Forms[TCounty] as TCounty).FillData;

 

and I get the same exact results as the original code

does NOT work in Chrome browser (external) 

works in (IE, Firefox, Safari)

 

Share this post


Link to post
Share on other sites

> TCounty(Forms[TCounty]).FillData;

From where are you calling this? Perhaps that event doesn't fire in Desktop version. Try to add some WriteLn notification messages before/after and during FillData and see if they get displayed in console.

Share this post


Link to post
Share on other sites
7 hours ago, Igor Savkic said:

> TCounty(Forms[TCounty]).FillData;

From where are you calling this? Perhaps that event doesn't fire in Desktop version. Try to add some WriteLn notification messages before/after and during FillData and see if they get displayed in console.

I am calling it from a button's OnClick event....and as I stated, it works in three other desktop browsers (IE, Firefox, Safari)

 

It turns out that the FillData is getting called and its NOT going past this line

 

if Length(gdata.counties) > 0 then

It doesn't like the "Length"

because, if I comment out the "if" statement, then it also doesn't like

for var i:= 0 to Length(gdata.counties)-1 do

 

But, as I said, it all works fine in three other browsers

 

procedure TCounty.FillData;
begin
 fCounty.Items.Clear;
 if Length(gdata.counties) > 0 then
 begin
   for var i:= 0 to Length(gdata.counties)-1 do
        fCounty.Add(gData.counties[i].name);
 end;
end;

 

BTW, gData is a variant

Share this post


Link to post
Share on other sites
3 hours ago, Igor Savkic said:

That's some compiler or RTL thing probably, try to use JS length directly. Assuming counties is array something like:

if gData.counties.length > 0 then

 

 

Yes, I tried that too, I get the same results with

gData.counties.length

as I do with

Length(gData.counties)

 

Share this post


Link to post
Share on other sites
4 hours ago, Igor Savkic said:

Then counties is most likely empty. If it's not an array you would get an error and since you have no error it must be empty. Try to call

WriteLn(JSON.Stringify(gData));

WriteLn(JSON.Stringify(gData.counties));

1

So its empty only in the External Chrome browser, but NOT empty in Internal default Chrome Broswer (IDE) and NOT ecmpty in External  IE, Firefox, and Safari browsers? How could that be?

I load the JSON data...

procedure TStart.InitializeForm;
begin
  inherited;
  fHttp.Get('res\data.json');
end;

then onDataReady, I place data in string and then parse it ....

as a test, I stringify the parsed data and display it in a show message

procedure TStart.HandleHttpDataReady(Sender:TW3HttpRequest);
begin
  fJSONStr:= Sender.ResponseText;
  gData:= JSON.parse(fJSONStr);
  ShowMessage(JSON.Stringify(gData));
end;

The showMessage does not display when running in external Chrome browser. However, it does display in the IDE's internal Chrome browser as well as in IE, Firefox, and safari browsers

 

 

Share this post


Link to post
Share on other sites

> So its empty only in the External Chrome browser, but NOT empty in Internal default Chrome Broswer (IDE) and NOT ecmpty in 
> External  IE, Firefox, and Safari browsers? How could that be?

> I load the JSON data...fHttp.Get('res\data.json');

Perhaps res\data.json is empty or doesn't exist? Try to use some manually assigned value to string instead of loading from file.

>  then onDataReady, I place data in string and then parse it ....as a test, 

Check first if OnDataReady is even called, I suspect something is wrong in that area of obtaining data. 

> I stringify the parsed data and display it in a show message  
> The showMessage does not display when running in external Chrome browser. 

Not showing at all or empty, try to use WriteLn instead, it should always work.

 

Share this post


Link to post
Share on other sites
2 hours ago, Igor Savkic said:

I don't know, key is how Chrome sees it. Make sure it's not using cached data for that file. 

BTW if you have some example I can test it on my computer.

Sure, I have sent it to you via forumn messenger

Share this post


Link to post
Share on other sites

> Sure, I have sent it to you via forumn messenger

I get error: "Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https"

From googling it seems Chrome denies all HttpRequests to file://urls.

You have two options:

a) Add some basic server that will serve these files

b) Try to embed json data as image, there is SMS option for it binary data to image, it doesn't work for me (old version of SMS) but try yourself. I remember

seeing somewhere post about it but I cannot find it now. I think correct path would be to use TW3Image to load such DataAsImage file, convert to TW3ImageData and from there extract string and parse it as you would usually.

Share this post


Link to post
Share on other sites

Kool......glad you were able to find the issue. Not sure why I wasn't getting an error.

I uploaded the program to a site online and it works without any code changes.

So, I can live with the issue in External Chrome now that I know its gonna work when deployed

Thanks for all your help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×