Archive for the ‘Software Development’ Category
Posted by jpluimers on 2013/04/02

IGrouping interface diagram (click to enlarge)
One of the things most people find hard to use in LINQ is GroupBy or the LINQ expression group … by (they are mostly equivalent).
When starting to use that, I was also confused, mainly because of two reasons:
- GroupBy returns a IGrouping<TKey, TElement> generic interface, but the classes that implement it are internal and not visble from outside the BCL (although you could artificially create your own).
This interface extends the IEnumerable<TElement> in a full “is a” fashion adding a Key member.
This has two consequences:
- Because it is a “is a” extension of the IEnumerable<TElement>, you can use foreach to enumerate the
TElement members for the current group inside the grouping.
No need to search for a Value that has the Elements, as the Group is the Elements.
- The Key member is indeed the current instance of what you are grouping over. Which means that Count<TElement>, are for the current group in the grouping.
- The LINQ expression syntax for grouping on multiple columns is not straightforward:
- Grouping on multiple columns uses a bit different syntax than you are used from SQL.
(Another difference is that SQL returns a set, but groups are IEnumerable)
- You also need to be a bit careful to make sure the group keys are indeed distinct.
Most people don’t see the IGrouping<TKey, TElement> because they use the var keyword to implicitly the LINQ result.
Often – when using any anonymous type – var is the only way of using that result.
That is fine, but has the consequence that it hides the actual type, which – when not anonymous – is a good way of seeing what happens behind the scenes.
David Klein gave an example for the multi column grouping and also shows that if you use LINQPad, you can actually see the IGrouping<TKey, TElement> in action.
Mike Taulty skipped the Group By Syntax for Grouping on Multiple Columns in his Grouping in LINQ is weird (IGrouping is your friend). So my examples include that.
Note that I don’t cover all the LINQ group by stuff, here, for instance, I skipped the into part.
There are some nice examples on MSDN covering exactly that both using Method based and Expression based LINQ.
The examples are based on these two classes, similar to what Mike did. Read the rest of this entry »
Posted in .NET, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 3.0, C# 4.0, C# 5.0, Development, LINQ, Software Development | Leave a Comment »
Posted by jpluimers on 2013/03/29
Als je postcode “1060 NP” invult bij aansluiting en “1170 AB” bij facturatie, dan krijg je deze onterechte foutmeldingen:
- Organisatie postcode is ongeldig
- Facturatie gegevens postcode is ongeldig
Beetje vreemd, want al sinds de introductie van postcodes in Nederland in 1978 zit in een postcode 1 spatie, en tussen de postcode en de woonplaats 2 spaties.
Ook trema‘s gaan mis: bij postcode 1060 NP hoort de straat Pyreneeën in Amsterdam, maar bij Heldenvan.nu wordt het deze Mojibake:
Read the rest of this entry »
Posted in Development, Encoding, Mojibake, Opinions, Power User, Software Development, Unicode | Leave a Comment »
Posted by jpluimers on 2013/03/28
There are a couple of very interesting libraries and ideas every Delphi developer should take a look at.
The list is far from complete, but should give you a good overview on what more recent Delphi language additions like attributes, generics, helpers, overloading, are capable of.
–jeroen
Posted in Delphi, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Development, Software Development | 3 Comments »
Posted by jpluimers on 2013/03/27
I was amazed that this is still usable:
You can even run VMware Fusion 4 full screen at 2880×1800, but I prefer to have the Mac Desktop and Dock to be visible. I didn’t have any of the VMware Fusion 4 issues mentioned here.
So the only thing you need VMware Fusion 5 for is Windows 8 support.
You need SwitchResX to get the Retina MacBook to use 2880×1800 at all (otherwise you get 1920×1200 at 1.5 scale factor, which is also a 16:10 display ratio).
It really runs 5+ hours on one battery charge, which is much longer than my ThinkPad W701.
All in all, I’m very happy with this setup.
--jeroen
PS:
via: Screen Shot 2013-03-27 at 19.55.39 | Flickr – Photo Sharing!.
Click on the image or here for full size image.

