Plugin access to forms

This forum is for programmers who have questions about the source code.
Post Reply
dmadsen
Posts: 2
Joined: Thu Feb 11, 2016 10:26 am

Plugin access to forms

Post by dmadsen » Fri Nov 16, 2018 4:21 pm

My company is wanting to upgrade to Open Dental 18.2 from 17.3 and we have several plugins that I have been testing to make sure they will work with the new version. I am seeing that version 17.3 of the forms in the Open Dental project inherited from ODForm, which in turn inherited from the standard System.Windows.Forms.Form. This enabled us to add a button to a form from a hook that fired off at the end of the form load.

So if the hook looks some thing like this:

Code: Select all

Plugins.HookAddCode(this,"FormPatientEdit.Load_end",PatCur);
Then we can do something like this:

Code: Select all

OpenDental.UI.Button myButton = new OpenDental.UI.Button();
myButton.Name = "btnGreatAndWondrous";
myButton.Text = "Great and Wondrous Button";
myButton.Location = new System.Drawing.Point(8, 665);
myButton.Size = new System.Drawing.Size(115, 26);
myButton.Click += btnGreatAndWondrous_Click;

formPatientEdit.Controls.Add(myButton);
formPatientEdit was the instance of the form sent to the hook as the sender input parameter. I just cast it as a FormPatientEdit. And once the control has been added to the form, clicking on it will call the method "btnGreatAndWondrous_Click" which is in the plugin code.

Now that I've downloaded 18.2, the plugin is failing on the line "formPatientEdit.Controls.Add(myButton);" because "Controls" is not a property of the form object anymore. The OpenDental project forms still inherit from ODForms, but now ODForms inherits from ODFormsAbs<Signalod> implements ISignalProcessor. When I reference formPatientEdit, the only methods available me are:
  • - Equals
    - GetHashCode
    - GetType
    - OnProcessObjects
    - OnProcessSignals
    - ShowHelp
    - ToString
And then it has a boolean property called "IsNew". I have searched through the documentation and the pluginexample, but I can't find any way of performing this same operation with the new structure of the code in 18.2. The PluginSample project seems to be using the old structure where the forms inherit from System.Windows.Forms.Form.

Is this something that isn't possible anymore or is there a new way of doing it that I just have not been able to find?

Thanks,
Dirk

User avatar
jsalmon
Posts: 1551
Joined: Tue Nov 30, 2010 12:33 pm
Contact:

Re: Plugin access to forms

Post by jsalmon » Sat Nov 17, 2018 7:51 am

All Open Dental forms are technically "System.Windows.Forms.Form"s by way of inheritance; FormPatientEdit > ODForm > ODFormAbs > Form
Therefore, you must not have told the compiler what your local "formPatientEdit" is so it has no idea how to treat it, thus it treats it like Object (the father of us all) plus some scope related options.
You probably want to change the declaration of your "formPatientEdit" variable.
Here is how you fix the snippet you gave (I don't know what "formPatientEdit" is so I completely removed it):

Code: Select all

OpenDental.UI.Button myButton = new OpenDental.UI.Button();
myButton.Name = "btnGreatAndWondrous";
myButton.Text = "Great and Wondrous Button";
myButton.Location = new System.Drawing.Point(8,665);
myButton.Size = new System.Drawing.Size(115,26);
myButton.Click += btnGreatAndWondrous_Click;
((OpenDental.ODForm)sender).Controls.Add(myButton);
This causes a great and wondrous button to show up in the bottom left of the Patient Edit window.
The best thing about a boolean is even if you are wrong, you are only off by a bit.

Jason Salmon
Open Dental Software
http://www.opendental.com

User avatar
jsalmon
Posts: 1551
Joined: Tue Nov 30, 2010 12:33 pm
Contact:

Re: Plugin access to forms

Post by jsalmon » Sun Nov 18, 2018 10:32 am

I read your post again but this time slowly, carefully chewing on every word and I think I understand your specific conundrum. Your plugin project must not have a reference to CodeBase thus it must not know what an ODForm even is in the first place. Simply add a reference to CodeBase in your plugin project and it should start working with whatever code you had before.
I have added a reference to CodeBase in our PluginExample solution / project (even though it is not directly used as you've pointed out) but will hopefully help future developers not have the particular issue you ran into if they choose to do such a casting.
The best thing about a boolean is even if you are wrong, you are only off by a bit.

Jason Salmon
Open Dental Software
http://www.opendental.com

Post Reply