On Sun, Aug 26, 2012 at 7:42 PM, Art Heimsoth <artst...@artheimsoth.com> wrote: > What is the proper way to end a program where an error is detected > with system data in the Init or InitDialog methods?
If you detect an error in the init() method, the best thing to do is to set initCode to non-zero. Then after you do the .MyDlg~new, check the initCode. Many / some of the examples do check the initCode, but with a lot of my programs I stopped doing that. (I know I'm not setting initCode to non-zero, and it is almost impossible for an internal error to happen.) On the other hand, if you know that you might be setting the initCode, then be sure and check it. Like this: dlg = .CustomDrawDlg~new('customDrawListview.rc', IDD_CUSTOMDRAW) if dlg~initCode <> 0 then do say 'Error initializing dialog. Init code:' dlg~initCode say 'Aborting' return 99 end dlg~execute("SHOWTOP") return 0 ... ::method init expose textRed textBlack forward class (super) continue ret = self~customDraw if ret <> 0 then do self~initCode = 17 return self~initCode end self~customDrawControl(IDC_LV_CUSTOM, 'ListView', onCustomDraw) ... In initDialog() on the other hand, the underlying Windows dialog has already been created, so you want to end with cancel() or ok(). I usually just do this ::method initDialog ... do some stuff if <detected error> then do -- maybe print an error message return self~cancel:super end > I define some > fonts in the InitDialog method and then delete them in the Cancel > method. If on the detected error condition, I invoke the cancel method > after presenting an error message, I get an invalid argument on the > DeleteFont() request. Oh , I see you are already doing it a good way. What you want to do is over-ride the leaving() method and do your deleteFont() there. Leaving is especially provided for just this purpose. The ooDialog framework will invoke that method before the underlying Windows dialog is destroyed. Something like this: ::method leaving unguarded expose myFont self~deleteFont(myFont) return 0 In fact the program I pulled the first code snippets out of does exactly that. /** leaving() * * This method is invoked automatically by the ooDialog framework when the * dialog is closed. It should be used to do any needed clean up. Here we * delete the font we created. * * Note that the colors we created are just numbers and do not represent any * system resource and therefore need no clean up. */ ::method leaving unguarded expose checkedFont self~deleteFont(checkedFont) return 0 > Also, if I have a method defined to get > control from a ConnectPosChanged() request, that also gives me > an error on the dialog requests dealing with changed Edit control > elements. These items do not give an error if I do not attempt > to call the Cancel method before the Init or InitDialog methods have > returned. Don't call cancel() from init(), use the initCode attribute to signal an error. In initDialog() it should work fine. I'd need to see more of your code to understand why you are getting the error you are talking about. (Actually, after re-reading that paragraph, I'm not sure I know what you are doing.) On the face of it, I don't think you should get an error. But, I'd need to look at your code. It is easily enough fixed, but I don't want to suggest how until I'm sure I understand what is actually happening. Maybe clean up things with my suggestions and if you are still getting this error, then show more of your code. -- Mark Miesfeld ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Oorexx-users mailing list Oorexx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/oorexx-users