I am working on a project using Delphi 7 and Delphi 2006, i am developing a component that will get certain system information.
Now the requirement is that after the component is installed on the system, there should be a menu item on the IDE , like this
and for delphi 7 like this
i have searched on the net about adding a menu item but i have not got anything to add an item to the IDE like the one EurekaLog has.
can any body tell me how to add the item like EurekaLog or mysql ?
is it some where in the registry?
To add a menu to the Delphi IDE you must use the Delphi Open Tools API. from here you can access the Main menu of the delphi IDE using a code like this.
LMainMenu:=(BorlandIDEServices as INTAServices).MainMenu;
or
LMainMenu:=(BorlandIDEServices as INTAServices).GetMainMenu;
And then add the menu items which you want.
Check these links for additional samples
Open Tools API Chapter 15: IDE Main Menus
Introduction to the Delphi Open Tools API
How can I add a menu item to the IDE’s main menu?
If you want to specifically add a menu item to the HELP menu, and also make it get removed when your package unloads, and handle enable/disable of the items, then this wizard code might be helpful. I took the sample wizard code that GExperts documentation shows as a starter project, and posted it up here as a slightly nicer start project. You can get started very quickly if you grab this code and just extend it:
https://bitbucket.org/wpostma/helloworldwizard/
What they mean by "Wizard" is a "simple IDE Expert", that is, something with a menu added to the IDE, that implements IOTAWizard and IOTAMenuWizard. This approach has many benefits and is the way that the GExperts wizards are written.
The core of the code is this starter wizard, which needs to be put into a package (DPK) and installed, and registered with the IDE:
// "Hello World!" for the OpenTools API (IDE versions 4 or greater)
// By Erik Berry: http://www.gexperts.org/, eberry#gexperts.org
unit HelloWizardUnit;
interface
uses ToolsAPI;
type
// TNotifierObject has stub implementations for the necessary but
// unused IOTANotifer methods
THelloWizard = class(TNotifierObject, IOTAMenuWizard, IOTAWizard)
public
// IOTAWizard interface methods(required for all wizards/experts)
function GetIDString: string;
function GetName: string;
function GetState: TWizardState;
procedure Execute;
// IOTAMenuWizard (creates a simple menu item on the help menu)
function GetMenuText: string;
end;
implementation
uses Dialogs;
procedure THelloWizard.Execute;
begin
ShowMessage('Hello World!');
end;
function THelloWizard.GetIDString: string;
begin
Result := 'EB.HelloWizard';
end;
function THelloWizard.GetMenuText: string;
begin
Result := '&Hello Wizard';
end;
function THelloWizard.GetName: string;
begin
Result := 'Hello Wizard';
end;
function THelloWizard.GetState: TWizardState;
begin
Result := [wsEnabled];
end;
end.
The registration code is not shown above, but is included in its own "Reg" (registration) unit if you download this from the link above. A tutorial link is on EDN here.
Related
I changed for Delphi 10.3 and its default TOpenDialog contains a preview pane. I made some searches and found the IFileDialogCustomize interface provided by Microsoft to customize standard WinAPI dialogs. I know I have to use the OnSelectionChange event handler to modify the picture of the pane. The big question for me is : how can I access the preview pane image by IFileDialogCustomize? What is the ItemID for this? I couldn't find any answer to this question on the net. Somebody know the answer? Then please share with me and the community! :)
I replaced some code fragments by ... for the sake of brevity, because these are trivial or app dependent sections.
procedure TMainWindow.OnSelectionChange( Sender : TObject );
var
dc : HDC;
aBMP : TBitmap;
function isSelectedFilePreviewAble : boolean;
begin
result := ...;
end;
functon getPreviewPictureDC : HDC;
var
iCustomize : IFileDialogCustomize;
h : THandle;
begin
if OpenDialog1.QueryInterface( IFileDialogCustomize, iCustomize ) = S_OK then
begin
h := iCustomize.??? this is the missing code fragment
result := GetDC( h );
end else
result := 0;
end;
procedure generatePreviewPicture;
begin
...
end;
begin
dc := getPreviewPictureDC;
if ( dc <> 0 ) then
begin
aBMP := TBitmap.Create;
try
if ( isSelectedFilePreviewAble ) then
generatePreviewPicture;
StretchBlt( aBMP.Handle, ...);
finally
aBMP.Free;
ReleaseDC( dc );
end;
end;
end;
I made some searches and found the IFileDialogCustomize interface provided by Microsoft to customize standard WinAPI dialogs.
First, IFileDialogCustomize does not "customize standard WinAPI dialogs". It customizes only IFileOpenDialog and IFileSaveDialog dialogs, no others.
Second, TOpenDialog primarily uses the legacy Win32 API GetOpenFileName() function. On Windows Vista+, GetOpenFileName() uses IFileOpenDialog internally with basic options enabled, so that legacy apps can still have a modern look.
Although, under the following conditions, TOpenDialog will instead use IFileOpenDialog directly rather than using GetOpenFileName():
Win32MajorVersion is >= 6 (Vista+)
UseLatestCommonDialogs is True
StyleServices.Enabled is True
TOpenDialog.Template is nil
TOpenDialog.OnIncludeItem, TOpenDialog.OnClose, and TOpenDialog.OnShow are unassigned.
But even so, TOpenDialog still does not give you access to its internal IFileOpenDialog interface, when it is used.
If you really want to access the dialog's IFileOpenDialog and thus its IFileDialogCustomize, you need to use TFileOpenDialog instead of TOpenDialog (just know that dialog won't work on XP and earlier systems, if you still need to support them).
The big question for me is : how can I access the preview pane image by IFileDialogCustomize?
You don't. The preview pane is not a dialog customization, so it can't be accessed via IFileDialogCustomize. Even if you could get a control ID for the preview pane (which you can't), there is no function of IFileDialogCustomize that would allow you to access the preview pane's HWND or HDC, or otherwise alter the content of the preview pane in any way. The preview pane is an integral and private component of IFileDialog for any file type that supports previews. It is not something that you can access and draw on directly. IFileOpenDialog itself will update the preview pane as needed when the user selects a file that has (or lacks) a preview to display.
My boss want to show previews for our own file formats.
The correct way to handle that on Vista+ is to create a Preview Handler for your custom file types. Then, any Shell component that wants to display previews of your files, including IFileOpenDialog, can use your handler.
Details/Scenario:
I am using Delphi XE6 with DevExpress 13.1.4 Components and i have a dxRibbon component.
The keytips that i mean is that F, Y1, Y2, Y3... 1, 2, 3... that shows up when i press alt on the keyboard as you can see below:
Question:
I want to disable the KeyTips of my Ribbon(the one that shows up when i press alt on keyboard), i have tried so many ways but i am unable to disable it, how it can be done?
Limitations:
I cannot modify the source of dxRibbon.pas or rebuild the DevExpress Components.
You have stated the following requirements:
Your program must use the DevExpress ribbon.
Your program must not modify the DevExpress ribbon.
This DevExpress support thread states that the keyboard shortcut tips cannot be disabled.
From which we can conclude that it is not possible to achieve your goals.
Step 1.
Use Andy's VCL VCLFixPack.
Step 2. Create a new Unit:
unit DxBarNix;
interface
implementation uses VclFixPack, dxBar;
var
NixKeyHook: TXRedirCode;
procedure NixKeyTip( AShowKeyTipWindows: Boolean);
begin
end;
procedure StartDxRibbonHook;
begin
HookProc(#dxBar.TdxBarNavigationController.EndKeyTipsWaiting, #NixKeyTip, NixKeyHook);
end;
procedure StopDxRibbonHook;
begin
UnhookProc(#dxBar.TdxBarNavigationController.EndKeyTipsWaiting, NixKeyHook);
end;
initialization
StartDxRibbonHook;
finalization
StopDxRibbonHook;
end.
After this, the KeyTips will disappear.
I'm using great TExceptionDialog from JEDI JCL package to show unhandled exceptions inside a C++ builder XE project, everything running ok so far. I've decided to enhance it a little bit by writing my own custom form to upload crash report to a server via FTP.
Problem is that I can't open my custom form from delphi PAS unit, tried to define as an external (no delphi programmer here, sorry :( ) but don't know how to properly code that. I've read lots of tutorials but couldn't find anything useful besides writing a DLL or an OLE container for my custom form, realy overkill for this project.
Question is, how can I properly execute this task? how to do ShowModal() of a form defined in a C++ unit, from a PAS delphi unit?
I've found an easy and practical way of doing it, kinda ugly but works!
Trick is to get form by iterating thru all forms with Screen.Forms object. I've set TAG property for my form to a predefined number just to get an easy id of it.
In short, inside C++ unit of my form, I'll do this:
MyForm->Tag=9999; // easy way of Iding my form
Then, inside my delphi unit of TExceptionDialog, in SEND button click method:
procedure TExceptionDialog.SendBtnClick(Sender: TObject);
var
i: integer;
form: TForm;
begin
for i := 0 to Screen.FormCount-1 do // all forms
begin
form := Screen.Forms[i]; // get a form
if(form.Tag = 9999) then // check if its my form
begin
form.ShowModal; // if its mine, call showmodal
break;
end;
end;
ModalResult := mrOk; // return to my app
end;
I am going through most of my applications and porting them to D2009 and I have one application that makes use of dynamic packages. For the life of me I cannot get my host application to recognize classes registered in a package. I traced through and the initialization section in the package being loaded was called and RegisterClasses was called but when I do a GetClass() call the classes are not available. Is there someone out there who can enlighten me as to what might be going on? I have researched and looked to see if there are any issues with the D2009 release and dynamic packages and so far I have found nothing. I'm beginning to wonder if I have a corrupted installation of Delphi or some other problem.
TIA
If you are using a 3rd party memory manager then make sure it is proven to work with D2009 (actually 2007 and up).
With FastMM (which is the default MM since 2007) you would have to set the UseRuntimePackages define in FastMM4Options.inc
make sure that the following steps are done:
Create a new package in Delphi;
Insert a form in this package;
Insert a "inicialization" section in the form and uses the RegisterClass method. (registerClass(TForm1)); Don't forget the "T".
Save and compile the package;
Close all;
Copy the .bpl file (c:\Users\Public\Documents\RAD Studio\5.0\Bpl) to the application folder;
Create a new aplication in Delphi;
Go in Project > Options > Packages, and check the box "Build with runtime packages";
Leave only "vcl;rtl" in the text field and click OK button;
Insert a button;
In the source of the button, insert the code:
procedure TForm1.Button1Click(Sender: TObject);
var
PackageModule: HModule;
AClass: TPersistentClass;
begin
PackageModule := LoadPackage('Package1.bpl');
if PackageModule <> 0 then
begin
AClass := GetClass('TForm2');
if AClass <> nil then
with TComponentClass(AClass).Create(Application)
as TCustomForm do
begin
ShowModal;
Free;
end;
UnloadPackage(PackageModule);
end;
end;
Compile the application. =)
There doesn't appear to be a simple component available to create a folder selection dialog in Delphi 2009, although a file selection dialog is provided by way of the TOpenDialog.
What is the most common way to create a modern folder selection dialog using Delphi?
There are two overloaded routines in FileCtrl.pas called SelectDirectory
For a modern look, use the second form, with sdNewUI
var
dir : string;
begin
dir := 'C:\temp';
FileCtrl.SelectDirectory('Select', 'C:\', dir, [sdNewFolder, sdNewUI], Self);
end;
NOTE: sdNewFolder, sdNewUI etc are only available from D2006+
you can use SelectDirectory from FileCtrl unit
using FileCtrl;
var
St: string;
begin
St:='c:\';
if SelectDirectory(St,[],0) then
begin
end;
end;
You can download a component PBFolderDialog from "http://bak-o-soft.dk/Delphi/PBFolderDialog.aspx" which is quite easy to use and offers access to all options of the Windows "SHBrowseForFolder" dialog; something which the built-in ones not do.
It's freeware with source and not too difficult to port to Delphi 2009.
See the sample code:
Delphi tip#157: select folder dialog
http://www.scalabium.com/faq/dct0157.htm