July 2006 - Posts

Bug or Behavior?
29 July 06 12:46 AM | adrian | with no comments

When using a CheckedListBox control, you might not want to use the ItemCheck event. Instead, use the standard SelectedIndexChanged event. Here's why:

  1. You are using a CheckedListBox control to simulate multiple selection from a list.
  2. When an item check status is changed, you want to do some operation about it. For example, count the items checked.

If you use the ItemCheck event, you will get the status of items BEFORE the last check operation is commited. For example, you have a two item list box, named “A” and “B”. When you check “A”, the control raise ItemCheck event, changed the check status, and the raise the SelectedIndexChanged.

If you used the ItemCheck event, the CheckedItems property will return 0 items checked (incorrect, or more precise, unwanted). But if you used the SelectedIndexChanged event, the CheckedItems property will return 1 items checked (correct).

Share this post: | | | |
Filed under:
Hello Windows Vista Build 5472
24 July 06 08:14 PM | adrian | with no comments

So in this build, Microsoft have done more artistic improvements, the most notable are the window color for Windows Vista Basic theme. The blue colors are definitely better looking than the previous grey ones. Performance gain in my 512Mb machine is noticably faster. Really, Windows Vista is looking on track for Release Candidate 1 next month (?).

Cheers m8!

Share this post: | | | |
Are You Sure StringBuilder is Faster?
22 July 06 11:50 PM | adrian | 5 comment(s)

Following some of blog posts saying that StringBuilder is faster than String concatenation, I've done some research on my own.

Most often, what you see is thousand strings concatenated at once. I don't deal with those. I deal with under 10 strings concatenated.

When you do small number of concatenation, for example, create a caption for MessageBox, StringBuilder is slower (although by a small margin).

In fact, I found out that for a 12 character string, 6 string concatenations runs as fast as 6 StringBuilder.Appends. I'll post the testing code when I get my own machine online on Monday.

So for now, I'll stick with String concatenation for my MessageBoxes.

Update 25/07: I have posted the test results in an article here.

Share this post: | | | |
Filed under:
WPF vs. UAC
22 July 06 11:24 AM | adrian | with no comments

If you're having a problem running WCF services on top of Windows Vista, especially any access denied exceptions, it might be caused by UAC blocking the operation. UAC turns a user from Administrators group to a standard user, unless you use the built-in Administrator account (which is nowhere to be found in 5456).

To make an application request UAC permission to elevate to Administrator privileges, you should add a MANIFEST file to the install (or build) directory of the application. A MANIFEST file is an XML file named exactly like the application EXE file plus a .MANIFEST afterwards. For example, if your application EXE is “HelloWorld.exe“, the manifest should be named “HelloWorld.exe.MANIFEST” and be placed on the same directory.

The content of this MANIFEST file is just plain XML, as follows:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator">
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

That MANIFEST file will require the application to be run with Administrator privileges and on Windows Vista machines will display UAC permission dialog.

When developing a Solution, you will also encounter this errors even if you have created the MANIFEST file. This is because by default Visual Studio will run without Administrator privileges. The application you built runs from Visual Studio which means it uses the privileges of Visual Studio. To elevate Visual Studio, just right-click on the shortcut and choose Run as Administrator.

Share this post: | | | |
I'm A Complex Intellectual
21 July 06 05:01 PM | adrian | 2 comment(s)

What are you?

Find out here: http://web.tickle.com/, search for Super IQ Test.

Complex Intellectual means:

You are highly intelligent and talented in two critical areas: math and language. While others may be skilled at one, you are exceptional at both. Your ability to understand theoretical or abstract information and your attention to detail only make your mathematical and linguistic skills stronger. You are a highly conceptual, complex thinker.

Because of your numerous intellectual abilities, you probably rarely come across something you're not good at. You are a quick study and so have a tendency to look for and find the deeper meaning in things. You might intellectualize a situation or muse about its layers of complexity, making grand-scale associations. While others are relieved to have tangible, concrete information to work with, you may find yourself easily bored and so you seek more intellectual content.

Share this post: | | | |
ByVal vs. ByRef (and also Value Type vs. Reference Type)
17 July 06 07:51 PM | adrian | 2 comment(s)

There are different behaviours of passing a parameter using ByVal and ByRef between Value Type and Reference Type.

For Value Type (most primitives and Structure objects):

  • ByVal copies the value of the parameter. Changes will not affect original object.
  • ByRef uses the value of the parameter. Changes will affect original object.

