The Wiert Corner – irregular stream of stuff

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

  • My work

  • 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,811 other followers

Archive for October, 2009

XP embedded – .NET Framework 3.0

Posted by jpluimers on 2009/10/27

The “out of the box” .NET 3.0 component in Windows XP Embedded drags way too many required components (like the System Restore Core) into your image.

So most people build their own .NET 3.0 component.

If you get errors like this when you make your own, then you didn’t get your dependencies right.

These are the dependencies for the .NET 3.0 framework:

  • .NET Framework 2.0
  • ASP.NET 2.0

These are the error messages you get when you forget the ASP.NET 2.0 dependency:

Of course I always get all my dependencies right :-)
(yeah right, not this time)

–jeroen

Posted in Development, XP-embedded | Leave a Comment »

Delphi – for … in on enumerated data types

Posted by jpluimers on 2009/10/27

I like enumerated type a lot.
The allow you to perfectly describe what the members of such a type actually mean, much more readable than a bunch of integer constants!

Given an enumerated type like TTraphicLightColors

type
  TTraphicLightColors = (Red, Orange, Green);

I always wondered why  – since the for ... in statement was added to the structured statements part of the Delphi language – it is not possible to use a for … in statement like the this:

</span>
<pre>var
  TraphicLightColor: TTraphicLightColors;
begin
  try
    for TraphicLightColor in TraphicLightColor do
      ShowValueAsTraphicLightColor(Ord(Value));
    // [DCC Error] EnumerationEnumeratorDemoProcedures.dpr(63): E2430 for-in statement cannot operate on collection type 'TTraphicLightColors'
end;

Somehow, for … in expects a collection type.
A request for [WayBack] the for … in do on enumerated types compiler feature is in QC, but it is closed with reason “Won’t do”.

Back in Delphi 2007, I tried working around this by writing a type implementing the GetEnumerator pattern myself, but got [WayBack] Internal Errors when compiling anything but the most basic sample.

Until today, where I found how I could get that most basic sample to work!
It is an example on how you could implement this: it is research, so you decide if you find the result practical enough to use yourself.

Read the rest of this entry »

Posted in Delphi, Development, QC, Software Development | 20 Comments »

Delphi operator overloading: table of operators, names, and some notes on usage and ‘glitches’

Posted by jpluimers on 2009/10/19

Operator overloading is a very nice feature of the Delphi language.
However. the Delphi documentation on Operator overloading is not completely right.

Below is my table of what I found out so far, and some notes.

It is part of my “Nullable types in Delphi” session that I gave on some conferences.
The downloads for that session contain more detailed information.

This is just an abstract to get you going and a try to answer this operator overloading question on Stackoverflow.
Download the full presentation to get more in depth information.

Let me know if you need more information.

Notes

Operator overloading

Add your own “behaviour” to operators

  • Win32: Works only for records, not classes!
  • An operator and the operand(s)
    are being implemented worden by a “class operator”;
    this is a kind of class method with name and argumen(s)

Example:

  • Multiplication X : = A * B;
  • Operator: *
  • Name: Multiply
  • Operands: 2 -> two parameters
type
  TMyRecord = record
    class operator Multiply(A, B: TMyRecord): TMyRecord;
  end;

Documentation is not correct!

Combining the rules of operator and result types, you can do magical things like Dances with XML | Australian Delphi User Group Members.

Do not use Delphi 2006 with operator overloading

Delphi 2007 fixed a number of bugs including this one: Delphi 2006 wont allow const parameters of type record within record method? – Stack Overflow.

Watch the result type of comparison operators!

Tips:

  • Some operators should be overloaded pair-wise
    = and <>
    shl and shr
    < and >=
    > and <=
    dec and inc
    + and –
    / and *
    div and mod
  • Prefer Explicit over Implicit operators
    • Beware of the built-in type coercion (implicit operators)
    • e.g
      • Byte to Integer;
      • Integer to Double;
      • Variants from/to anything!

Table of operators

operator # usage name cagetory *
and 2 R := A and B; BitwiseAnd bit
not 1 R := not A; //BitwiseNot bit glitch: does not exist!
or 2 R := A or B; BitwiseOr bit
xor 2 R := A xor B; BitwiseXor bit
() cast 1 R := TValue(A); Explicit conversion
:= 1 R := A; Implicit conversion
operator # usage name category *
round 1 R := Round(A); Round function
trunc 1 R := Trunc(A); Trunc function
and 2 R := A and B; LogicalAnd logical
not 1 R := not A; LogicalNot logical
or 2 R := A or B; LogicalOr logical
xor 2 R := A xor B; LogicalXor logical
operator # usage name category *
+ 2 R := A + B; Add binary
/ 2 R := A / B; Divide binary
div 2 R := A div B; IntDivide binary
mod 2 R := A mod B; Modulus binary
* 2 R := A * B; Multiply binary
2 R := A – B; Subtract binary
operator # usage name category *
shl 2 R := A shl B; LeftShift binary name is confusing
shr 2 R := A shr B; RightShift binary name is confusing
1 R := -A; Negative binary
+ 1 R := +A; Positive binary
dec 1 Dec(A); Dec self
inc 1 Inc(A); Inc self
operator # usage name category *
= 2 R := A = B; Equal comparison
> 2 R := A > B; GreaterThan comparison
>= 2 R := A >= B; GreaterThanOrEqual comparison
< 2 R := A < B; LessThan comparison
<= 2 R := A <= B; LessThanOrEqual comparison
<> 2 R := A <> B; NotEqual comparison
operator # usage name category *
in 2 R := A in B; In set

–jeroen

Posted in Conferences, Delphi, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Development, Event, Software Development | 6 Comments »

Delphi – list of posts about hidden registry entries

Posted by jpluimers on 2009/10/15

There are quite a few registry tricks that you can perform to influence the Delphi IDE.

If you have any registry settings to share, please let me know by posting a comment below, or filling out the contact form.

This summary will be enhanced over time:

Have fun with them!

–jeroen

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

Delphi – finding the VERxxx define for a particular Delphi version: use JEDI.INC

Posted by jpluimers on 2009/10/15

Edit 20140822 since originally posting, JEDI moved to a GIT repository, so I changed some URLs and added that it is up to date until Delphi XE7.

Finding the correct VERxxx conditional define for a particular Delphi version is asked by a lot of people.

Even the first link in the above search, does not contain the full list!
But: JCL comes to the rescue

The JCL file JEDI.INC usually (read: like 99.999% of the time) is up to that with that information soon.
Currently, it contains all the defines starting with Delphi 1, up to Delphi 2010 XE7.

You can always browse the to JEDI.INC with this link to the sourceforge trunk. link to the GitHub master version.

In fact that file contains a lot more useful defines.
Actually, having the JCL and/or JVCL at hand is a very good practice: it is filled with high quality code that solves a lot of everyday problems.

Note:

VER190 (by some people attributed to the wrong Delphi version) is only used by Delphi 2007 for .NET (Delphi 2007 for Win32 used VER185 by itself and shares VER180 with Delphi 2006 for Win32).

The number 13 (in between Delphi 2009 aka Delphi 12, and Delphi 2010 aka Delphi 14) was never used as a Delphi version number
Since Delphi is mainly developed in the USA, and since a lot people there have Triskaidekaphobia, they showed mercy to those and skipped Delphi 13.

–jeroen

Posted in Delphi, Delphi 1, Delphi 2, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi 8, Delphi x64, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Development, Software Development | 9 Comments »

 
%d bloggers like this: