The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,862 other subscribers

Archive for April, 2009

Jeroen turns 40 today :-)

Posted by jpluimers on 2009/04/29

Being born on April 29, 1969, Jeroen turns 40 today.

Posted in About | Leave a Comment »

WordPress – bug in sourcecode shortcode: backslash followed by zero is removed

Posted by jpluimers on 2009/04/28

See this support post:
http://en.forums.wordpress.com/topic/bug-within-sourcecode-backslash-followed-by-zero-is-removed

It seems even that post is affected by the same bug.

–jeroen

Posted in Development, WordPress | Tagged: | 2 Comments »

.NET/C# – an easier foreach for enums using generic methods

Posted by jpluimers on 2009/04/28

I like enums. Maybe because of my Turbo Pascal and Delphi background. They are descriptive. Makes code easier to read.

        public enum TrafficLightColors
        {
            Red,
            Yellow,
            Green
        }

But using them in C# foreach loops is a bit of a pain, not so much in the loop itself, but more in getting the list of values to loop over.
Read the rest of this entry »

Posted in .NET, C# 2.0, Delphi, Development, Software Development | Leave a Comment »

Answered @ stackoverflow – on virtual constructors called through class references in Delphi

Posted by jpluimers on 2009/04/27

I just tried to elaborate on an answer to a question from Michael Justin on stackoverflow.
(yes, that’s the author of some message broker clients like the Habari ActiveMQ client that allows Delphi applications to talk to the Apache ActiveMQ message queueing broker).

His question is on virtual constructors and class reference: How can I detect if a Delphi class has a virtual constructor?
The combination of class references and virtual constructors is one of the fundaments of how Delphi became Delphi; in simple terms:

  • class references allow you to register components on the component palette in Delphi
  • virtual constructors allows the designer to construct  the instances of those components at design time

That’s why I think it is important to describe the distinction between virtual constructors and regular non-virtual constructors in the answer below (which is a copy of the answer I posted to stackoverflow)

Read the rest of this entry »

Posted in Delphi, Development, Pingback, Software Development, Stackoverflow | Leave a Comment »

Delphi – bizarre use of class helpers to circumvent ‘with’

Posted by jpluimers on 2009/04/27

Quite a while ago, a co-worker asked how to get tot the Instance variable when using a with statement like this:

function TMyForm.ExecuteForm(FormClass: TFormClass): Integer;
begin
  with FormClass.Create(self) do
    try
      Result := ShowModal;
    finally
      Free;
    end;
end;

So I wrote the blog entry below when I started my blog last week, and set the published date to somewhere early May, a week that will be really busy.
Then I found out about the Stackoverflow question Reference object instance created using “with” in Delphi followed by the answer by user ‘Alexander‘ (a really smart Russian guy).
Enough coincidence to publish the blog article earlier than scheduled :-) 

Before I explain why I really hate ‘with’, lets show what my co-worker wanted, and my solution: Read the rest of this entry »

Posted in Delphi, Development, Pingback, Software Development, Stackoverflow | 2 Comments »

.NET/C# – Issue with FileStream on network with transfers larger than 64 megabyte

Posted by jpluimers on 2009/04/27

Quite a while ago (2006!), I bumped into an issue when copying large chuncks of data to a network.

I posted it to Google, mentioned that breaking up the data in smaller blocks worked, but never had the time to post the solution.

So here it is :-)

First the problem:

The old code consistently fails when:

  • the FileStream is on a network
  • and the MemoryStream is 64 megabytes or larger

The old code succeeds when:

  • the MemoryStream is smaller than 64 megabytes
  • or the FileStream is not on a network

An example of the exception message you get upon failure:

System.IO.IOException: Insufficient system resources exist to complete the requested service.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.FileStream.Write(Byte[] array, Int32 offset, Int32 count)
   at System.IO.BufferedStream.Write(Byte[] array, Int32 offset, Int32 count)
...

Then the old code:

        public static void WriteMemoryStreamToFile(string filename, MemoryStream memory)
        {
            using (Stream
                file = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite),
                fileBuffer = new BufferedStream(file)
            )
            {
                byte[] memoryBuffer = memory.GetBuffer();
                int memoryLength = (int)memory.Length;
                fileBuffer.Write(memoryBuffer, 0, memoryLength); //##jpl: drawback: works only up to 2 gigabyte!
                fileBuffer.Close();
                file.Close();
            }
        }

Note that the old code already has a limitation of 2 gigabyte, back then this was not an issue (in 2006 there were not that many people having more than 2 gigabytes of memory, now that is a different story).

Read the rest of this entry »

Posted in .NET, C#, Development | 6 Comments »

Performed @ Bloemencorso Bollenstreek 2009 (Flowercorso 2009)

Posted by jpluimers on 2009/04/26

Yesterday, the Senior Band of Adest Musica (the marching band where next year I hope to celebrate my 30th membership anniversary) participated in the 62nd edition of the Flower Parade in “de Bollenstreek“.
(Actually this is should formally be called “de Duin- and Bollenstreek”, as the complete “Bollenstreek” also includes two more regions in North Holland, and a few smaller areas on the South Holland islands).

New truck for Adest Musica with "the Musketeer" theme for their WMC 2009 show

New truck for Adest Musica with “the Musketeer” theme for their WMC 2009 show

The Senior Band has brass and percussion (no woodwinds, though the Stage Band orchestra part of Adest Musica has them).

It will compete during the World Music Contest 2009 in Kerkrade, so this was a great opportunity to show the public our new marches that we are going to play at the WMC: “Moving Force” and “to Fight and Win” (sorry Dutch link only) as well as the introductory march to the show “Up is Down” that bridges our previous show “Legends of the Seas” to the new show “the Musketeer”.

At the flower corso, also our new truck themed “the Musketeer” as well, click on the picture on the right to see an enlarged version.

A few videos of the Flower Parade with us performing are already on-line:

  1. Adest Musica Sassenheim – Bloemencorso 2009 – WMC / The  – 10 minute compilation
  2. Adest Musica Sassenheim – Bloemencorso 2009 – 2.5 minute compilation showing “Up is Down”
  3. Adest Musica Sassenheim – Bloemencorso 25 april 2009 – very short fragment, but the only one showing my wife (light blue shirt) and brother (khaki jacket) having back-packs with fresh water!

So now you know what I do to balance all the keyboard work I do :-)

–jeroen

Posted in About, Adest Musica, Personal | Leave a Comment »

Conferences, seminars and other public appearances « The Wiert Corner

Posted by jpluimers on 2009/04/26

On request, I have started to maintain a page about the events I have spoken at or will be speaking at.

The page serves as a central landing spot for people wanting to download materials of past appearances, or wanting to meet me in person on future appearances.

Currently, it contains

I will extend it with more downloads and more events over time (and blog about it when it gets extended).

Drop me a message at the contact form when you need more of the past downloads (I have been speaking at conferencs since 1995, so there is quite a lot of material <g>)

Posted in About, Conferences, Delphi, Development, Event, PowerDay | Leave a Comment »

Spoken @ Delphi 2009 interactive briefing on April 1st, 2009 (no joke!) on migrating from Delphi 2007 to Delphi 2009, and from Delphi 5 to Delphi 2006/2007

Posted by jpluimers on 2009/04/26

Oosterkamp training | consultancy (the company that I used to co-own before partnering in better office benelux), together with Barnsten (the CodeGear / Embarcadero representative in the benelux) organized a Delphi 2009 interactive briefing on the evening of April 1st, 2009.

That wasn’t a joke, and we had good attendance with interesting questions.

I did a session on migrating to the most current Delphi version.

Read the rest of this entry »

Posted in Briefing, Delphi, Development, Event, Software Development | 1 Comment »

.NET/C# – obtaining information through WMI

Posted by jpluimers on 2009/04/25

WMI (Windows Management Instrumentation) is a way of obtaining information from your PC that otherwise might be hard to find.
WMI is based on Common Information Model (CIM), so you’ll see an example of that too.

There is one drawback: for a lot of the WMI, you need to have enough privileges (like: being an admin, which none of you should be, right?).
So beware!

You can use WMI from C#, but you have to generate the C# classes for the WMI classes first.

I’ll show some examples for WMI Win32 classes, as I needed some of those classes recently myself.

Before I forget:
in order to browse through the WMI Win32 object instances, you can download this nifty WMI Administrative Tools toolset from the Microsoft MSDN site. Note that these are from 2002, and they only reliably work from within Internet Explorer.
Read the rest of this entry »

Posted in .NET, C#, Development, Software Development, Visual Studio and tools | Leave a Comment »