Announcement

Collapse
No announcement yet.

Wie erzeuge ich eine HTML-Datei mittels Komponente?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wie erzeuge ich eine HTML-Datei mittels Komponente?

    Hallo Leute,

    eigentlich habe ich schon mal eine HTML Datei mit Inhalt erzeugt..ABER ich möchte gerne wissen, ob das gleiche auch mit
    einer Dephi-Komponente zu machen ist...?

    Ein Beispiel wäre supertoll!

    Tatjana

  • #2
    Hallo,

    das kommt darauf an, was in dieser HTML-Datei stehen soll. Wenn zum Beispiel der Inhalt einer Datenbank-Tabelle als HTML-Datei gespeichert werden soll, kann man auf <b>TDataSetTableProducer</b> zurückgreifen:
    <pre>
    { ************************************************** *******************
    Autor : Andreas Kosch
    Compiler : Delphi 5 UpdatePack#1
    Betriebssystem : Windows 2000
    Datum : 16.12.2000
    Beschreibung : TDataSetTableProducer stellt in einer normalen
    Win32-Anwendung (kein WebModul !) den Inhalt
    einer Datenbanktabelle als HTML-Tabelle dar.
    ************************************************** ******************** }

    unit Table2HTMLFrm;

    interface

    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    StdCtrls, Db, DBTables, HTTPApp, DBWeb, ImgList, ComCtrls, ToolWin,
    OleCtrls, SHDocVw;

    type
    TForm1 = class(TForm)
    DataSetTableProducer1: TDataSetTableProducer;
    Table1: TTable;
    StatusBar1: TStatusBar;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ImageList1: TImageList;
    ToolButton4: TToolButton;
    WebBrowser1: TWebBrowser;
    procedure ToolButton3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    private
    { Private-Deklarationen }
    FAppPath : String;
    procedure ShowIntroHTML;
    public
    { Public-Deklarationen }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.DFM}

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    StatusBar1.Panels[0].Text := Table1.DatabaseName;
    FAppPath := ExtractFilePath(Application.EXEName);
    ShowIntroHTML;
    end;

    procedure TForm1.ToolButton1Click(Sender: TObject);
    begin
    Close;
    end;

    procedure TForm1.ToolButton3Click(Sender: TObject);
    var
    vDocument : OleVariant;
    vMIMEType : OleVariant;
    vHTML : OleVariant;
    begin
    if not VarIsEmpty(WebBrowser1.Document) then
    begin
    vDocument := OleVariant(WebBrowser1.Document).Script.Document;
    vMIMEType := 'text/html';
    vDocument.Open(vMIMEType);
    vDocument.Clear;
    Table1.First;
    vHTML := DataSetTableProducer1.Content;
    vDocument.Writeln(vHTML);
    vDocument.Close;
    end;
    StatusBar1.Panels[1].Text := 'HTML-Inhalt direkt anzeigen';
    end;

    procedure TForm1.ToolButton4Click(Sender: TObject);
    const
    sHTMLFileName = 'TblCountry.htm';
    var
    aSL : TStringList;
    sFileURL : String;
    begin
    ShowIntroHTML;
    Table1.First;
    StatusBar1.Panels[1].Text := 'HTML-Datei generieren....';
    aSL := TStringList.Create;
    try
    aSL.Add(DataSetTableProducer1.Content);
    aSL.SaveToFile(sHTMLFileName);
    finally
    aSL.Free;
    end;
    sFileURL := Format('file:///%s%s', [FAppPath, sHTMLFileName]);
    WebBrowser1.Navigate(sFileURL);
    StatusBar1.Panels[1].Text := 'HTML-Datei anzeigen';
    end;

    procedure TForm1.ShowIntroHTML;
    var
    sFileURL : String;
    begin
    sFileURL := Format('file:///%s%s', [FAppPath, 'Table2HTMLIntro.htm']);
    WebBrowser1.Navigate(sFileURL);
    end;

    end.
    </pre&gt

    Comment

    Working...
    X