I decided to try and use TPageProducer to make an HTM web page.
Start a new project, add a TMemo align it to alBottom, add a TPageProducer component to Form1 and a TSaveDialog.
Click on PageProducer1 and then in the Object Inspector click on the
HTMLDoc property (Click on the ellipses) then add this code:
<HTML><HEAD> <TITLE>DPSC PageProducer Demo</TITLE> </HEAD> <body text="#000000" bgcolor="#FFFFFF" link="#0000FF" vlink="#000099" alink="#000088"> <Center><H1>Page Producer
Demo</H1></Center>
|
You can also use the HTMLFile property to load an .HTM file with the same code above to get the same results of this section about TPageProducer.
As you can see in the code above I have added the HTML Body with the HTM page color and links colors, this helps make the finished web page look professional.
Here is some information about the HTMLDoc property.
HTMLDoc is a set of strings that we are using to make an HTML template
for our HTM web pages.
This HTML template is a lot of HTML commands and HTML-transparent tags,
which make up the finished HTML web page.
Rules for the tag:
<#TagName Param1=Value1 Param2=Value2 ...>
The tag has a < (less than) bracket first, then a # sign then the tag name and last a > (greater than sign).
The # hash (Pound) sign is used immediately after the bracket < (less than) and it has no spaces separating it from the angle bracket. These dynamic tags look like the tags you will find in an HTML web page.
Next click on the events tab and double-click on OnHTMLTag and then
add this code:
procedure TForm1.PageProducer1HTMLTag(Sender: TObject; Tag: TTag; const TagString: String; TagParams: TStrings; var ReplaceText: String); var NDays : Integer; Time : TDateTime; begin if TagString = 'Name' then ReplaceText := Edit1.Text else if TagString = 'date' then ReplaceText := FormatDateTime('dddddd, ' , Now)//DateToStr(Now) else if TagString = 'ProgName' then ReplaceText := ExtractFileName(Application.ExeName) else if TagString = 'Time' then begin Time := Now; ReplaceText := TimeToStr(Time); end end; |
TagString holds the value of the whole tag.
ReplaceText is a string variable that you give a new value which is
used to replace the tag.
Next add 2 TButton components, Change the Button1 caption to read 'Show HTML Code' and change the Button2 caption to read 'Save To File'.
Double-click on Button1 and add this code:
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
Memo1.Text := PageProducer1.Content;
end;
Double-click on Button2 and add this code:
procedure TForm1.Button2Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
Memo1.Lines.SaveToFile
(SaveDialog1.FileName);
end;
end;
Add a TEdit component to the top of your form, then place a TLabel component above Edit1.
Change the Label1 caption to read 'Enter your first name:'.
Next run the program, then enter your name into Edit1, click on Button1 and then save the file as demo1.htm
Open demo1.htm with a web browser and you should see something like
this:
Page Producer Demo
|
And here is the HTML page source:
<HTML><HEAD>
<TITLE>Producer Demo</TITLE> </HEAD> <body text="#000000" bgcolor="#FFFFFF" link="#0000FF" vlink="#000099" alink="#000088"> <Center><H1>Page Producer
Demo</H1></Center>
|