Posted in Apple, Delphi, Delphi XE3, Development, Mac, Mac OS X / OS X / MacOS, MacBook, MacBook Retina, OS X 10.8 Mountain Lion, Power User, Software Development | 7 Comments »
Posted by jpluimers on 2013/03/27
As I wrote before, I’m with the [WayBack] Delphi with haters camp, and this is why:
Using the [WayBack] with statement in Delphi makes your code less future proof.
Originally, the with statement in Pascal was argumented in part of allowing compiler optimisations:
PASCAL User Manual and Report – Kathleen Jensen, Niklaus Wirth – Google Books
The with clause effectively opens the scope containing field identifiers of the specified record variable, so that the field identifiers may occur as variable identifiers. (Thereby providing an opportunity for the compiler to optimize the qualified statement.)
Screenshots of this 1975 book are below the fold.
The Delphi (actually even before that Turbo Pascal compiler) has no measurable difference between with and non-with code.
The debugger however, still does not support with, and there are other drawbacks of which one is below.
The below code example is just one of many. I show it because I recently bumped into doing some long overdue code porting to Delphi XE3.
Since I’ve been bitten by using with a couple of times before, it didn’t take me long to find the cause.
Example code where FIConData is of type NOTIFYICONDATAW that used to compile fine:
with FIconData do
begin
cbSize := SizeOf(FIconData);
Wnd := Self.Handle;
uID := $DEDB;
uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
hIcon := Application.Icon.Handle;
uCallbackMessage := WM_CAS400NTIcon;
StrCopy(szTip, PChar(Caption));
end;
Well, as of Compiler Version 20, it doesn’t compile any more. Read the rest of this entry »
Posted in Borland Pascal, Conference Topics, Conferences, Delphi, Delphi 1, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi XE, Delphi XE2, Delphi XE3, Development, Event, Pascal, Software Development, Turbo Pascal, With statement | 32 Comments »
Posted by jpluimers on 2013/03/26
While porting a library from Delphi 2006 to Delphi XE2.
The really cool thing is that the Windows Event Log contains details of what I did wrong (:
–jeroen
Posted in Delphi, Delphi XE2, Development, MQ Message Queueing/Queuing, Software Development, WebSphere MQ | Leave a Comment »
Posted by jpluimers on 2013/03/22
After installing the WebSphere MQ 7.x client software, you must reboot.
Otherwise the directory where mqic.dll resides doesn’t get added to the system path.
I was bitten by this with an unattended installation at a client where they forgot to have the system to reboot.
–jeroen
Posted in Development, MQ Message Queueing/Queuing, Power User, Software Development, WebSphere MQ, Windows | Leave a Comment »
Posted by jpluimers on 2013/03/21
Sometimes, Delphi XE2 gets confused after converting an old Delphi project because the Unit scope names are not correct. When creating a new Delphi XE2 application, the Unit scope names are as follows:
- System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell
This means that if you don’t prepend a unit with a Unit scope prefix, Delphi will automatically try the list above. The thing is: when importing a Delphi project from an old Delphi version, the Unit scope names are somehow “guessed”, and not always complete:
- System;Xml;Data;Datasnap;Web;Soap;Winapi
This means it cannot resolve the right name for the VCL units like Controls or Forms, and you get a nice compiler error: But with the default, it cannot resolve the Windows and other units in the Winapi scope. So the list I normally use is one of these:
- System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;Winapi;System.Win
- System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;Winapi;System.Win;Bde
(Yes, some apps still store Paradox data locally and use the BDE)
–jeroen
Posted in Delphi, Delphi XE2, Delphi XE3, Development, Software Development | 2 Comments »
Posted by jpluimers on 2013/03/20
Fijne foutmelding:
Uw formulier voldoet niet aan de volgende controles:
!
U heeft geen correct telefoonnummer ingevoerd. Een telefoonnummer moet beginnen met een 0 of + , bestaat uit minimaal 10 cijfers en mag geen leestekens bevatten
•
U heeft geen correct telefoonnummer ingevoerd. Een telefoonnummer moet beginnen met een 0 of + , bestaat uit minimaal 10 cijfers en mag geen leestekens bevatten
Inderdaad twee velden: telefoon en mobiel.
Noem ze dan niet beide “telefoonnummer!”.
En hou je gewoon aan de ITU-T E.123 standaard waar spaties, haakjes en plus gewoon zijn toegestaan.
Het vervolg is nog meer bizar:
Let op: een aantal gegevens kunt u niet meer wijzigen nadat ze zijn opgeslagen.
Zijn uw gegevens correct ingevuld?
Uiteraard staat nergens aangegeven WELKE gegevens niet meer te wijzigen zijn.
Stel je voor!
–jeroen
via: eLoket (Profiel).
Posted in Development, Software Development, Usability, User Experience (ux) | Leave a Comment »
Posted by jpluimers on 2013/03/20
I recently had an error like this when building with packages:
[DCC Error] E2201 Need imported data reference ($G) to access 'VarCopyProc' from unit 'SynCommons'
It was a bit hard to find good information about this error, mainly because of two reasons:
- the documentation on E2201 Need imported data reference ($G) to access ‘%s’ from unit ‘%s’ isn’t very well written
- [dcc error] e2201 need imported data reference ($g) to access ‘varcopyproc’ from unit – Google Search doesn’t yield very good answers
Finally, it was the FastMM and D2007 – Delphi Language BASM – BorlandTalk.com thread pointing me to Hallvard’s Blog: Hack#13: Access globals faster ($ImportedData).
That explained the error was caused by:
- VarCopyProc being a variable in one package
- VarCopyProc access being needed from the package that failed to compile
- Not having
{$G+} or {$IMPORTEDDATA ON} in the failing package would prevent that access
Somehow that does not work for all cases. Apparently, the VarCopyProc isn’t exported from the Delphi RTL as that package is compiled in the $G- state.
So I had to add the USEPACKAGES define to the conditional defines list, which forces the SynCommons to use the standard version of the RecordCopy method in stead of a highly optimized one that calls VarCopyProc.
–jeroen
Posted in Delphi, Delphi XE2, Delphi XE3, Development, Software Development | 2 Comments »