Posted 7 years ago on 5/3/2006 and updated 1/20/2009
Take Away:
use of Sender under Delphi for .NET
Let's say you have a DropDownList object on your ASP.NET form, and you want to access the Items property without actually naming the object. You can do this the same way you would with a Win32 application under Delphi.
The following code will capture the currently selected string each time it changes in the drop-down (note that, under ASP.NET, this only occurs when some reason exists for a "trip to the server", and the user choosing a new drop-down value is NOT such a reason (at least, not when runat="server" is set)).
This assumes the default naming of DropDownList1 for the object:
procedure TWebForm1.DropDownList1_SelectedIndexChanged(sender: System.Object; e: System.EventArgs); begin sItemString := DropDownList(sender).Items.Item[DropDownList(sender).SelectedIndex].ToString; end;
(we are simply casting the sender argument as a DropDownList, since sender is the object that caused the event, and it's a DropDownList, but we need to "upcast" from Object in order to access the DropDownList properties).
This makes this code portable to other DropDownLists, regardless of their naming or scoping.