This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to invoke a property editor at design time
I'm creating a non-visual component, and I want the user to be able to double click on my component at design-time and have that open a design-time editor.
How can I do it?
Double-clicking a component at design time invokes a component editor. The default component editor is one that looks for event properties with certain names and creates a handler for what it finds. You can write your own component editor that does whatever you want.
Create a descendant of TComponentEditor (from the DesignEditors unit) and override the Edit method to handle double-clicks. You can also override the GetVerbCount, GetVerb, and ExecuteVerb methods to add context-menu items to your component. To get a reference to the component your editor is being asked to edit, check the Component property. Call Designer.Modified if your editor modifies the component.
Tell the IDE that your editor should be used with your component by calling RegisterComponentEditor (from DesignIntf) in your Register procedure.
You should put this code in a design-time package, separate from your component's code. Put your run-time package on the "requires" list of the design-time package. If you put everything in a single package, then consumers of your component won't be able to use run-time packages in their projects; they're not allowed to distribute the dependencies of your design-time package, which are only for use by the IDE.
Related
I'm working with Firemonkey in Delphi XE4 and I'm unable to create a new component using the menu item Component -> New Component.
Whether the component is a VCL or Firemonkey component or whether I create a package first the result is the same.
The Tool Palette in Delphi appears to be searched and gradually it closes leaving it empty of components and a component dialog box that says "No Items available" when it comes to selecting an ancestor component.
I have two separate installations of Delphi XE4 and the same symptoms appear on both.
It appears that Delphi believes that there are no suitable base components on which to build a new component.
Creating components is fairly straightforward in code.
Create a unit.
Add code for your component.
Add a Register procedure.
procedure Register;
begin
RegisterComponents('NewPage', [TMyComponent]);
end;
Add a declaration for Register in the implements section.
Add a call to RegisterFMXClasses in your initialization section.
implementation
uses FMX.Types;
...
initialization
RegisterFMXClasses([TMyComponent]);
end.
Create a package.
Add the unit to the package.
Right-click the package (in the top-right panel) and select Install.
(Note: It's usually best to create your component at run time whilst testing. You only need to do the package stuff once it's fairly stable).
Information
I seem absolutely clueless as to how I should manage my component packages and install custom property editors. I have spent the last week or so looking at examples and tutorials, I must clearly be doing something wrong as my property editors never show up in the Object Inspector and I require step by step instructions to try and solve this frustration.
Component Package
I currently have one package, and it is set to designtime and runtime in the options. Added to this package are the units to my components (ie, MyButton, MyListBox etc) - Additionally I have a unit containing the RegisterComponents procedure. I can build and install this now, add my components to a new project and run them without any problems.
Adding a custom PropertyEditor
It gets tricky and confusing for me now that I want to introduce a property editor to my components from the package above.
TMyButton for example is a custom button with my own paint methods, it already has published properties to allow changing the appearance of the button - In addition there is also a published list to allow selecting preset appearance settings, example:
TMyButtonStyle = (bsStyle1, bsStyle2, bsStyle3)
I want to take away the list of preset styles and instead add a property to the Object Inspector called 'PresetStyles'. This property will be of paDialog, I want to a show a form where I can visually see the different button styles - a more graphical way of selecting a preset style then from a simple list.
Which packages do I need
If I understand, you need to split designtime packages and runtime packages?
Does this mean I need two register units, one for the components and one for the Property Editors?
I am not full sure how to manage this, as I said my current package is designtime and runtime, I am not sure what package type I should split it into. If I make a new designtime package for the Property Editors, and make the other package runtime only I lose the install button. Even writing this now is confusing me.
Installing the PropertyEditor
One of the articles I tried following was one from this page: http://www.delphisources.ru/pages/faq/master-delphi-7/content/LiB0097.html
The only thing I changed was add my own dialog form, and change the register code from:
RegisterPropertyEditor(TypeInfo(string), TMdSoundButton, 'SoundUp', TSoundProperty);
to
RegisterPropertyEditor(TypeInfo(string), TMyButton, 'PresetStyles', TSoundProperty);
I know it still says TSoundProperty, I just left it like that until I could get it working then I would change the class name.
Conclusion
What is the correct way of splitting/managing packages between actual components and the design side ie PropertyEditors?
The PropertyEditor never appears on TMyButton in the Object Inspector and I have a feeling it must be something to do with not configuring the packages correctly or something.
I would really appreciate some kind of assistance here, even a link to a really good tutorial guide or something as nothing I am doing seems to work, even using a lot of the examples are not working for me.
I currently have one package, and it is set to designtime and runtime in the options.
To implement custom property/component editors, you MUST separate your code into two packages - one runtime only package containing just the implementation code for the components themselves, and one designtime only package that contains just the implementation code for the component registrations and custom editor(s). The designtime package needs to specify the runtime package, and the designide package, in its Requires list. The runtime package is what gets compiled into executables. The designtime package is what the IDE uses to get your components to appear in the Component Palette and Form Designer and interact with them.
Does this mean I need two register units, one for the components and one for the Property Editors?
No. The runtime package should have no registrations at all. That belongs in the designtime package instead. You can have a single Register() function in the designtime package that registers everything.
If I make a new designtime package for the Property Editors, and make the other package runtime only I lose the install button.
You cannot install a runtime package into the IDE, only a designtime package.
One of the articles I tried following was one from this page: http://www.delphisources.ru/pages/faq/master-delphi-7/content/LiB0097.html
The only thing I changed was add my own dialog form, and change the register code from:
RegisterPropertyEditor(TypeInfo(string), TMdSoundButton, 'SoundUp', TSoundProperty);
to
RegisterPropertyEditor(TypeInfo(string), TMyButton, 'PresetStyles', TSoundProperty);
Does your TMyButton component actually define a PresetStyles property that is a String type? You cannot define a property editor for a property that does not exist.
Without knowing exactly how your PresetStyles property is implemented in the component itself and what it represents, it probably does not make much sense to invoke a popup Dialog for a String property (except maybe for things like filenames and such). Based on your description, it probably makes more sense to implement a component editor instead of a property editor, and leave your existing TMyButtonStyle property alone to use the IDE's default editor for enum properties. To invoke your popup dialog, the component editor would allow the user to right-click on the component itself and choose "Edit" (or whatever other string value you decide to name it) from the popup menu, or just double-click on the component, in the Form Designer. You can then display and edit the component as desired, and assign any changes to the component when the dialog is closed.
The PropertyEditor never appears on TMyButton in the Object Inspector and I have a feeling it must be something to do with not configuring the packages correctly or something.
It is hard to know for sure since you did not show any of your actual code yet.
If I understand, you need to split designtime packages and runtime packages?
Does this mean I need two register units, one for the components and one for the Property Editors?
No. One registration unit that registers both the components ánd the property editors is enough, as long as that registration unit isn't used at runtime (which normally isn't). This applies to the unit containing the property editor too. Prevent using DesignEditors.pas at runtime, and then you're fine.
Component Package
It is OK to have one package for both today. In the past it made sense to split them if an application was
distributed with runtime packages to reduce the total size. I like to split them up to now to
seperate the implementation and the design interface.
Which packages do I need
If you have two packages the runtime packages must be referenced in 'Requires' in the design time package.
Therefore you only have to register the design time package. The runtime package ist implicit loaded into the IDE.
In your case with one package you have to register this.
Installing the PropertyEditor
There is something wrong with the first parameter. It must be the typeinfo of the property.
RegisterPropertyEditor(TypeInfo(TMyButtonStyle), TMdSoundButton, 'PresetStyles', TSoundProperty);
TSoundProperty should be a descand from TEnumProperty.
Conclusion
Go on with one package. The property should appear with the changed code. If not check that the property is not readonly.
I'm trying to add a new property (Images: TImageList) to the TMS Control "TAdvSmoothDock" but the property doesn't appear in the Object Inspector
I defined it under "Published" as following :
Published
property Images: TImageList read GetImages write SetImages;
I can compile it but the property doesn't appear in the Object Inspector.
it does appear in the delphi IDE when using the control in the code:
like :
AdvSmoothDock1.Images := ImageList1;
currently I'm using Delphi XE2 VCL.
Regards.
You need to rebuild the TMS packages that contain the component, not just change the source code.
The Object Inspector doesn't use the code source to figure out what to display. It uses RTTI (run-time type information) it gets from the compiled version in the runtime package that contains the component (or the designtime package if there is no runtime package available.
Figure out what package the TMS component is in, open that package's source in the IDE (the .dproj file for the package), and do a build of that package. Make sure it's seeing your version of the source instead of the normal TMS version, so your changes are used.
(Of course, the proper way to do this would be to create your own descendant of the TAdvSmoothDock, add the property, put it into your own package that uses the TMS one, and never touch the TMS source code.)
You know in Visual Studio you can use the "+=" syntax and a couple tabs to have it autogenerate the code for an event handler?
How do I accomplish the same thing in Delphi? I'm trying to create an event handler for an event in an invisible activex library that I've imported using the Import Component function.
I realize that with imported activex controls you can just click the object, browse the events tab for what the component provides and double click on the event to have it generate one for you.
These particular activex components are invisible so you can select them on the form. Can Delphi autogenerate the code? If not, can someone point me to some sample code?
In Delphi, even non-visual components are represented on the form as small boxes with an icon. Just select that component and you can get to the events from the object inspector.
If you didn't install it on the component pallet, then there is no autogeneration of the code for the event handler. The easiest way would be to go into the generated tlb.pas file and find the signature of the event you want, copy it, and make a compatible method for it. Then just point the event property to that new method.
In a Delphi Form, I would like to replace one visual component with another. Example: I want to replace a Panel component with an ElPanel from a 3rd party package.
I would like all identical properties and events of the first component to be transferred to the new one, and all the components that belong to the first component (e.g. Toolbars, memos,status bars, etc.) to end up placed on the new component exactly where they were on the first one.
Is there a best/easiest way to do this other than adding the new component to the form and meticulously transferring every property, event and component to it one-by-one?
I do it as following:
Right click on the form and choose (View as Text).
Press Ctrl + F to search for the Component class name like TPanel and replace it with TElPanel
Switch back to back to the form (View as form)
In the interface section replace the TPanel with TElPanel.
if you have many components using GExperts will be more feasible solutions.
You can use GExperts or you can do it by hand.
To do it by hand, open the .dfm in notepad and replace all the class names. (Replace TPanel with TElPanel for example). When you've made all your changes, open the .pas file with Notepad, and do the same thing.
Make sure you add the required units to your uses clause.
Then open the form in the IDE and clean up any mismatched events or unknown property problems.
If I recall the excellent free GExperts plugin does this. Right click your form and select "Replace Components". http://www.gexperts.org
IMHO, the big drawback of the Replace component GExpert is that it changes the order of the components in the source code. That is not very VCS friendly. :-)
If you have other components inside a container doing this replacement with GExperts will cause some ugly exceptions and possibly unexpected behaviour in the IDE.
So, the best solution is to edit the .dfm file where you want (inside or outside the IDE) and replace manually the types of the components that you want to change. Maybe it will cause some exceptions too, but the IDE will managed them.
If you do it inside the IDE, after switching to design view if you save the .dfm inmediately the IDE will ask you to change the type of the variables related to the components you touched, liberating you to do it.
To convert between text and binary dfm formats, use the convert.exe tool in the Delphi bin\ directory. – Tim Knipe (Oct 28 at 4:15)
You can also use the context menu of the form designer - at least with BDS 2006. It's the last menu item ("Text-DFM" in a German IDE).
In my project I had to convert few doezens forms from one set of components to another.
I have created small perl script to convert components and its properties and do all neccesary mapings.
The script is quick&dirty solution but it is highly configurable. It scanns all dfm and pas files in project direcotory and convert dfm components definitions according to rules that you should provide in ObjectBeginFound, PropertyFound, ObjectEndFound procedures/events.
DFM files should be in text mode. Tested on Delphi 5 files. I don't know if it will be compatible with newer versions. Please send posts if you find it out.
USAGE:
perl.exe cxdfm.pl > logfile.txt
DOWNLOAD LINK
http://dl.dropbox.com/u/15887789/cxdfm.pl