Delphi 8 and ASP.NET

by Charlie Calvert


What is ASP.NET?


Of WinForms and WebControls


Understanding ASP.NET Applications


Installing ASP.NET Applications


The ASPX file   


ASP.NET Form Markup

<HTML>
<HEAD>
	<TITLE>Basic ASPX with simple form</TITLE>
</HEAD>
<BODY>

<H1>Basic ASPX with Simple Form</H1>   
   
<form runat="server">

<P><strong>Enter name:</strong></P>
<input id="MyControl" type="text" size="30" Runat="Server">

</form>

</BODY>
</HTML>

Web Controls vs HTML Controls

    <asp:button id=Button1 
style="Z-INDEX: 1; LEFT: 94px; POSITION: absolute; TOP: 158px"
runat="server" text="Button">
</asp:button>

Viewstate


Delphi Scripting in ASPX Files Not Supported, Must use CodeBehind

<%@ Page Language="C#" %>

<SCRIPT runat="server">

void Page_Load(object sender, System.EventArgs e)
{
  Response.Write("This is the load page event");
}
</SCRIPT>

<HTML>
<HEAD>
	<TITLE>Basic ASPX with simple form</TITLE>
</HEAD>
<BODY>

<H1>Basic ASPX with Simple Form</H1>   
   
<form runat="server">

<P><strong>Enter name:</strong></P>

<input id="MyControl" type="text" size="30" Runat="Server">

</form>

</BODY>
</HTML>

The following syntax was available in the preview. At that time they said, place the following web.config file in the virtual directory for your application:

<configuration>
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="DelphiProvider" />
</assemblies>
<compilers>
<compiler language="Delphi" extension=".pas"
type="Borland.Delphi.DelphiCodeProvider,DelphiProvider" />
</compilers>
</compilation>
</system.web>
</configuration>

This did not make it into the shipping product, we must use CodeBehind.

Delphi 8 Update 2 and Cassini Needed to Avoid Occasional Lockups


Codebehind

Intro to Web Controls: Styles

Accessing an XML File

var
Names: DataSet;
FileName: String;
begin
Names := DataSet.Create();
FileName := System.Web.HttpContext.Current.Server.MapPath('names.xml');
Names.ReadXml(FileName);
DataGrid1.DataSource := Names;
DataGrid1.DataBind;
end;

Database Simple

  • Here is how to do it in code.
    procedure TWebForm1.Button1_Click(sender: System.Object; e: System.EventArgs);
    var
      MyConnection: SqlConnection;
      MyDataSet: DataSet;
      MyDataAdapter: SqlDataAdapter;
    begin
      MyConnection := SqlConnection.Create('Server=localhost;Integrated Security=SSPI;database=pubs' );
      MyConnection.Open();
      MyDataAdapter := SqlDataAdapter.Create('Select * From Authors', MyConnection);
      MyDataSet := DataSet.Create();
      MyDataAdapter.Fill(MyDataSet, 'Products');
      DataGrid1.DataSource := MyDataSet;
      DataGrid1.DataBind();
    end;
  •  

    Database Delphi Style