Serge's Technology View

Talk about Technologies, Software Architecture and Management

Archive for August, 2008

TIPS: Draw Image From TImageList

This question is coming back and again.

I have a TImage in many form which shows the status of the item. It requires status image being changed when it is changed. I do not want to use several instances of the TImage on the form. Instead I would like to use TImageList to store and share them.

Yes, you can. But there are some quirks you have to consider when doing so.

Let’s say you have state images and you have to draw a different one based on the state.

Let’s say you have placed Image list and an Image on your form and populated the list with few state images

var
  MyImageList: TImageList;
  MyImage: TImage;

Canvas

That is probably the easiest case. Lets draw an image on canvas of some control (OwnerDraw situation) and also center it. X, Y are top left corner of the future image and Width is a width of the rectangle we want to center image in.
MyImageIndex is an index of the image in the Image List.

MyImageList.Draw(Canvas, X + Width div 2 - MyImageList.Width div 2, Y, MyImageIndex, dsNormal, itImage);

TImage

Being a little bit more complex, it does require some extra code.

// Make sure that any prior state is cleared.
// If you do not do that with transparency enabled, you would see
// images on top of each other
MyImage.Picture.Bitmap := nil;
// Make sure that transparency pixel in the image is taken
// in consideration
MyImage.Picture.Bitmap.TransparentMode := tmFixed;
MyImage.Picture.Bitmap.TransparentColor := clWhite;
// Load image from the Image list into TImage
MyImageList.GetBitmap(MyImageIndex, MyImage.Picture.Bitmap);

Can I use resource file?

Would you like to keep images in the file?

// Store it once
WriteComponentResFile('MyImageList.dat', MyImageList);
// Use it later
ReadComponentResFile('MyImageList.dat', MyImageList);

Not that difficult after all.

Delphi, methods and default values. Convenience or contract enforcement?

Delphi, methods and default values.

Being somewhat unique in methods declaration for the classes, Delphi requires you to have proper method parameters declaration, but:

  1. You do not have to have any default values for the parameters being propagated into implementation section for the method.
  2. And you do not have to have any parameters being specified in implementation section at all.
  3. If your class implements an interface, then while order and type of parameters remain unchanged for the interface method implemented, compiler would not not even detect it.
  4. When declaring the method and then using code complete feature of the IDE, stub generated would have all parameters but no default values.
  5. Declaration of the parameters could be “optimized” by changing the way they are grouped if they are of the same type. And sync is not enforced between declaration and implementation.

Convenient. Nice. Easy.

Again, it is convenient since it does not force you to propagate your changes between two if you are to change your default values.

Is default value good or evil?

Well, Microsoft saying it is specific to an implementation of the language (C#) and suggests to use overloads instead. Yes, it can be done, but defaults were introduced for a reason. And, in fact, some compilers, even Delphi, would be confused with overloaded declaration if there is a slight chance of mixing two.

(more…)

AT&T service is terrible

Never thought I would say it, but AT&T customer service is terrible.

(I just read Hadi’s blog. Is it a special time of the year when customer support goes South?)

Story:

I have been with AT&T since 2000 when they were SBC. I have had a phone line and DSL for just a little less. I have had several moves, they become AT&T, but I have managed stay out of trouble and haven’t had much to complain about. Good service for the dollar.

Little over two weeks ago  I have decided that I am not actually using a phone service that much (for kids mostly). How about just leave DSL and take advantage of the T-Mobile @home service which is 4 times less (10.99, no limits, free long distance).

OK then. After talking to AT&T customer support I was assured that:

I can have just DSL and it would be converted in no time, “just transfer your phone number and call us back. DSL will be switched on the “dry loop” and you will be OK”. Nice! Great!

Well, not nice and not great! Now fun is began.

I have got my T-mobile router in 2 days and phone number was switched in a week time. As result AT&T automatically turned off my phone, … and DSL “because they sit on the same line and goes together”. OK. so I am calling tech support and asking them to switch me now to a promissed “dry loop”.

(more…)

DS Plug-in System is ready for Delphi 2009

Are you using DS Plug-in system and  wondering if your code would still work in the new version? Then answer is Yes. DSPS has been adjusted where necessary to support a new version of Delphi.

At this time I am actively testing all my components to ensure that everything is done properly.

Delphi 2009 is not yet out so I cannot publish a new version yet but if you are a Tiburon beta tester you want to try a latest release by sending me an email.

Valid XHTML 1.0 Transitional  Valid CSS!