How can I restore the synchronization between the auto-create forms list and the DPR initialization code? - forms

I have a D2006 app in which the DPR file has had numerous edits (yes, I know - you shouldn't mess with the DPR file) to accommodate such things as a splash screen, preventing a second instance of the app being started, handling of command line options that need to be processed before any forms are created, etc.
One day, I noticed that the auto-create forms list in the project options is empty - but the DPR file still has the code in there to create some of the forms.
If I try to restore all the forms that should be auto-created from the dialog, it complains Error - Call to Application->CreateForm is missing or incorrect and doesn't do anything.
How can I restore this connection - apart from rebuilding the DPR from scratch?
is it safe to manually add the CreateForm calls?
are there any documented rules as to what you can do in the DPR file?
I have a suspicion that try..except and if..else clauses in the DPR upset Delphi. Will moving as many functions as possible to a separate unit and calling them be helpful?

I haven't really seen any documented rules as to what you can do in the DPR file, because I guess there are no strict rules.
The problem begins when you create a "Forms" application. (No problems with console or non-GUI applications I've noticed).
The IDE will automatically change the DPR any time you add a new Form or a DataModule to it, by assuming you want to auto-create them.
This can mess up your DPR, if it has a lot of code/compiler-directives/if-blocks/try-catch blocks etc...
So I'll tell you what my rules are, and in a short line:
Keep it as simple as you can.
My DPR contains only a call to some init code and auto creates the main form only:
MyAppInit; // in AppInit unit
Application.Initialize;
Application.CreateForm(TMainForm, MainForm);
Application.Run;
However in the uses section I add (or keep what the IDE added) all the forms my application uses (and also application related units) - this is useful when I want to view->forms or view-units.
In-fact when I add a new form to the application, the first thing I do is go the DPR and remove the line:
Application.CreateForm(TMyNewForm, MyNewForm);
NOTE (EDIT): The IDE can be configured to NOT auto create forms (No Application.CreateForm entry will be created in the DPR). In older version of Delphi this option is under: Tools/Environment Options/Preferences -> Auto create forms. In newer versions: Tools/Options/VCL Designer/Module creation options -> Auto create forms & data modules.
At run-time, I create all my forms dynamically when I need them, and destroy them when they no longer needed. DataModules/Splash (etc...) are created on the MainForm.OnCreate event.
This method has worked for me nicely for the past few years maintaining a large scale DB application. This will probably not cover all cases, but it worked fine for my needs.
P.S: "Is it safe to manually add the CreateForm calls" - Yes. But think twice if you really need them to be auto-create by the application.

IMHO You don't really need that AutoCreate forms from Delphi, but maybe in the casual test project.
And the dpr is just another source code file, where you're meant to write code to make things happen (or prevent it to happen), so don't worry if you lost that sincronization, which IMHO is buggy if can't read your pascal code to work properly.
If you still want to create some forms from the DPR, add the Application.CreateForm or TMyForm.Create calls manually to the file, AFAIK there's no rules against doing it that way.

Since Delphi owns the .DPR, I put my startup logic into a separate unit for each project.
That works really well, only very few entries need to be in the .DPR.
Since that unit controls the Application.CreateForm logic too, the IDE has an empty list for that: I'm fine with that.
The only things left in the .DPR are:
the big uses that indicates which modules are part of your project
a call to Main in the startup logic unit

Related

Access 2010 Form.Repaint - Hanging

I'm hopefully missing something obvious here...
I have just kicked off developing a new Access 2010 application. Something personal and hopefully simple.
The first thing I need to do is read a bunch of files off of the hard drive. I parse the contents adding the information to a table if it doesn't already exist.
Code works fine, that's not the issue. As it can take a while I've added a simple progress dialog using a standard form but in dialog/popup mode. As the For Each loop of the FSO.Folder.Files object is progressed I send some information to a couple of text boxes and issue a Me.Repaint (have also tried DoCmd.RepaintObject acForm, "FormName").
The issue is that I can get anywhere from 5% to 35% of the process complete before the repaints stop responding. The form only repaints when it gets to 100%.
The process uses limited recursion - if there is a subfolder - it calls itself to process that subfolder, but the folder structure is fairly linear so not many of those.
There are nothing bound to the form. All table updates happen in code and via RecordSets.
Any ideas why Access stops responding?
Cheers,
Roy
Add DoEvents after Repaint. That will cause Access to yield to Windows, which will can then handle its pending tasks ... such as updating the display in this case.
Actually, if your code updates text boxes, I don't see why you need to Repaint the form in order to display the changes. Try something like this instead ...
Me.MyTextBox = "hello"
DoEvents

How do you set up an Optimizely test for a single-page app?

I have a single-page web app that presents a multi-step photo management "wizard", split up across several discrete steps (photo upload, styling, annotation, publishing) via a tab strip. On switching steps I set the URL hash to #publishing-step (or whichever step was activated).
How do I set up Optimizely tests to run on the various discrete steps of the wizard?
The browser never leaves the page, so it only gets a single window.load event. Its DOM isn't getting scrapped or regenerated, but just switches what page elements are visible at any one time via display: none or block, so the part I am trying to figure out is really mostly about in what way I go about the Optimizely test setup itself - it's fine (and likely necessary) if all edits get applied at once.
This thing unfortunately has to work in IE9, so I can't use history.pushState to get pretty discrete urls for each step.
There's actually several ways you could go about doing this, and which option you choose will largely depend on what's easiest for you AND how you plan to analyze the data.
If you want to use Optimizely's analytics dashboard:
I would recommend creating one experiment which will activate a bunch of other experiments at different times. The activation experiment will be targeted to everyone and run immediately when they get to your wizard. The other experiments will be set up with manual activation and triggered by this experiment.
The activation experiment would have code like:
window.optimizely = window.optimizely || [];
function hashChanged() {
if(location.hash === 'publishing-step') {
window.optimizely.push(['activate', 0000000000]);
}
if(location.hash === 'checkout-step') {
window.optimizely.push(['activate', 1111111111]);
}
}
window.addEventListener('hashchange', hashChanged, false);
Or you could call window.optimizely.push(['activate', xxxxxxxxx]); directly from your site's code instead of creating an activation experiment and listening for hashchange.
If you want to use a 3rd party analytics tool like Google Analytics:
You could do this all in one experiment with code similar to above, but in each "if" section instead of activating an experiment, you could run your variation code that makes changes to the wizard and sends special tracking information to your analytics sweet for later reporting. You'll have to do your own statistical significance calculation for this method (as Optimizely's data won't be "clean"), but this method actually works out better usually if properly configured.
Alternatively you could use the method outlined above but still try to use the Optimizely analytics dashboard by creating custom events on your experiment and sending data to them using calls like window.optimizely.push(["trackEvent", "eventName"]);
This article may also be helpful to you.
You'll probably need to do this yourself, using Optimizely's JS API to trigger actions on their end and tell it what your users did: https://www.optimizely.com/docs/api

layout initialisation peculiarity in Zend Framework

I've noticed something interesting about Zend Framework's bootstrap. I created a new project and then used
zf enable layout
to enable the layout engine. It worked out of the box, woo!
But then I tried creating a function called _initLayout in the bootstrap to set some options. Interestingly, this seems to disable the layout again, even if the function body is actually empty. No errors are thrown, but the layout script is not used anymore (exception being the case when I actually set the options again and manually call Zend_Layout::startMvc()).
Renaming the function to anything else, like _initFoo makes the layout work again.
So, my question is: is this a function name that is somehow recognised by Zend Framework and extra actions are applied to it, such as cancelling the layout config from application.ini? Are there other cases where I should avoid certain _init* function names in the bootstrap?
The main purpose of the Bootstrap is to setup resources that the application uses. These can either be setup by lines in the config file (resources.resourcename.foo) or by methods in the bootstrap class (_initResourceName()). I assume zf enable layout has added some resources.layout.* lines to the application.ini. By adding an _initLayout method to the bootstrap, ZF will use this to setup the layout resource instead of the configuration lines.
Are there other cases where I should avoid certain _init* function names in the bootstrap?
The resource plugins are detailed in the manual: http://framework.zend.com/manual/en/zend.application.available-resources.html, _init<resourcename>() will always override any corresponding lines in the config.

how can I improve iPhone UI Automation?

I was googling a lot in order to find a solution for my problems with UI Automation. I found a post that nice summarizes the issues:
There's no way to run tests from the command line.(...)
There's no way to set up or reset state. (...)
Part of the previous problem is that UI Automation has no concept of discrete tests. (...)
There's no way to programmatically retrieve the results of the test run. (...)
source: https://content.pivotal.io/blog/iphone-ui-automation-tests-a-decent-start
Problem no. 3 can be solved with jasmine (https://github.com/pivotal/jasmine-iphone)
How about other problems? Have there been any improvements introduced since that post (July 20, 2010)?
And one more problem: is it true that the only existing method for selecting a particular UI element is adding an accessibility label in the application source code?
While UI Automation has improved since that post was made, the improvements that I've seen have all been related to reliability rather than new functionality.
He brings up good points about some of the issues with using UI Automation for more serious testing. If you read the comments later on, there's a significant amount of discussion about ways to address these issues.
The topic of running tests from the command line is discussed in this question, where a potential solution is hinted at in the Apple Developer Forums. I've not tried this myself.
You can export the results of a test after it is run, which you could parse offline.
Finally, in regards to your last question, you can address UI elements without assigning them an accessibility label. Many common UIKit controls are accessible by default, so you can already target them by name. Otherwise, you can pick out views from their location in the display hierarchy, like in the following example:
var tableView = mainWindow.tableViews()[0];
As always, if there's something missing from the UI Automation tool that is important to you, file an enhancement request so that it might find its way into the next version of the SDK.
Have you tried IMAT? https://code.intuit.com/sf/sfmain/do/viewProject/projects.ginsu . It uses the native javascript sdk that Apple provides and can be triggered via command line or Instruments.
In response to each of your questions:
There's no way to run tests from the command line.(...)
Apple now provides this. With IMAT, you can kick off tests via command line or via Instruments. Before Apple provided the command line interface, we were using AppleScript to bring up Instruments and then kick off the tests - nasty.
There's no way to set up or reset state. (...)
Check out this state diagram: https://code.intuit.com/sf/wiki/do/viewPage/projects.ginsu/wiki/RecoveringFromTestFailures
Part of the previous problem is that UI Automation has no concept of discrete tests. (...)
Agreed. Both IMAT and tuneup.js (https://github.com/alexvollmer/tuneup_js#readme) allow for this.
There's no way to programmatically retrieve the results of the test run. (...)
Reading the trailing plist file is not trivial. IMAT provides a jUnit like report after a test run by reading the plist file and this is picked up by my CI Tool (Teamcity, Jenkins, CruiseControl)
Check out http://lemonjar.com/blog/?p=69
It talks about how to run UIA from the command line
Try to check the element hierarchy, the table can be placed over a UIScrollView.
var tableV = mainWindowTarget.scrollViews()[0].tableViews()[0].scrollToElementWithName("Name of element inside the cell");
the above script will work even the element is in 12th cell(but the name should be exactly the same as mentioned inside the cell)

SDL.NET (VB/C#): What should the startup object and application type be?

I eventually couldn't get any further with my program due to the various shortcomings of VB.NET (bad audio support, no reading events in the middle of execution, very weak keyboard input, etc). So I tried SDL.NET 6.1.
Despite its terrible documentation, I was able to fix my code to use it and I love it!
But there's a problem. I don't know how to set up my application settings for it. The Startup Object definitely should be a class (the examples always are in classes, never modules), but a startup class specifically has to be a form! This is bad because SDL makes its own window via SetVideoMode; you don't need a form. So when the form constructor New() finishes, a useless form is created and you have two windows.
I tried placing a call to the game engine loop within New() so that the game starts up without New() ever finishing. The game runs normally, and this solves the "second window" problem... but it can't be closed! X button does nothing, calls to Events.QuitApplication or Me.Close are blatantly ignored, etc.
I'm stumped. It seems I need to set a non-form class as the startup object, but it won't let me.
Oh, by the way, it seems that there are two things called "SDL NET". To clarify, I'm using this one, which exists in the SdlDotNet namespace.
Oh, I forgot to mention, I also noticed that a lot of the examples have a line that says "[STAThread]". Is this is important?
EDIT:
I've already received and accepted an answer for my question, but I want to tell other people what the problem is with exiting/closing the app, even though that wasn't my question:
While SDL.NET allows you to receive input and run other events without having to stop running logic, the application still cannot quit while logic is being run. So I find the best way to tell your SDL.NET application to Quit in the middle of running logic is to use the following TWO lines:
SdlDotNet.Core.Events.QuitApplication
End
Place these in the handler for the SdlDotNet.Core.Events.Quit event, as well as anywhere else you want your program to quit.
The Startup Object definitely should be a class (the examples always are in classes, never modules)
Here's your mistake. There's no real difference between a class and a VB module from CLR perspective. So just make it a module with Main and go on. There is no need for a class. I suspect you're looking at C# examples, which use classes - but that's because there is no such thing as a module in C#.
[STAThread] probably won't make any difference for SDL. It is important for UI applications (both WinForms and WPF require it), but I don't think that SDL does any COM calls, so it shouldn't care whether your thread is STA or not. It's just something that Visual Studio puts on Main in new projects by default.