cloning ABL forms

Posted by doug.macmillan on 18-Apr-2012 12:43

I routinely clone classes that have an assoiciated .resx file.

Invariably I get the error "visual designer cannot load this class.  An exception has occurred loading the design canvas: Object reference not set to an instance of an object."

What is the correct procedure to clone a class file with an associated resx?  I have done it from without OEA and outside of OEA.  The error just seems to go away sometimes and I have no idea why so I don't really know what I have done to fix it and I typically just move on at that point.

All Replies

Posted by Matt Baker on 18-Apr-2012 16:30

By "clone" do you mean "physically copy the .cls"?

The basic steps are:

Copy the .cls to a new .cls

Copy the .resx to the new .resx

Copy all the culture specific .resx files to the new _.resx

Edit the file to replace all the class name references in the constructor, destructor, and wherever else.

Edit the first few executable lines of "InitializeComponent" method so that it points to the proper .resx.

Edit:

You can also copy paste all the UI.

Create a new Form.

Open the old one, Press Ctrl+A to select everything.

Switch to the new Form

Press Ctrl+V to paste everything.

Save.

Posted by Thomas Mercer-Hursh on 18-Apr-2012 16:37

Personally, I think that if you are doing this a lot, then there is something wrong with your development process.  Really common code should get encapsulated in custom controls or classes.  Routine stuff should be done with generators.  Etc.

See http://cintegrity.com/content/Search-Lazy-Programmer for some ideas.

Posted by doug.macmillan on 19-Apr-2012 07:57

Development environment aside (that is a diff question) - what does the error that I posted mean and what is the solution or the meaning of the error message?

Posted by Matt Baker on 20-Apr-2012 06:09

Its a null pointer exception.  It means you have a variable definition in your code that is being used, but it was never assigned to anything.  You can open the .log file for the workspace and see the complete stack if you want...but unfortunately it won't tell you anything because forms are dynamically interpretted line by line so the stack would probably be pointing to something inside the designer code and not to a line in InitializeComponent in the form.

mattB

Posted by Shelley Chase on 20-Apr-2012 09:22

The null pointer exception happens when you have not changed the name of the .resx for the ResourceManager load. As Matt stated you need to:

  • Edit the first few executable lines of "InitializeComponent" method so that it points to the proper .resx.

My guess it that the ResourceManager creation/load fails but is referenced later in InitializeComponent without checking for null. This will result in the error you are seeing.

-Shelley

This thread is closed