Recent

Author Topic: Launching a website from value DbEdit?  (Read 523 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 278
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Launching a website from value DbEdit?
« on: November 09, 2024, 04:08:03 pm »
This doesn't work, would anyone be able to correct my syntax or better way.  I did this as a double-click because the user needs to enter the URL into the DbEdit but if they want to launch the client's website, double-click...

Code: Pascal  [Select][+][-]
  1. procedure TFrmClientsMgt.DBEditClientURLDblClick(Sender: TObject);
  2. begin
  3.   //->ShellExecute(handle,'open','extract DBEditClientURL',nil,nil,SW_SHOWNORMAL);
  4. end;
  5.  

TRon

  • Hero Member
  • *****
  • Posts: 3643
Re: Launching a website from value DbEdit?
« Reply #1 on: November 09, 2024, 04:38:54 pm »
I see code using Lazarus. Alternatives are:
- OpenDocument
- OpenURL (link to ccr documentation seems broken)

Details for the window only shellexecute solution can be read here.

What exactly is it that you seem to have issues with ?  The actual run of shell execute (e.g. casting parameters) or the extraction of the clientURL from the database ?

This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 278
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Launching a website from value DbEdit?
« Reply #2 on: November 09, 2024, 06:11:50 pm »
If I uncomment this line of code, getting these 2 errors when compiling:

clientsmgt.pas(215,3) Error: Identifier not found "ShellExecute"
clientsmgt.pas(215,64) Error: Identifier not found "SW_SHOWNORMAL"

Can't remember where I picked up this example, but it's not correct...

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 278
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Launching a website from value DbEdit?
« Reply #3 on: November 09, 2024, 06:13:06 pm »
I think I got this from old code I have from back with Delphi 7, not sure.

TRon

  • Hero Member
  • *****
  • Posts: 3643
Re: Launching a website from value DbEdit?
« Reply #4 on: November 09, 2024, 06:19:09 pm »
shellexecute is a windows (only) function.

In order to be able to use it the unit windows needs to be included in the uses clause of your code.

The same is true for the constant SW_SHOWNORMAL.

Alternatively it is possible to use the shellapi unit.

edit: example
Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. {$mode delphi}
  4.  
  5. uses
  6.   windows;
  7.  
  8. var
  9.   ClientURL : string;
  10. begin
  11.   ClientURL := 'some url';
  12.  
  13.   // https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea
  14.   ShellExecute
  15.   (
  16.     0,                 // (optional) handle to parent window
  17.     'open',            // (optional) string with action (verb) to be performed
  18.                        // verbs: edit, explore, find, open, print, runas or nil
  19.     pchar(ClientURL),  // file or object to be used (execute) by the verb
  20.     nil,               // (optional) parameters/arguments for file or object
  21.     nil,               // (optional) working directory
  22.     SW_SHOWNORMAL      // display flags option
  23.   );
  24. end.
  25.  
« Last Edit: November 09, 2024, 08:03:43 pm by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 278
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Launching a website from value DbEdit?
« Reply #5 on: November 09, 2024, 11:06:00 pm »
Thanks TRon, more involved that what I thought but makes sense.

 

TinyPortal © 2005-2018