Archive for December, 2009

Custom Variant Wrapper for TDataset - Part 3

Thursday, December 31st, 2009

In Part 2 I explained how to initialize a custom variant’s data structure and how to create a TCustomVariantType descendant to implement the methods required to make the variant useful.  Now I will start to explain which methods need to be implemented, what they do and how they do it.  In this part we will discuss clearing your variant and copying your variant to another variant.


Custom Variant Wrapper for TDataset - Part 2

Thursday, December 31st, 2009

In Part 1 of this series we discussed the data structure needed to hold your custom variant data.  In this article we will discuss the code needed to create an instance of your custom variant.


Custom Variant Wrapper for TDataset - Part 1

Wednesday, December 30th, 2009

This is the first in a series of articles that will attempt to document the process of creating a Delphi custom variant.  In this article I will cover the data structure required to define a custom variant.  Later articles will address the classes and methods that need to be implemented in order for you custom variant to be able to do any useful work.


Custom Variants in Delphi

Wednesday, December 30th, 2009

I was watching one of the CodeRage presentations the other day.  It was the one about domain specific languages by Marco Cantu.  In it he shows how custom variants can be used to implement a domain specific language in Delphi.  While I found the presentation interesting, I didn’t see much benefit to inventing one and using it in the type of programming that I do.  However, I can see a lot of applications for custom variants.

Unfortunately, Marco didn’t go into a lot of detail about exactly how custom variants are implemented.  So I started reading the Delphi Developers Guide.  It covers the necessary material but I found the explanations to be insufficient and I didn’t have the eureka moment that made everything clear enough to start implementing a custom variant.  So I went to the old standby, Google.  I didn’t find much there either.  One fairly length article that I did find basically parroted the Delphi documentation and examples and wasn’t much help either.

Anyway, I took the information that I could find and the VCL source code and dove in.   As a first project, I decided to implement a custom variant wrapper for the TDataset component that would allow me to access the dataset’s field’s values without have to use the excessively wordy and cumbersome dataset.FieldByName(”field_name“).Value syntax.  I wanted to be able to get a field’s value by using the field’s name as a property, like this, datasetVariant.field_name.  Where field_name is the name of the field in the database.

In a series of articles to follow, I am going to try to document my experiences and discoveries in the hope that; (1) it will serve as a memory aid to me if I ever have to do this again and (2) it will help someone else along the road to their own custom variant.  Wish me luck.

Part 1 - Variant Data Structures
Part 2 - Initializing the Variant
Part 3 - Copying and Clearing the Variant
Part 4 - Implementing Dynamic Properties
Part 5 - Casting the Variant to a Different Data Type
Part 6 - Implementing Dynamic Functions and Procedures

Slow Remote Desktop Connections on Vista and Windows 7

Monday, December 21st, 2009

After I got my new, blazing fast Windows 7 workstation I started noticing that some, but not all, of my remote desktop connections were much slower than they were from my old, slow XP workstation.  The remote server would take a long time to respond to mouse clicks and key presses.  I suffered with this for a couple of months before I got fed up enough to start researching the problem.

It turns out that Remote Desktop 6.0, the version that ships with Vista and Windows 7, uses a new operating system feature that allows RDP to automatically tune the TCP/IP receive window size.  Theoretically this is supposed to improve network throughput but apparently Vista and Windows 7 have a problem on certain networks.  Not much of a surprise that a new Windows feature would have problems. :(
Anyway, disabling or restricting the auto tuning feature fixes the slow RDP connection problem.  To disable auto tuning completely, enter the following command on the workstation.  You will need to start an administrator mode command prompt first.

netsh interface tcp set global autotuninglevel=disabled

In some cases, simply restricting the auto tuning feature to a more conservative level might fix the problem.  To make the auto tuning feature more conservative, enter the following command on the workstation.

netsh interface tcp set global autotuninglevel=highlyrestricted

There is an excellent blog post that goes more deeply into the technical details here.