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,860 other subscribers

Archive for the ‘Delphi’ Category

Delphi – more for … in support for TComponent.Components using a class helper

Posted by jpluimers on 2009/05/12

With my blog posting last week on Delphi – class helper to add for … in support for TComponent.Components/ComponentCount  I ‘lied’ a bit. 

What I actually wanted to do was write code like this:

  for Component in Self.ComponentsOfType(TSQLQuery) do
    (Component as TSQLQuery).SQL[1] := FTableName;

This filters the enumeration to only enumerate components that are of type TSQLQuery or descend from type TSQLQuery.

So I wanted to write a ‘richer’ enumerator than just iterating over all components.
The scond part of the lie is that such an enumerator in fact already exists: there is already a TComponent.GetEnumerator method.
Primoz Gabrijelcic’s – web/blog – rightly noted in the comment where he pointed to a similar blog post he wrote for TControls.

Since I wrote this post last week as well, but scheduled to be published right before DelphiLive!, I just added a reference to his comment, site, blog and posting.

TComponent already has a GetEnumerator since Delphi 2006.
But my TComponentEnumerator was meant as a base class to show you how to descend from it.
And that’s what this blog post is about.
Read the rest of this entry »

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

Delphi – class helper to add for … in support for TComponent.Components / ComponentCount

Posted by jpluimers on 2009/05/07

You might have discovered that I’m a fan of Delphi class helpers.

This is another case where I’d like to use the for … in statement: accessing the Components of a TComponent instance.

So I wanted to end up with this:

procedure MyForm.FormCreate(Sender: TObject);
var
  Component: TComponent;
begin
  for Component in Self do
  begin
  // business logic goes here
  end;
end;

Read the rest of this entry »

Posted in Component Development, Delphi, Development | 12 Comments »

Delphi – class helper to get SourceFileName from an EAssertionFailed

Posted by jpluimers on 2009/05/06

In one of our applications, we have a default Config.xml file that is in our source tree, but it can be overridden by a Config.xml file relative to the application’s .EXE file.
So we have a two step process looking for the Config.xml, and we’d like to have the full path to the source file where the sources were build.
It seems the only way to get that, is by looking inside the Message of an EAssertionFailed exception.

So I wrote yet another class helper to get this code to work:
Read the rest of this entry »

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

Delphi – Michael Justin had strange floating point results when his 8087 FPU Control Word got hosed

Posted by jpluimers on 2009/05/06

Two days ago, [Wayback] Michael Justin (who just released version 1.7 of the [Wayback] Habari Active MQ Client components) posted a blog entry about a strange circumstance [Wayback] when 1.99 would not compare equally to 1.99.
He tracked it down to the [Wayback] 8087 (more formally: Intel [Wayback] FPU) Control Word being hosed on his system.

I could not reproduce his particular case, but since I have seen similar issues in the past, I wrote the DUnit test case below which shows you what can happen by manually setting the 8087 Control Word.

The difference between the 8087 Control Word values $1372 (default) and $1272 (failure) is the internal mantissa precision (see the [Wayback] “Art of Assembly Language” and the [Wayback] Intel FPU Control Word documentation on this).
Edit: Found a [Wayback] much more complete description of the bits in the FPU Control word.

It changes from 64 bits to 53 bits, which is enough to make 1.99 not equal to 1.99.

I have seen behaviour like this in the past with some networking stacks in the Turbo Pascal 7 era, with some C++ DLL’s in the Delphi 1-3 era, and some printer drivers in the Delphi 5-7 era.
Let me know in the comments (or using the contact form) where you have bumped into this.

The code below makes use of the Jcl8087 unit which is part of the JCL ([Wayback] JEDI Code Library) at [Wayback] SourceForge.
Add the unit to any DUnit test project you created and observe the results.
Read the rest of this entry »

Posted in 8087, Algorithms, Delphi, Development, Floating point handling, Software Development | 8 Comments »

Delphi / .NET interop – Atozed announced Crosstalk

Posted by jpluimers on 2009/05/06

On 20090504, Atozed announced Crosstalk: a technology that allows native Delphi code to consume .NET assemblies in a really intuitive and transparent way.atozed-logobig-white-bg

The announcement contains a FAQ.

It is a promising technology, not only because it is dead easy to use, but also because it is backed by Atozed: a team of people that have made complex technology like Web Apps easy to use by creating IntraWeb.

Expect demos soon (maybe even at Delphi Live!).
Here is a short example:

Read the rest of this entry »

Posted in .NET, Delphi, Development, Software Development | 3 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 »

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 »