Topic: Simple ShellExecute or similar.

Hi Everybody

I'm looking for a command that will open either a file or url depending on what is in the TABLE
Best I could come up with was the following (and it ain't working);


var S : String ;
uses ShellApi;

begin
       s :=SQLExecute('SELECT Menu1URL2 FROM MainDatabase WHERE id=1');
        ShellExecute(Handle,'open',s,nil,nil, SW_SHOWNORMAL);
end;



Far from being a programmer  anything too complicated and it  starts looking like spaghetti.
Thanks for your help

Mike

Re: Simple ShellExecute or similar.

For a web page try.

procedure frmMain_lbWebpage_OnClick (Sender: TObject);
var
    webpage:string;
begin
  
  webpage := frmMain.lbWebpage.Caption; 
  OpenURL(webpage);  OR OpenURL('http//:: my website .something') - if website is HTTPS you need to include the 'S'
end;

For a file it depends on what you type of file you want to open, but this will work for text files and exe's.

OpenFile('drive_letter:\your_file_path\your_programe_name');
On a clear disk you can seek forever

Re: Simple ShellExecute or similar.

Thanks CDB however I never know if it will be a file or a URL as the data entered in a database is somewhat random.

I am trying to create a menu board, for people who have reduced mobility.

By creating very large buttons they will be able to open web pages, software or files. The menu board needs to be flexible so that  any button can be modifiable and updated as needed (Thus the database).

I do know that Shellexecute has some kind of ability to do that.

4 (edited by CDB 2020-06-06 20:08:45)

Re: Simple ShellExecute or similar.

jeffmtl,


You could test for the condition in an IF statement and then branch to the appropriate code.


So:  UNTESTED!!

ProcedureDoSomething();
var
request : string;  // To hold either URL or File


begin
  
   If copy(request, 1,4) = 'HTTP' then    //copy(string, count from where you want to start, how many characters after count)
      OpenURL(request)
   else
       OpenFile( request);

end; 

Depending on how you are getting the information out of the database, the on or after click event of the button would call ProcedureDoSomething.

OpenFile can open both documents and exe files. 

I don't think Pascal script knows about shellexecute.

On a clear disk you can seek forever

5 (edited by derek 2020-06-06 20:38:22)

Re: Simple ShellExecute or similar.

Hi Mike, Hi CDB,
Perhaps you could do it like this (see attached).  Sorry about the spaghetti but it's just repetitive stuff so not as bad as it seems!
I've tried to make it look like large buttons on a menu board but in fact it's just a simple tablegrid.
Then, together with 'oncellclicks', it looks to see which one of four 'types' has been filled in (website, file, program or image).
The files and images are attached, just so you can see it working but obviously they'd normally be anywhere on your machine (or network).
You can move around the 'buttons' (cells) with the arrow keys which might be preferable for your users.
I've left the 'add', 'edit' and 'delete' buttons on the form but I imagine you'd take them off for the version your end-users might use.
Anyway, hope it gives you some ideas.
Derek.

Post's attachments

Attachment icon jeffmtl2.zip 1.61 mb, 347 downloads since 2020-06-06 

6 (edited by CDB 2020-06-06 20:22:02)

Re: Simple ShellExecute or similar.

So using your code:


var S : String ;
begin
     s :=SQLExecute('SELECT Menu1URL2 FROM MainDatabase WHERE id=1');

      DoSomething(s);

end;

procedure DoSomething(request : string);
begin
 
  
   If copy(request, 1,4) = 'HTTP' then    //copy(string, count from where you want to start, how many characters after count)
      OpenURL(request)
   else
       OpenFile( request);

end; 

Looks like while I was typing - Derek was busy uploading!

On a clear disk you can seek forever

Re: Simple ShellExecute or similar.

Thanks guys, Actually both are going to be helpful.

I now have to study both solutions and see how to apply them.

Thanks for your help, and if this works the way I would like, will make a lot of people in a Day program that are in wheel chairs very happy.

Jeffmtl