For Reference Type (Class objects):

  • ByVal copies the pointer to the value of the parameter. Changes will affect the original object. Unless you changed the reference of the object (e.g.: assigning a different object to the parameter, setting the parameter to Nothing)
  • ByRef uses the pointer to the value of the parameter. Changes will affect the original object, including reference changes.

Now, things get interesting when you're assigning a local variable to the referenced object (a.k.a. doing operation with the parameter outside the original method call). It seems that when you do that, the local variable copied the reference to the referenced object (just like ByVal). So when you modify the value of local variable, the changes will affect the original object, but reference changes will not.

Is it any way possible to keep references even outside the method call?

Share this post: | | | |
Filed under:
Office Compatibility Pack
14 July 06 12:20 PM | adrian | with no comments

If you're using Microsoft Office Professional 2007 and having problem with interoperability with older version of Offices (2003 and XP), you should try downloading the compatibility pack here: http://www.microsoft.com/office/preview/beta/converter.mspx.

Available for Word, Excel, and Powerpoint only.

Finally I wouldn't have to convert my docx'es to doc.

Share this post: | | | |
Hello Windows Vista Build 5456
10 July 06 09:25 PM | adrian | 1 comment(s)

I've just reinstalled my Windows Vista to build 5456 (June CTP). This version boasts many features such as IE7 Beta 3, .NET Framework 3.0 (was WinFX), and a more polished User Interface.

I have activated the installation using my build 5384 (Beta 2) cd-key, and everything works like magic!

Looking forward to see what's new here!

BTW, installation runs for a perfect 30mins on my system.

23:27 Update: the interface is awesome! But I suffer significant performance hit when compared to 5384. I think this is largely because of Beta status is more important. All devices work flawlessly except for the audio (driver problem) and modem (also driver problem, but worse, because no driver available). A word of advice, if you're using 5384 and experience unwanted slowness, you shouldn't upgraded to 5456.

23:59 Update: it seems that UAC is hitting the performance. I'm currently experimenting with UAC on and off. Now if someone can find me that audio driver...

00:54 Update: UAC seems fine, not significant performance hit when active. So the culprit is still the audio driver. Now I have two bugs; intro music is played twice (one for logging in to the logon screen, one for the actual logon), and some of the system strings like “Calendar” and “Communication” from search conditions even to “Windows Media Player” toolbar name is messed up towards something like the attached picture. Where do I connect with Microsoft about Windows Vista? It's not in the Microsoft Connect web site.

Final verdict: use it.

12/07/06 Update: I've found a workaround on the audio glitches. For you guys running Intel D865PERL onboard audio, run Winamp on the background playing that llama stuff indefinitely. Media Player and every other application runs perfect. I'm using WinXP driver, but going to try the driver from WU.

Share this post: | | | |
CollectionBase vs. ArrayList
10 July 06 12:26 AM | adrian | 2 comment(s)

 Or in Generic realms, Collection<T> vs. List<T>.

What's the big deal between the two of them, we'll see:

Comparison

CollectionBase

ArrayList

Implemented Interfaces

ICollection, IEnumerable, IList

ICollection, IEnumerable, IList

Number of Members

18; 5 public, 13 protected

58; all public

Intended Usage

As a base class for extension

Ready-to-use

Extra notes: CollectionBase was widely used pre-Generic for it's strong typing capabilities. ArrayList doesn't have this. But since Generic, List<T> is strong typable, too.

Conclusion: if you're looking for a ready-to-use IList implementation, use ArrayList (or List<T>), and if you're going to extend IList, use CollectionBase.

Anyone up for a speed comparison challenge?

Share this post: | | | |
Filed under:
Connect with Microsoft
07 July 06 06:47 PM | adrian | with no comments

Product Feedback Center a.k.a. Ladybug is now Microsoft Connect.

In the past, I cannot remember exactly what is the web address of PFC, but now they moved it to something easier to remember: http://connect.microsoft.com.

Start evaluating those betas, please... :D

Share this post: | | | |
... and All Ends Here
01 July 06 08:51 PM | adrian | with no comments

On my Public Box.net folder.

What's Public Box.net folder? It's a file hosting service provided by www.Box.net (they have opened their API for usage in other applications, too bad it uses raw XML and not Web Services).

I have and will put all my stuff here (instead of the now defunct adrian.godong.or.id).

Here's the link: http://www.box.net/public/ei7g0k7nv5.

All files are my copyright, feel free to use and distribute as long as no modification is made.

Share this post: | | | |