0

Whith TWebBrowser based on Internet Explorer the URL is not encrypted, for example i can simply go :

path:='file:///C:/##Project/Page.html
WebBrowser1.Navigate(path);

But, for TChromium Component URL is encoded like :

path:='file:///D:/%23%23Project/Page.html
chrm1.Browser.MainFrame.LoadUrl(path);

This is a problem because in the program I create the path (URL) using :

path := ExtractFilePath(Application.ExeName)+ 'Page.html';

And chromium does not recognize the path, because it is not properly encoded.

Toster
  • 361
  • 3
  • 17

2 Answers2

1

Update:

I installed DCEF3 and the following works fine for that specific path in the GuiClient demo:

  Path := StringReplace(Path, '#', '%23', [rfReplaceAll]);
  crm.Browser.MainFrame.LoadUrl(Path);

I also tried

Path := TIdURI.UrlEncode(Path);

but that left the Path value unchanged (in D7). So, for a more general solution than my StringReplace one, you might want to take a look at some of the answers in the q Hugh Jones gave a link to,

stackoverflow.com/questions/776302/standard-url-encode-function

[Original]

I don't have DCEF3 installed to check, but it look like you need to do

path := ExtractFilePath(Application.ExeName)+ 'Page.html';
path := HttpEncode(Path);
chrm1.Browser.MainFrame.LoadUrl(path);

after adding HttpApp to your Uses.

Community
  • 1
  • 1
MartynA
  • 30,454
  • 4
  • 32
  • 73
0

Functions above encoding work, but their way of coding was different.

Tchromium has need a realy specific, enough specyfic to not to create to typical function.

HttpEncode to work almost perfectly, but encodes special characters such as +, - etc.

I try the authors functions: stackoverflow.com/questions/776302/standard-url-encode-function

And i Try

function MyEncodeUrl(source: string): string;

var i:integer;
 begin
   result := '';
   for i := 1 to length(source) do
       if not (source[i] in ['A'..'Z','a'..'z','0','1'..'9','-','_','~','.']) then result := result + '%'+inttohex(ord(source[i]),2) else result := result + source[i];
 end;

But, I use above functions on fragments of between '/' like:

 path := ExtractFilePath(Application.ExeName) ;


   function GenerateURL(path: string): string;
          var after,temp: string;
    begin
          path:= ExtractFilePath(Application.ExeName);
          after:=Copy(path,1,4);
          Delete(path,1,3);


          while (Pos('\',path)>0 )do

          begin

                    wynik:=Copy(path,1,Pos('\',path)-1);

                        if Length(temp)<>0 then
                          temp:=MyEncodeUrl(temp)+'\';

                    Insert(temp,after,Length(s));
                    Delete(path,1,Pos('\',path))
          end ;

   Delete(after,(Length(after)),1);
   Result := StringReplace(after, '\', '/', [rfReplaceAll]);
   end;

After above function i just add beginning and end of URL function :

 URL := 'file:///' + GenerateUrl(path)+ 'page.htm';

Thanks all for your help

Community
  • 1
  • 1
Toster
  • 361
  • 3
  • 17