Recent

Author Topic: [SOLVED] SQLite open link  (Read 762 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 525
[SOLVED] SQLite open link
« on: July 15, 2023, 09:31:22 pm »
Hello, how can I improve the code so that ShellExecute works for addresses without http:// ?

Code: Pascal  [Select][+][-]
  1. var Link: String;
  2. begin
  3. if ZQuery2.RecordCount = 0 then Exit;
  4.   Link := ZQuery2.FieldByName('Link').AsString;
  5.   ShellExecute(Handle, 'open', PChar(Link), nil, nil, SW_SHOW);
  6. end;
  7.  
« Last Edit: July 16, 2023, 09:34:06 am by Pe3s »

TRon

  • Hero Member
  • *****
  • Posts: 1852
Re: SQLite open link
« Reply #1 on: July 15, 2023, 09:46:16 pm »
Hello, how can I improve the code so that ShellExecute works for addresses without http:// ?

Code: Pascal  [Select][+][-]
  1. var Link: String;
  2. begin
  3. if ZQuery2.RecordCount = 0 then Exit;
  4.   Link := ZQuery2.FieldByName('Link').AsString;
  5.   if not Link.StartsWith('http://') then Link := 'http://' + Link;
  6.   ShellExecute(Handle, 'open', PChar(Link), nil, nil, SW_SHOW);
  7. end;
  8.  
?

Pe3s

  • Hero Member
  • *****
  • Posts: 525
Re: SQLite open link
« Reply #2 on: July 16, 2023, 09:33:49 am »
@TRon, Thank you :)

Zvoni

  • Hero Member
  • *****
  • Posts: 2033
Re: [SOLVED] SQLite open link
« Reply #3 on: July 17, 2023, 08:24:48 am »
Or use regex
https://regex101.com/r/vsumW6/1
catches both: http and https
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Pe3s

  • Hero Member
  • *****
  • Posts: 525
Re: [SOLVED] SQLite open link
« Reply #4 on: July 22, 2023, 12:09:28 pm »
Thank you  :)

TRon

  • Hero Member
  • *****
  • Posts: 1852
Re: [SOLVED] SQLite open link
« Reply #5 on: July 22, 2023, 12:22:57 pm »
@Zvoni:
Though my solution is far from perfect as proofed by your examples, that is one heck of an expression and still fails when the protocol name has a capital letter. Thus casting to low or high for checking the protocol is preferred (I know that can (easily) be added to the expression as well  ;) ).

If you really want to do it properly then ParseURI and EncodeURI is imho far more understandable (though I do admit that when using RE's is something that you do every day you probably read/write it as a normal person would read/write text is his/her native tongue -> I honestly can't).

Zvoni

  • Hero Member
  • *****
  • Posts: 2033
Re: [SOLVED] SQLite open link
« Reply #6 on: July 22, 2023, 12:49:48 pm »
@Zvoni:
Though my solution is far from perfect as proofed by your examples, that is one heck of an expression and still fails when the protocol name has a capital letter. Thus casting to low or high for checking the protocol is preferred (I know that can (easily) be added to the expression as well  ;) ).
Or switch to case insensitive …
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

TRon

  • Hero Member
  • *****
  • Posts: 1852
Re: [SOLVED] SQLite open link
« Reply #7 on: July 22, 2023, 01:41:34 pm »
Or switch to case insensitive …
Rrright. Forgot about that one  :-[

 

TinyPortal © 2005-2018