Right-click menu of EXE file - delphi

I was wondering if it was possible in Delphi to implement some items added to the right-click menu of an EXE file, specifically a Windows Service Application EXE which has not yet been registered or installed anywhere. The menu options would allow user to install/uninstall the EXE as a windows service. Is this possible? If so, then how? It's OK if it's only compatible with Windows Vista+.
There would be 2 menu items:
Install (or Uninstall)
Start (or Stop)

If you're referring to the Shell Context Menu (the right-click window in Windows Explorer), you cannot. You can add to the menu that will be displayed for all .exe files, but not for an individual one.
You could register a context menu handler for all executables, and then filter the filename passed to see if you needed to handle it or not, but this would mean that for every one of the hundreds (or thousands) of executable files on your machine, your filter would run on the slim chance it was your application that was right-clicked.
A possible workaround would be to put a file with a custom extension in your service's folder, and add a context menu handler for that file instead. When that file is right-clicked, the menu items would simply call your service with the appropriate command-line parameters.
(Of course, the best solution is to use the Control Panel's Services applet to manage your service, which is what it's designed specifically do do.)

It is possible, and you need to write shell extensions for Windows Explorer.
References:
http://delphi.about.com/library/bluc/text/uc071701a.htm
http://www.andreanolanusse.com/en/shell-extension-for-windows-32-bit-and-64-bit-with-delphi-xe2/
http://www.codeproject.com/Articles/441/The-Complete-Idiot-s-Guide-to-Writing-Shell-Extens

Related

delphi I'd like to make EXE which doesn't have an icon resource

I'm making many VCL form applications using delphiXE5 at present. The icon resource is unnecessary for it.
I'd like to make EXE which doesn't have an icon resource like a console application, but how should it be done?
Open your .dproj file in Notepad or similar editor and delete tags
<Icon_MainIcon>...</Icon_MainIcon>
With this approach your project will still have version information, as well as runtime themes (or custom manifests) enabled.
If you wish to add icon back, just go to Project Options -> Application and load yours or use default icon.

How do I launch a new instance of RAD Studio from Explorer

I have the habit of opening my Delphi projects from File Explorer by double-clicking on the .dpr or .dproj file.
Normally, this will launch Embarcadero RAD Studio XE7 in my case and open the project for me.
I'd like to compare how something is done in a separate project (different directory, etc.). If I double-click on a second .dpr/.dproj file, the default action seems to be to add that to the Project Group of the instance of RAD Studio that I already have open.
Is there a way I can set up RAD Studio to open a second instance for me so that I can see things side by side?
Currently I manually open up a new instance and then find the project file through File->Open, but that is painful.
In the Registry, the .dpr and .dproj file extensions are registered to invoke bdslauncher.exe if the IDE is not already running, and to invoke DDE to pass the dragged filename to an existing IDE if it is running. So, the only way to make a double-click open a new instance of the IDE would be to change the Registry settings to bypass bdslauncher.exe and DDE and just invoke bds.exe directly with the filename as a command-line parameter.
Otherwise, the other alternatives are to:
drag&drop a .dpr/.droj file directly onto the bds.exe file, which will run a new copy of bds.exe that will open the dragged file.
right-click on a .dpr/.dproj file, choose "Open With", and select bds.exe (you can optionally set it as the default app or not). On subsequent right-clicks, the "Open With" menu will now have a submenu (if it did not already) that includes "Embarcadero RAD Studio" as an option.

Delphi IDE is not visible

