IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants FMX Delphi Discussion :

Problème avec WebBrowser


Sujet :

Composants FMX Delphi

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut Problème avec WebBrowser
    Bonjour

    Je compile et construit mon projet (Delphi 10.4.2) sans difficulté, mais au lancement j'obtiens ceci:

    Nom : WB.JPG
Affichages : 701
Taille : 81,4 Ko

    Auriez vous une idée de l'origine de ce message svp.

    Merci.

    Pierre

  2. #2
    Membre expert

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2006
    Messages
    661
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Deux Sèvres (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Novembre 2006
    Messages : 661
    Points : 3 630
    Points
    3 630
    Billets dans le blog
    2
    Par défaut
    Bonjour,

    Est ce que vous êtes bien sous FMX et si oui, utilisez vous bien le TWebBrowser de FMX.WebBrowser dans la clause uses ?
    Si vous utilisez la VCL, le TWebBrowser est défini dans SHDocVw (qui n'est valable que pour Windows et qui s'appuie sur la SHDOCVW.dll de l'API Microsoft Shell Doc Object and Control Library) : il n'a pas la propriété "position"... Si vous avez un code traduit de la VCL vers FMX, attention : le TWebBrowser est différent et n'est pas "rangé" dans la même unité.
    Mon site - Mes tutoriels - GitHub - N'oubliez pas de consulter les FAQ Delphi et les cours et tutoriels Delphi

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    Bonjour,

    Merci de votre réponse, J'ignorais qu'il existait tant de différence entre les 2 WebBrowser's.
    Cela va changer beaucoup de choses car mon code provient d'une ancienne application en VCL... qui utilisait la propriété Document du WebBrowser VCL.

    Cordialement
    Pierre

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    La question qui me vient à l'esprit est :

    Comment remplacer la fonction ExecScriptt sans Document?

  5. #5
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 043
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 043
    Points : 40 957
    Points
    40 957
    Billets dans le blog
    62
    Par défaut
    Peut-être http://docwiki.embarcadero.com/Libra...uateJavaScript
    Mais la question du content m'intéresse beaucoup en effet dans le programme utilisant leaflet je suis passé par un fichier html, et travaille avec LoadStrings pour charger la page, je n'ai jamais fait l'inverse (un sorte de SaveStrings)
    même si je pense qu'une sérialization pourrait m'apporter une réponse, il doit y avoir plus simple
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    Merci, mais comment passer des paramètres à une fonction Javascript ?

  7. #7
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 043
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 043
    Points : 40 957
    Points
    40 957
    Billets dans le blog
    62
    Par défaut
    à priori, et sans essayer, rien qu'un format ne pourrait faire. Il me faudrait juste un exemple pour vérifier
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  8. #8
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    Merci, Je teste...

  9. #9
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    Je pense avoir trouvé!!!

    Pour charger la page HTML dans un String:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    procedure TfrmMap.FormCreate(Sender: TObject);
    var
      HtmlList: TStringlist; i:Integer;
      aStream     : TMemoryStream;
    begin
      SetPermissions;
      HtmlStr:= '';
      HtmlList:= TStringlist.Create;
      HtmlList.LoadFromFile('C:\Users\piech\Documents\Embarcadero\Studio\Projets\FirstMap.html');
      for i := 0 to HtmlList.Count-1 do
      begin
        HtmlStr:= HtmlStr + HtmlList.Strings[i];
      end;
      HtmlList.Free;
      //**********************************************************************************************
      WebBrowser1.LoadFromStrings(HtmlStr, '');
      //WebBrowser1.Navigate('file://C:\Users\piech\Documents\Embarcadero\Studio\Projets\FirstMap.html');
    end;
    Le Script modifié dans la page HTML:

    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    ...
    <script>
      function GotoLatLng(Lat, Long)
      {
      var map = L.map('map').setView([Lat, Long], 10);
      L.esri.basemapLayer('Topographic').addTo(map);
      }
    </script>
    ...

    Le passage des paramètres depuis 2 Tedit:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    procedure TfrmMap.btnLocateClick(Sender: TObject);
    begin
      WebBrowser1.EvaluateJavaScript(Format('GotoLatLng(%s,%s)',[edLatitude.Text, edLongitude.Text]));
    end;

  10. #10
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    Se pose maintenant le problème:
    Si je modifie les coordonnées dans les Tedit, j'obtiens:

    Nom : Capture.JPG
Affichages : 649
Taille : 23,6 Ko

    Merci de votre aide.
    Cordialement
    Pierre

  11. #11
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 043
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 043
    Points : 40 957
    Points
    40 957
    Billets dans le blog
    62
    Par défaut
    Pour la première, j'aurais pu l'écrire puisque c'est ce que j'ai utilisé (largement) au sein de mon programme test

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
      try
      FS.LoadFromFile('D:/Test/Randos/leaflet.html');
     {$ENDIF}
      SL.LoadFromStream(FS);
    ..
      webbrowser1.BeginUpdate;
      webbrowser1.LoadFromStrings(SL.Text,WebBrowser1.FilesPref);
    //  webbrowser1.URL:=WebBrowser1.FilesPref+'D:/Test/Randos/FirstMap.html';
      webbrowser1.EndUpdate;
      finally
       SL.Free;
       FS.Free;
      end;
    Mais je ne pensai pas que le problème était là.
    AMHA il n'y a pas besoin de la variable HTMLStr dans votre code

    pour ce qui est du javascript en fait je triturait directement le texte de la TStringList pour ajouter mes points
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  12. #12
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    Voilà de quoi occuper ma journée...
    Merci.

  13. #13
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 043
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 043
    Points : 40 957
    Points
    40 957
    Billets dans le blog
    62
    Par défaut
    Citation Envoyé par Pierre95 Voir le message
    Voilà de quoi occuper ma journée...
    je peut mettre à jour mes sources (à jour) sur le forum, ou ouvrir un nouveau dépôt Git si besoin
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  14. #14
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    Peut-être une mise à jour du forum?
    Merci encore!
    Pierre

  15. #15
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 043
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 043
    Points : 40 957
    Points
    40 957
    Billets dans le blog
    62
    Par défaut
    Citation Envoyé par Pierre95 Voir le message
    Peut-être une mise à jour du forum?
    Fait https://www.developpez.net/forums/d2.../#post11746423
    Même si je ne suis pas sûr de mon ZIP
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  16. #16
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    Il m'est toujours impossible de lancer une fonction javascript depuis Delphi.

    J'ai changé avec succès le code de chargement de la page HTML en ne passant plus par un String (Comme conseillé par SergioMaster).

    La procédure FormCreate devient donc:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    procedure TfrmMap.FormCreate(Sender: TObject);
    var
       i:Integer;
    begin
      SetPermissions;
      HtmlList:= TStringlist.Create;
      HtmlList.LoadFromFile('C:\Users\piech\Documents\Embarcadero\Studio\Projets\FirstMap.html');
      WebBrowser1.LoadfromStrings(HtmlList.Text,'');
      HtmlList.Free;
    end;
    Le HTML:

    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8" />
      <title>Esri Leaflet Quickstart</title>
      <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
     
      <!-- Load Leaflet from CDN -->
      <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"
        integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
        crossorigin=""/>
      <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"
        integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
        crossorigin=""></script>
     
      <style>
        body { margin:0; padding:0; }
        #map { position: absolute; top:0; bottom:0; right:0; left:0; }
      </style>
    </head>
    <body>
     
    <div id="map"></div>
     
    <script> 
        var map = L.map('map').setView([0, 0], 5);
        L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
        }).addTo(map);
        
        function GotoPosition(Lat,Lng)
        {
          map = L.map('map',
          {
            center: [Lat,Lng],
            zoom: 13
          })
          L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
          {
            attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
          }).addTo(map)
        ;}
    </script>
     
    </body>
    </html>

    et enfin, le click sur le bouton 1:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    procedure TfrmMap.btnLocateClick(Sender: TObject);
    begin
      WebBrowser1.BeginUpdate;
      WebBrowser1.EvaluateJavaScript(Format('GotoLatLng(%s,%s)',[edLatitude.Text,edLongitude.Text]));
      WebBrowser1.EndUpdate;
    end;
    Je ne peux me séparer de ce message:

    Nom : Capture.JPG
Affichages : 617
Taille : 65,8 Ko

    Merci de vos lumières

    Cordialement
    Pierre

  17. #17
    Membre chevronné
    Avatar de free07
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    931
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ardèche (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 931
    Points : 1 909
    Points
    1 909
    Par défaut
    Bonsoir,

    Est ce que mettre Silent à True serait suffisant ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    WebBrowser1.Silent := True;
    Cela cache les messages d'erreurs que rencontre le WebBrowser.

  18. #18
    Membre habitué
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    439
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 439
    Points : 161
    Points
    161
    Par défaut
    Merci, mais la version FMX du WebBrowser ne possède pas cette propriété

    Pierre

  19. #19
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 043
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 043
    Points : 40 957
    Points
    40 957
    Billets dans le blog
    62
    Par défaut
    Bonjour,

    De toute façon Silent:=True n'aurait fait que faire une sorte de try except end pour ignorer et/ou traiter l'erreur donc ce n'est pas là le problème.

    La question est plus maintenant comment exécuter un javascript dans le FMX.WebBrowser (j'ai mis en valeur le FMX pour les prochains intervenants @free07 qui n'a pas du y faire attention).
    Ma première idée était qu'il y avait un problème dans la chaine proposée (une histoire de point décimal) mais le code et l'image écran m'ont démontré que non.
    Reste qu'il n'est pas sûr que le script soit correct. Il va falloir suivre cette piste (pour l'instant j'obtiens la même erreur)
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

  20. #20
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 043
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 043
    Points : 40 957
    Points
    40 957
    Billets dans le blog
    62
    Par défaut
    Après divers essais, je pense qu'il s'agit bien d'un problème de syntaxe. Je n'ai pas (encore) trouvé le GotoLatLng dans la documention de Leaflet par contre j'ai pu sans problème exécuter ce script
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    var
     js:string;
    begin
        js := 'map.panTo([48.76314,-80.13569]);';
        WebBrowser1.EvaluateJavaScript(js);
    // WebBrowser1.EvaluateJavaScript('map.GotoLatLng(48.76314,-80.13569);'); //  erreur 80020101.
    
    end;
    [EDIT]
    dernier jus, j'ai utilisé une autre métode de positionnement

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    procedure TMainForm.btnjvScriptClick(Sender: TObject);
    var
     js:string;
     latitude, longitude : single;
    begin
      latitude:=48.76314;
      longitude:=-80.13569;
      js:=Format('map.setView([%1.5f,%1.5f]);',[latitude,longitude],TFormatSettings.Create('EN_US'));
      WebBrowser1.BeginUpdate;
      WebBrowser1.EvaluateJavaScript(js);
      WebBrowser1.EndUpdate;
    end;
    A noter :
    - l'utilisation du format avec des nombres (et donc un TFormatSettings pour être sûr de la conversion) car je n'aime pas la saisie de chaine quand il s'agit de nombres
    - l'utilisation de WebBrowser.BeginUpdate / WebBrowser.EndUpdate, non nécessaire mais fortement conseillée pour éviter phénomène de "carte vide"
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

Discussions similaires

  1. Probléme avec WebBrowser.
    Par MrDjamel dans le forum VB.NET
    Réponses: 0
    Dernier message: 16/09/2012, 06h57
  2. Problème avec le composant WebBrowser
    Par VILPELLET dans le forum Windows Forms
    Réponses: 2
    Dernier message: 01/10/2008, 11h29
  3. probléme avec webBrowser
    Par dalilnet dans le forum Général Dotnet
    Réponses: 1
    Dernier message: 22/09/2008, 16h33
  4. [VB 2005] Problème avec contrôle WebBrowser
    Par Vinoo dans le forum Windows Forms
    Réponses: 3
    Dernier message: 19/09/2007, 00h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo