There are a number of
‘tools’ available to create
ASP.NET code. Having created a number of ASP.NET
‘applications’ in an environment other than
Delphi® (Don’t interpret this wrong, Delphi® is my passion and always my FIRST choice. Unfortunately, limitations and guidelines can often restrict the tools used.) and having a little time available I decided to create an
ASP.NET web application with my reaffirmed passion
BDS 2006 (a.k.a. Delphi 10).
Question: What could I throw together quick that could serve as something useful? Answer: I do like the ConvertIt demo that shipped with both Delphi® 2005 and BDS 2006.
I fired up ‘Delphi for the Microsoft .NET Framework’ (The ability to selectively load personalities is one thing I am very fond of) and decided to get stared on a new ASP.NET Web Application. On a form I dropped a ComboBox (cbxConversions), TextBox (txtValue), and two ListBoxes (lstFrom and lstTo).

To ensure the ‘proper’ flow of my design I set the AutoPostBack property to True for cbxConversions, lstFrom and txtValue. Now for the code (the events coincide with the defaults for the controls):
unit WebForm1;
interface
uses
System.Collections, System.ComponentModel,
System.Data, System.Drawing, System.Web, System.Web.SessionState,
System.Web.UI, System.Web.UI.WebControls, System.Web.UI.HtmlControls,
ConvUtils, Borland.Vcl.Classes, Borland.Vcl.StdConvs,Borland.Vcl.StrUtils,
Borland.Vcl.SysUtils;
type
TWebForm1 = class(System.Web.UI.Page)
{$REGION 'Designer Managed Code'}
strict private
procedure InitializeComponent;
procedure cbxConversions_SelectedIndexChanged(sender: System.Object; e: System.EventArgs);
procedure lbFrom_SelectedIndexChanged(sender: System.Object; e: System.EventArgs);
procedure txtValue_TextChanged(sender: System.Object; e: System.EventArgs);
{$ENDREGION}
strict private
procedure Page_Load(sender: System.Object; e: System.EventArgs);
strict protected
lstFrom: System.Web.UI.WebControls.ListBox;
lstTo: System.Web.UI.WebControls.ListBox;
cbxConversions: System.Web.UI.WebControls.DropDownList;
txtValue: System.Web.UI.WebControls.TextBox;
procedure OnInit(e: EventArgs); override;
end;
implementation
{$REGION 'Designer Managed Code'}
///
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
///
procedure TWebForm1.InitializeComponent;
begin
Include(Self.lstFrom.SelectedIndexChanged, Self.lbFrom_SelectedIndexChanged);
Include(Self.cbxConversions.SelectedIndexChanged, Self.cbxConversions_SelectedIndexChanged);
Include(Self.txtValue.TextChanged, Self.txtValue_TextChanged);
Include(Self.Load, Self.Page_Load);
end;
{$ENDREGION}
procedure TWebForm1.Page_Load(sender: System.Object; e: System.EventArgs);
var
LFamilies: TConvFamilyArray;
i: integer;
begin
if cbxConversions.Items.Count <= 0 then
begin
GetConvFamilies(LFamilies);
for I := 0 to Length(LFamilies) - 1 do
cbxConversions.Items.Add(ConvFamilyToDescription(LFamilies[I]));
end;
end;
procedure TWebForm1.OnInit(e: EventArgs);
begin
//
// Required for Designer support
//
InitializeComponent;
inherited OnInit(e);
end;
procedure TWebForm1.txtValue_TextChanged(sender: System.Object; e: System.EventArgs);
begin
lbFrom_SelectedIndexChanged(sender,e);
end;
procedure TWebForm1.lbFrom_SelectedIndexChanged(sender: System.Object; e: System.EventArgs);
var
LValue: Double;
LBaseType, LTestType: TConvType;
I: Integer;
begin
lstTo.Items.Clear;
try
LValue := StrToFloatDef(txtValue.Text, 0);
if lstFrom.SelectedIndex <> -1 then
begin
DescriptionToConvType(
lstFrom.Items.Item[lstFrom.SelectedIndex].Text,
LBaseType
);
for I := 0 to lstFrom.Items.Count - 1 do
begin
DescriptionToConvType(lstFrom.Items.Item[i].Text, LTestType);
lstTo.Items.Add(Format('%n %s', [Convert(LValue, LBaseType, LTestType),
ConvTypeToDescription(LTestType)]));
end;
end;
except
lstTo.Items.Add('Cannot parse value');
end;
end;
procedure TWebForm1.cbxConversions_SelectedIndexChanged(sender: System.Object; e: System.EventArgs);
var
LFamily: TConvFamily;
LTypes: TConvTypeArray;
I: Integer;
begin
lstFrom.Items.Clear;
lstTo.Items.Clear;
if DescriptionToConvFamily(
cbxConversions.Items[cbxConversions.SelectedIndex].Text,
LFamily) then
begin
GetConvTypes(LFamily, LTypes);
for I := 0 to Length(LTypes) - 1 do
lstFrom.Items.Add(ConvTypeToDescription(LTypes[I]));
end;
end;
end.
I built the application and fired up one of my test Virtual Machines (As I had mentioned before, Microsoft® Virtual PC is a developers dream) and configured an application root for my newly created ASP.NET application. I copied over the ‘application’ and within minutes I had a functional web based variation of a conversion program a la BDS 2006 style.

Labels: .NET, ASP.NET, Code, Delphi