Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   [Fehler] URL.pas(32): Inkompatible Typen: 'HKEY' und 'String' (https://www.delphipraxis.net/175666-%5Bfehler%5D-url-pas-32-inkompatible-typen-hkey-und-string.html)

Nintendo 8. Jul 2013 18:04

[Fehler] URL.pas(32): Inkompatible Typen: 'HKEY' und 'String'
 
Hallo,

Ich will zur Laufzeit eine Webseite aufrufen und erhalte in folgender Funktion die Fehlermeldung, die den Threadtitel bildet:

Delphi-Quellcode:
procedure OpenURL(Url: string);
var
  ts: string;
begin
  with TRegistry.Create do
    try

      //Hier kommt die Fehlermeldung des Compilers
      rootkey := 'HKEY_CLASSES_ROOT';
      //Was muss ich anders definieren???

      OpenKey('\htmlfile\shell\open\command', False);
      try
        ts := ReadString('');
      except
        ts := '';
      end;
      CloseKey;
    finally      
      Free;
    end;
  if ts = '' then Exit;
  // remove quotes and commandline parameters
  ts := Copy(ts, Pos('"', ts) + 1, Length(ts));
  ts := Copy(ts, 1, Pos('"', ts) - 1);
  ShellExecute(0, 'open', PChar(ts), PChar(url), nil, SW_SHOW);
end;
Wer kann helfen?

sx2008 8. Jul 2013 18:21

AW: [Fehler] URL.pas(32): Inkompatible Typen: 'HKEY' und 'String'
 
Das ist aber umständlich. Es reicht doch Folgendes:
Delphi-Quellcode:
function OpenURL(const url: string): Boolean;
begin
   Result := ShellExecute(0, 'open', PChar(url), nil, nil, SW_SHOW) > 32;
end;

// Anwendungsbeispiel
if not OpenURL('http://www.delphipraxis.net') then
  RaiseLastWin32Error;
Noch ein kleiner Hinweis:
Die Funktion OpenURL() kann auch potentiell gefährliche Dinge (Dateien mit Viren) öffnen.
Deshalb ggf. die URL prüfen bevor man sie öffnet.

nahpets 8. Jul 2013 18:28

AW: [Fehler] URL.pas(32): Inkompatible Typen: 'HKEY' und 'String'
 
Das ist kein String sondern eine Konstante:
Delphi-Quellcode:
rootkey := HKEY_CLASSES_ROOT;


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:52 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz