0

Have someone an example showing how I handle custom URL protocol from a webpage in my desktop-app like zoom (You got an link and this open the meeting in the desktop-app)?

I'll be happy if some one has nice example or something he can share for the purpose.

1

1 Answer 1

1

This is a matter of registry keys. Look at the Microsoft documentation.

The code below can create it for you:

function RegisterURLProtocol( const ProtocolID : String; const ProtocolName : String; const DefaultIcon : String; const OpenCommand : String) : Boolean; var Reg : TRegistry; begin Result := FALSE; Reg := TRegistry.Create(KEY_WRITE); try Reg.RootKey := HKEY_CLASSES_ROOT; if not Reg.OpenKey(ProtocolID, TRUE) then Exit; Reg.WriteString('', 'URL:' + ProtocolName); Reg.WriteString('URL Protocol', ''); if Reg.OpenKey('DefaultIcon', True) then begin Reg.WriteString('', DefaultIcon); end; Reg.CloseKey; if not Reg.OpenKey(ProtocolID + '\shell\open\command', True) then Exit; Reg.WriteString('', OpenCommand); Result := TRUE; finally FreeAndNil(Reg); end; end; 
Sign up to request clarification or add additional context in comments.

6 Comments

Shouldn't Result be initialized to false instead of true?
Also two more Reg.CloseKey() would be fine to clean up each Reg.OpenKey().
@WoutervanNifterick A matter of taste. In the context of the application I extracted this code, the intent is to continue even if the function fails (Lack of permission for example).
As a stand-alone general-purpose library function, it is not a matter of taste. As it is now, the function always returns True, so that's what you'd write in its documentation. Not very useful, though. If the caller wants to continue on failure, just don't stop on the function's returning False!
Edited to return FALSE in case of error.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.