Standard Edit Actions and TJvEditor

By | November 2, 2008

Delphi’s standard edit actions (TEditCut, TEditCopy, …) do not work with the TJvEditor/TJvHLEditor because they require the component to be derived from TCustomEdit what TJvEditor isn’t. A better implementation would use an interface that the controls can implement if they want the actions to work for them. And that is exactly what the new JVCL Standard Edit Actions do. I have designed them to be backward compatible to TCustomEdit but if a component supports the IStandardEditActions interface the actions switch to the interface mode. With this new set of actions I can now control both the TEdit and the TJvEditor without writing a single line of code.

Unfortunately writing these action classes was the easy part. The much harder part was to get the localized captions, hints, shortcuts, … properties. I didn’t want to translate them by myself because the IDE already has the correct translation. But how does it set the action properties. If you create a TEditCut action in the code you get the Caption “EditCut1”. But if you add the action through the “Standard Actions” dialog it is set to “Cut” (engl.) or “Ausschneiden” (ger.) depending on Delphi’s localization. This means that there must be some code in the form designer that fills the properties after the standard action was created. By assuming this I opened a console window, navigated to the “RAD Studio\6.0\bin” directory and used the good old “find” command to look for the action’s German hint “Ausschneiden|Markiertes Objekt in die Zwischenablage verschieben” in the .de files. I had two hits. One in dclstd120.de and one in webappdbg.de.
Because the “ActnList.RegisterActions” function has a third parameter with the name “Resource” I opened the dclstd120.bpl with PE Viewer (JEDI Tools from the JCL) and what I found was a “TStandardActions” formular resource that contains all the standard edit actions with their properties set to the correct values. I draw the conclusion that the formular designer must use the “RegisterAction” “Resource” parameter to load the formular resource and then copy the property values to the new action instance.

With this knowledge I began to write a component class that creates an instance of the dclstd120.bpl:TStandardActions class (exported symbol “@Actnres@TStandardActions@”) and copies the properties to the JVCL standard edit actions. And without any problem (except that the “Category” property is overwritten by the formular designer) the JVCL standard edit actions are now localized and have their properties set.