Subscribe!

Don't forget to...

 Subscribe

Monday, May 30, 2011

SQL Server 2005 Hidden Install of Express Tools

A few weeks ago I was given the long-winded task of installing all of the necessary software on my new remote developer cpu at my shiny new job.  All went well until - GASP! - SQL Server 2005 refused to complete its installation.

Now there were actually 2 problems with the install.  You see, it would hang while the status window read "Setting File Security" and it stayed there for what seemed like forever.  This was happening because the remote machine was connected to a network which was monumentally large (it's a pretty large organization) and the install was trying to find all the nodes in the network.  There's a patch for this type of problem that can be used with the installation, but if this is the only problem, the user can also just wait it out.  Which is what I chose to do.  And then the real problem showed up.

After 2-3 hours of waiting (I had other work to do..honest) the installation finally "completed" by giving me an error message saying something like the developer tools were already installed.  So basically, all of the SQL Server components installed correctly, except for management studio...which is the one I needed!

After scouring the internet for days and trying every patch fix and forum tip I could find, I finally found a solution.  But it was dangerous.  I had actually found it earlier on, but hesitated at trying it, as it required me to edit the registry, which I've never done before, and I'm sure could royally screw up my new remote machine.  But at this point I had no choice, as even my coworkers had no idea what was going on.

So I followed directions in the article, and it turns out that on my remote machine (which had been used previously, probably by another programmer) there was a previous install of SQL Server 2005 Express Tools that didn't show up in add/remove programs in the control panel!  It must've been un-installed un-properly.  Long story short, I followed the articles instructions and removed all the SQL Server entries in the database, including that one for the Express Tools.  Then I ran the installation one more time (again, I just let it go for 2 hours to alleviate the first issue) and lo-and-behold, SQL Server was finally installed on my cpu.  Here's the article that made it all worth while:

http://support.microsoft.com/kb/909967


and here's the article on my page, in case it ever gets moved:



Thursday, May 26, 2011

Adobe Flex 3.0 - Passing parameters to event listeners - actionscript

So I just started this job, and I'm writing an application that lets users view photos and tag them, giving descriptions of the tags as well.  I was trying to add an event listener to a Text object, when I realized there was no way to add a parameter to it!  Because the addEventListener function goes like this:

var itemToPass:Object;
textObject.addEventListener(MouseEvent.MOUSE_OVER, callbackListenerFunction);

there was no way to pass a parameter, except for the event object, which is passed automatically.  Of course you could use an anonymous function for the callback, like this:

var itemToPass:Object;
textObject.addEventListener(MouseEvent.MOUSE_OVER, function(event:Event):void {
    callbackListenerFunction(itemToPass);
});

And this will work in many cases.  But the underlying problem is still there!  You see, if you change the value of itemToPass later on in the current code block, then the value that's passed into callbackListenerFunction is ALSO changed!  The code I had at first was something like this:


for each(textObj:Text in TextObjectList)
{
    //..........
    var itemToPass:Object = someValue * whatever;
    textObject.addEventListener(MouseEvent.MOUSE_OVER, function(event:Event):void {
        var param1 = itemToPass;
        callbackListenerFunction(param1);
        //................
    });

}

which may seem like a good solution to the untrained eye....or brain...whatever.  The problem is the way Flex 3.0 (or actionScript, I dunno) instantiates and stores variables.  You see, in most object-oriented languages, when you instantiate a variable, it's value is only available within the block of code where it was declared, and if it's declared in a loop, then it gets garbage collected and then re-instantiated every loop through. BUT Flex 3.0 doesn't work that way.  In Flex, when you instantiate a variable, it's available for the rest of that entire function or class where it was declared, and if it's declared in a loop, then the variable stays the same, but it's value may change.  So, in the code just above, I was passing the exact same value to all the listener functions for all the Text objects! - Whatever value itemToPass has on the last loop execution.  The solution is to put whatever's inside the loop in it's own function.  That way, every time the loop executes, a new function is started and new variables are instantiated.  Here's the code:


for each(textObj:Text in TextObjectList)
{
    //..........
    helperFunction(someValue:int, whatever:int);
}

private function helperFunction(someValue:int, whatever:int):void {
    var itemToPass:Object = someValue * whatever;
    textObject.addEventListener(MouseEvent.MOUSE_OVER, function(event:Event):void {
        var param1 = itemToPass;
        callbackListenerFunction(param1);
        //................
    });
}

So there ya go.  If you ever have an issue like that again, you know where to look for the solution.

Cheers!