Work with Web Sharp ActiveX in Delphi
Here tech you how to start Web Sharp in Delphi. If you want to know to the details of programming with Web Sharp, download the course.
Note: Source code of this demo is in the directory ¡°Demo\Delphi\¡±, you can click here to download all the demos.
l Work with Web Sharp in Delphi
It is well known that Delphi is short in web applications though it has many web solutions (e.g. Web Broker, WebSnap, IntraWeb) and owns a lot of web components(e.g. PageProducer, WebDispatcher). You have to spend much time to learn how to use these components which are not easily used or high produces in fact. Yet Web Sharp can give Delphi programmers a satisfied result. If you own Web Sharp and Delphi¡¯s powerful database technology, nothing is difficult.
We now Create an ISAPI demo in Delphi 7. If you are familiar with Delphi, steps from 1) to 5) are easy.
1) Install Web Sharp ActiveX pack. Click here to download.
2) Import Web Sharp ActiveX into Delphi. Click [Project] menu, select [Import Type Library]. Select ¡°Web Sharp Library¡±. Click ¡°Install¡± button or ¡°Create Unit¡± button.
Note:If you do not import it into Delphi, you have to create the Web Sharp objects by invoking CreateOleObject () function. We do not suggest this.
3) Create a new Web Server Application.

4)
Select the first Option: ![]()

5) Save the project as WebSharpDemo.dpr. Create a new action called WebActionItem1 in the current Web Module.

6) Create a template file C:\inetpub\wwwroot\WebSharp.htm with the following code:
<html>
<head>
<title>Web Sharp </title>
</head>
<body>
<font color="red">{%HeadLine%} </font>
<p>
<!--BEGIN LOOP: NumberBlock-->
{%Number%}
<!--END LOOP : NumberBlock -->
</p>
Please visit my homepage: <a href="{%URL%}">{%Text%}</a>
</body>
</html>
7) We provider a code produce tool called ¡°Code Framework¡± to make programming
code automatically. It can produce most of the programming code. Run CodeFramework.exe,
select Delphi.def from the languages combobox, and then click ¡°Open Template¡±
button and select the template file WebSharp.htm, and then you will see the
auto complete code result in something like the code in the following figure: 
8) Copy this code to the OnAction event of WebActionItem1 and modify it. The hightlight code in yellow is the modified result. What you do is only to fill the code framework with the actual data.Remember to refer WebSharp_TLB in uses part of current unit. Press Ctrl+F9 to compile the project.
procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
strText:string;
strURL:string;
strNumber:string;
strHeadLine:string;
vnNumberBlock:IValueNode;
vnNumberBlockItem:IValueNode;
WebTemplate:CoWebTemplate;
vnRoot:CoValueNode;
I, K: Integer;
begin
WebTemplate := CoWebTemplate.Create;
try
WebTemplate.FileName := 'C:\inetpub\wwwroot\WebSharp.htm';
RootValueNode := CoValueNode.Create;
try
strHeadLine:= 'Web Sharp Delphi Application';
RootValueNode.SetValue('HeadLine', strHeadLine);
//<!--BEGIN LOOP : NumberBlock -->
vnNumberBlock:=vnRoot.CreateChild('NumberBlock');
for I := 1 to 15 do
begin
vnNumberBlockItem:=vnNumberBlock.CreateChild('');
strNumber:=IntToStr(I);
vnNumberBlockItem.SetValue('Number',strNumber);
end;
//<!--END LOOP : NumberBlock -->
strURL:= 'http://www.coolmasoft.com';
vnRoot.SetValue('URL',strURL);
strText:= 'Coolmasoft';
vnRoot.SetValue('Text',strText);
Response.Content := WebTemplate.Rendered(vnRoot, '');
finally
RootValueNode := nil;
end;
finally
WebTemplate := nil;
end;
end;
1) Start IIS manager and configure a virtual path in IIS named WebSharpDemo. This path must be pointed to the directory where your Delphi project WebSharpDemo.dpr are in and this path owns the privilege of execute application. If you use IIS6.0, you must go to IIS manager and configure the Web Service Extension¡ªset ISAPI Extension option to permitted state.
2) Navigate to http://localhost/websharpDemo/webSharpDemo.dll and you will see the result.

OK, do you think it is very simple? Yes, you can use Web sharp to develop high performance web application in Delphi now. Why not try it?
If you want to know to the details of programming with Web Sharp, download the course.