2009年5月29日

Delphi 7 SynEdit Export HTML

須安裝 Delphi SynEdit 開發 IDE 元件
http://synedit.sourceforge.net/
在 Form 上按右鍵選擇 View as Text
或是按 [Alt + F12] 編輯 Delphi Form (DFM)
換掉原有 code, 貼入下列 code

object Form1: TForm1
Left = 193
Top = 129
Width = 507
Height = 301
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object SynEdit1: TSynEdit
Left = 0
Top = 29
Width = 499
Height = 234
Align = alClient
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Courier New'
Font.Style = []
TabOrder = 0
Gutter.Font.Charset = DEFAULT_CHARSET
Gutter.Font.Color = clWindowText
Gutter.Font.Height = -11
Gutter.Font.Name = 'Courier New'
Gutter.Font.Style = []
Gutter.ShowLineNumbers = True
Gutter.Gradient = True
Highlighter = SynPasSyn1
Lines.Strings = (
'procedure TForm1.FormCreate(Sender: TObject);'
'begin'
' ShowMessage(IntToStr(123)); '
' ShowMessage(md5sum(''c:\boot.ini'')); // FileName'
'end;')
end
object ToolBar1: TToolBar
Left = 0
Top = 0
Width = 499
Height = 29
ButtonHeight = 21
ButtonWidth = 68
Caption = 'ToolBar1'
ShowCaptions = True
TabOrder = 1
object ToolButton1: TToolButton
Left = 0
Top = 2
Caption = 'Export HTML'
ImageIndex = 0
onclick = ToolButton1Click
end
end
object SynPasSyn1: TSynPasSyn
CommentAttri.Foreground = clGreen
IdentifierAttri.Foreground = clNavy
NumberAttri.Foreground = clTeal
StringAttri.Foreground = clMaroon
Left = 8
Top = 40
end
object SynExporterHTML1: TSynExporterHTML
Color = clWindow
DefaultFilter = 'HTML Documents (*.htm;*.html)|*.htm;*.html'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Courier New'
Font.Style = []
Highlighter = SynPasSyn1
Title = 'Exported to file'
UseBackground = False
Left = 8
Top = 72
end
object SaveDialog1: TSaveDialog
DefaultExt = 'htm'
Left = 8
Top = 104
end
end

再按 [Alt + F12] 編輯 Object Pascal
換掉原有 code, 貼入下列 code

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SynEditExport, SynExportHTML, SynEditHighlighter,
SynHighlighterPas, ComCtrls, ToolWin, SynEdit;

type
TForm1 = class(TForm)
SynEdit1: TSynEdit;
SynPasSyn1: TSynPasSyn;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
SynExporterHTML1: TSynExporterHTML;
SaveDialog1: TSaveDialog;
procedure ToolButton1Click(Sender: TObject);
private
public
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ToolButton1Click(Sender: TObject);
begin
with SynExporterHTML1 do
begin
SaveDialog1.Filter := DefaultFilter;
if SaveDialog1.Execute then
begin
ExportAsText := True;
ExportAll(SynEdit1.Lines);
SynExporterHTML1.SaveToFile(SaveDialog1.FileName);
end;
end;
end;

end.

執行程式, 按 Export HTML

沒有留言:

網誌存檔