Sender is the component calling your event handler. For example it's
not uncommon to use the same method for more than one button click
event when they perform very similar tasks. You then write code like:
if (Sender as TButton).Name = 'btnPrint' then
begin
// do stuff
end
else (Sender as TButton).Name = 'btnTestPrint' then
begin
// do slightly different stuff
end;
// do stuff common to both print buttons
You need to cast the Sender object to whatever type you expect it to
be because it is of type TObject which doesn't have properties like
Canvas or Handle. So if you're using Sender instead of StringGrid1
you'll have some code like: (Sender as TStringGrid).Canvas.Handle
Hope this helps,
Dave.
Dave Murray
Glasgow, UK
--- In delphi-en%40yahoogroups.com">delphi-en
yahoogroups.com, "Nesler, Thomas J" <tnesler
...> wrote:
>
> Hi David!
>
> Thanks for the tip...However I can't get it to work...:-(
>
> Can you suggest how I would incorporate Sender into my code?
>
> Thanks in advance!
>
> Tom Nesler
>
>
> -----Original Message-----
> From: delphi-en%40yahoogroups.com">delphi-en
yahoogroups.com [mailto: delphi-en%40yahoogroups.com">delphi-en
yahoogroups.com] On
> Behalf Of David Smith
> Sent: Wednesday, March 19, 2008 10:45 AM
> To: delphi-en%40yahoogroups.com">delphi-en
yahoogroups.com
> Subject: RE: [delphi-en] Working with ExtTextOut
>
>
> You should use Sender instead of StringGrid1. That's what it's for.
>
> "Nesler, Thomas J" <tnesler
...> wrote:
> Hi Rob!
>
> Your observation combined with Theo's code cleanup fixed the problem.
>
> Here is the final code for those who may need to do this in the future:
>
> // *** This procedure Centers all cells in the grid ****
>
> procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow:
> Integer;
> Rect: TRect; State: TGridDrawState);
> var
> Text : string;
> Begin
> Text := StringGrid1.Cells[Acol,ARow];
> ExtTextOut(StringGrid1.Canvas.Handle,
> Rect.Left + (Rect.Right - Rect.Left -
> StringGrid1.Canvas.TextWidth(Text)) div 2,
> Rect.Top + 2,
> ETO_OPAQUE or ETO_CLIPPED,
>
Rect,
> PChar(Text),
> Length(Text),
> nil);
> end;
>
> //************** End of Code ***********
>
> Thanks for your input, Rob
>
> Tom Nesler
> Live long!... Code Well!... and Prosper!... V
>
> -----Original Message-----
> From: delphi-en%40yahoogroups.com">delphi-en
yahoogroups.com [mailto: delphi-en%40yahoogroups.com">delphi-en
yahoogroups.com] On
> Behalf Of Rob Kennedy
> Sent: Tuesday, March 18, 2008 8:07 PM
> To: delphi-en%40yahoogroups.com">delphi-en
yahoogroups.com
> Subject: Re: [delphi-en] Working with ExtTextOut
>
> ....
> > ExtTextOut(Handle,
> > // HDC
> > Rect.Left + (Rect.Right - Rect.Left -
> > TextWidth(Text)) div 2, // X Position
> > Top + DY,
>
> Do you mean Rect.Top?
>
>
>
>
>
>
> ---------------------------------
> Never miss a thing. Make Yahoo your homepage.
>
> [Non-text portions of this message have been removed]
>
>
> ------------------------------------
>
> -----------------------------------------------------
> Home page: http://groups.yahoo.com/group/delphi-en/
> To unsubscribe: delphi-en-unsubscribe
...! Groups Links
>
.