From: "Earl F. Glynn" Subject: Re: How to set Canvas.Pen to have a SQUARE Endcap Date: Thursday, March 08, 2001 3:22 PM Hi, Ed: "Ed Kasanjian" wrote in message news:986ar8$6l97@bornews.inprise.com... > Thanks, this works great. I noticed that you are not deleting this pen > object. Why is this? I will need to call ExCreatePen several times because > I am drawing with different widths. I assume that I should be calling > DeleteObject(Canvas.Pen.Handle) before creating a new one? I took a look at the Delphi source in the graphics.pas unit. When you assign a TPen.Handle, the SetHandle method is called, which then calls a SetData method. The TPen.SetData calls the PenManager.ChangeResource. The TResourceMananger.ChangeResource calls a FreeResource method. The TResourceManager.FreeResource seems to be calling a DeleteObject. If this is correct,then I don't think an explicit DeleteObject is needed. Normally, VCL components take care of this for you but when you call Windows API calls yourself, then a DeleteObject would normally be needed. I think this is a case when the VCL takes care of everything automatically. Since TComboBox.OnDraw is using the canvas of the TComboxBox control, I assumed (and still do) that Delphi takes care of any DeleteObject that might be needed here with the TPen associated with the TComboBox.Canvas. But, of course, it could never hurt to run an experiment to do this a few thousand times to make sure there is no resource leak. -- efg efg2@efg2.com Earl F. Glynn, Overland Park, KS USA efg's Computer Lab: http://www.efg2.com/Lab Mirror: http://homepages.borland.com/efg2lab/Default.htm