BPSoftware.com
Home   Utilities   Purchase   FAQ   Support   Contact        
Shareware Utilities
 APrintDirect
 AIconExtract
 AFile Attribute Manager
Freeware Utilities
 AddrMon
 AFileSync
 ASysIcon
 B&P Table Utilities
 BPACLer
 BPSNMPMon
 BPSNMPUtil
 CharCount
 Delphi® Components
 MacAddr
Miscellaneous
 BPSoftware Blog
 Purchase Shareware
 Support

 Subscribe!

Sunday, January 22, 2006
MyOwnConversion

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: , , ,

posted by Brad Prendergast at 11:12:00 AM
Comments:
Links to this post:

Create a Link

Recent Posts
 Where in the world?
 Remember SWAG?
 Express
 Adieu George!
 Is it better to be tall or short?
 Syncing
 Piecing it all together (Part 3)
 Piecing it all together (Part 2)
 Piecing it all together (Part 1)
 Some Component Updates

 Subscribe!


Labels



Archives
 October 2005
 November 2005
 December 2005
 January 2006
 February 2006
 March 2006
 April 2006
 May 2006
 June 2006
 July 2006
 August 2006
 September 2006
 December 2006
 January 2007
 February 2007
 March 2007
 September 2007
 October 2007
 November 2007
 July 2008
 November 2008
Powered by Blogger