I double click the Delphi icon on the desktop, but the IDE does not show up. Looking into the Task Manager list, the BDS.exe appears under the Processes list, while it should appear under the Applications list. Has anyone any idea why this is happening? Note: the IDE version I'm currently using is XE3, but the 2010 version, wich is also installed, behaves the same way. Windows version is 8.1. I really appreciate any help.
Often this happens because you've got either a poorly behaving third-party component installed, or you've set the IDE to load the last project when it opens and it can't do that for some reason.
There are a few things that can help resolve this; they involve editing the shortcut to Delphi temporarily (or creating a new shortcut and modifying it instead, of course).
Edit the shortcut and add the -np parameter to the command line; it tells the IDE to not load a project on startup. If this works, you can try opening your project. If the IDE hangs again, rename your .dproj file to a different extension and open it with just the .dpr; the IDE will create a new .dproj file;
If the above doesn't work, edit the shortcut again, remove the -np, and replace it with -rFoo. This tells the IDE to load the Foo configuration from the registry on startup instead of the normal Delphi configuration. (Foo doesn't exist, so the IDE will create an all-new configuration in the registry named Foo, with no third-party components installed and all of the default settings for folders and options.) If this works, you can reinstall your third-party component sets one at a time to identify the problem package, and the edit the registry to remove it from your normal Delphi configuration.
Note: Foo in the second bullet point item above is just a name. It has no special meaning; it's just something that's commonly used as a dummy type or variable content. The parameter can be set to anything that doesn't already exist as a configuration in the Delphi registry settings; Bar, Dummy or Zombie will work just as well.
Once you've tried these (whether they fix the issue or not), don't forget to go back to remove the no longer needed command line parameter.
If none of the above works, a reinstall may be in order.
If you want to try a reinstall, uninstall the existing version (using the usual Control Panel Uninstall Software applet).
Doing an uninstall does not remove the registry keys, and a new install will see it exists and not create a new one, so you'll need to use RegEdit to delete the HKCU\Software\Embarcadero\BDS\10.0 tree (or rename it to something different like Old 10.0), and then reinstall Delphi. (As you're using other Delphi versions, make sure you leave those keys alone so you don't damage those installs. Only alter or delete the 10.0 tree.)
In Delphi 4 and 5 it was the delphi32.dsk file. You can delete this file but you can also edit the file, section 'Main Window'. First kill the process in the taskmanager before you edit/delete this disk file.
[Main Window]
Create=1
Visible=0 <-- This value must be **1**
State=0
......
......
Start Delphi - et viola! It is back again.
Offtopic: Still running Delphi 5 on Windows 7, blazing fast, yes!

How keep the debug layout the same as the desktop layout

I try to have a similar layout during editing as well debugging. When running the program my structure and object inspector disappear. I did create my own desktop speedsetting, set the debug desktop to it as well, but as soon as the program runs structure and obejct inspector disappear. How can I prevent that?
A question related to this: the edit menu changes as well. A right click on a procedure name results in a popup menu with the first item being "find declaration". When debugging the first item is "close page". I find the find declaration item a fast way to find some code. Apart from that it is frustrating to lose one's code because you click "no" on the question to save the information (I know, it's my fault but menu's shouldn't change in my opinion).
Thanks,
Arnold
What version of Delphi? Dialogs and menus change between versions (and even between SKUs of the same version).
For the first, open Tools->Options->Environment Options and uncheck Hide designers on run in the Running group box (D2010, XE, and XE2), or Tools->Options->Environment Options and unchecking Hide designers on run in the Compiling and Running group box (D2007).
For the second: The right-click menu is called a context menu, meaning it displays what is appropriate in the context of when it's being shown. It's entirely appropriate for it to change depending on when and how you're using it; that's the way it's supposed to work.
Right-clicking on a .zip file in Windows Explorer is different than right-clicking on a Word .doc file, because they have different options based on context - a zip file has an 'Extract to...' option that the Word document doesn't have, because 'extracting' a Word document doesn't apply. Same applies to right-clicking a .exe file, which has the Run as Administrator option (Win7), as opposed to right-clicking a .pas file, which doesn't offer that option.

How do I embed a binary within a Delphi executable and extract at runtime?

I'd like to embed an executable inside of my Delphi binary and extract it at runtime. The purpose of this is to ensure that a helper utility is always available on the system, without having to distribute multiple files.
With Delphi 2007 I have used JvDataEmbedded, but I am building a console application and I want to know if anyone knows of another way to do it without having to add a hidden form for JvDataEmbedded.
I am using Delphi 2010.
Build a RC file that embeds this program as a resource, and then at runtime you can extract it with a TResourceStream. (See the accepted answer to this question of mine for the general principle.) You can chain the TResourceStream to a TFileStream to write it out to a temp file, then run it.
Cool Trick, Mason!
To add... It occurred to me that this could run into trouble with UAC/permissions if the "mothership" dumps teh "scout ship" diretly into the same directory as it's running from. If you're on Vista/Windows7, regular programs are prevented from writing to the "\program files" directory, when run without elevated permissions. So in that case, the file will likely be placed into a shadow directory. It gets better: you may have different results if you launch the "mothership" program from an installer, as setup programs have special access, and they may temporarily give that access to programs that they launch (which makes it somewhat hazardous to always say YES to "do you want to run the program now?" at the end of installation).
Use a TDataModule to hold the TJvDataEmbedded instead of a TForm.

Resources