uHtmlEdit.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:36k
源码类别:

Email服务器

开发平台:

Delphi

  1. {*******************************************************}
  2. {                                                       }
  3. {       作者: 隐神                                      }
  4. {                                                       }
  5. {       日期: 2007.05.15                                }
  6. {                                                       }
  7. {       电邮: Dot.net@tom.com                           }
  8. {                                                       }
  9. {       版权所有 (C) 2007 独家村一号                    }
  10. {                                                       }
  11. {*******************************************************}
  12. unit uHtmlEdit;
  13. interface
  14. uses
  15.   Windows, Messages, Forms, SysUtils, Classes, Controls, Graphics, OleCtrls,
  16.   SHDocVw, Dialogs, ComCtrls, mshtml, Variants, ActiveX, StdCtrls, ExtCtrls,
  17.   Clipbrd,OleServer;
  18. type
  19.   {
  20.   2D-Position 允许通过拖曳移动绝对定位的对象。
  21.   AbsolutePosition 设定元素的 position 属性为“absolute”(绝对)。
  22.   BackColor 设置或获取当前选中区的背景颜色。
  23.   BlockDirLTR 目前尚未支持。
  24.   BlockDirRTL 目前尚未支持。
  25.   Bold 切换当前选中区的粗体显示与否。
  26.   BrowseMode 目前尚未支持。
  27.   Copy 将当前选中区复制到剪贴板。
  28.   CreateBookmark 创建一个书签锚或获取当前选中区或插入点的书签锚的名称。
  29.   CreateLink 在当前选中区上插入超级链接,或显示一个对话框允许用户指定要为当前选中区插入的超级链接的 URL。
  30.   Cut 将当前选中区复制到剪贴板并删除之。
  31.   Delete 删除当前选中区。
  32.   DirLTR 目前尚未支持。
  33.   DirRTL 目前尚未支持。
  34.   EditMode 目前尚未支持。
  35.   FontName 设置或获取当前选中区的字体。
  36.   FontSize 设置或获取当前选中区的字体大小。
  37.   ForeColor 设置或获取当前选中区的前景(文本)颜色。 )
  38.   formatBlock 设置当前块格式化标签。
  39.   Indent 增加选中文本的缩进。
  40.   InlineDirLTR 目前尚未支持。
  41.   InlineDirRTL 目前尚未支持。
  42.   InsertButton 用按钮控件覆盖当前选中区。
  43.   InsertFieldset 用方框覆盖当前选中区。
  44.   InsertHorizontalRule 用水平线覆盖当前选中区。
  45.   InsertIFrame 用内嵌框架覆盖当前选中区。
  46.   InsertImage 用图像覆盖当前选中区。
  47.   InsertInputButton 用按钮控件覆盖当前选中区。
  48.   InsertInputCheckbox 用复选框控件覆盖当前选中区。
  49.   InsertInputFileUpload 用文件上载控件覆盖当前选中区。
  50.   InsertInputHidden 插入隐藏控件覆盖当前选中区。
  51.   InsertInputImage 用图像控件覆盖当前选中区。
  52.   InsertInputPassword 用密码控件覆盖当前选中区。
  53.   InsertInputRadio 用单选钮控件覆盖当前选中区。
  54.   InsertInputReset 用重置控件覆盖当前选中区。
  55.   InsertInputSubmit 用提交控件覆盖当前选中区。
  56.   InsertInputText 用文本控件覆盖当前选中区。
  57.   InsertMarquee 用空字幕覆盖当前选中区。
  58.   InsertOrderedList 切换当前选中区是编号列表还是常规格式化块。
  59.   InsertParagraph 用换行覆盖当前选中区。
  60.   InsertSelectDropdown 用下拉框控件覆盖当前选中区。
  61.   InsertSelectListbox 用列表框控件覆盖当前选中区。
  62.   InsertTextArea 用多行文本输入控件覆盖当前选中区。
  63.   InsertUnorderedList 切换当前选中区是项目圆点符号列表。
  64.   Italic 切换当前选中区斜体显示与否。
  65.   JustifyCenter 将当前选中区在所在格式化块置中。
  66.   JustifyFull 目前尚未支持。
  67.   JustifyLeft 将当前选中区所在格式化块左对齐。
  68.   JustifyNone 目前尚未支持。
  69.   JustifyRight 将当前选中区所在格式化块右对齐。
  70.   LiveResize 迫使 MSHTML 编辑器在缩放或移动过程中持续更新元素外观,而不是只在移动或缩放完成后更新。
  71.   MultipleSelection 允许当用户按住 Shift 或 Ctrl 键时一次选中多于一个站点可选元素。
  72.   Open 目前尚未支持。
  73.   Outdent 减少选中区所在格式化块的缩进。
  74.   OverWrite 切换文本状态的插入和覆盖。
  75.   Paste 用剪贴板内容覆盖当前选中区。
  76.   PlayImage 目前尚未支持。
  77.   Print 打开打印对话框以便用户可以打印当前页。
  78.   Redo 目前尚未支持。
  79.   Refresh 刷新当前文档。
  80.   Removeformat 从当前选中区中删除格式化标签。
  81.   RemoveParaformat 目前尚未支持。
  82.   SaveAs 将当前 Web 页面保存为文件。
  83.   SelectAll 选中整个文档。
  84.   SizeToControl 目前尚未支持。
  85.   SizeToControlHeight 目前尚未支持。
  86.   SizeToControlWidth 目前尚未支持。
  87.   Stop 目前尚未支持。
  88.   StopImage 目前尚未支持。
  89.   StrikeThrough 目前尚未支持。
  90.   Subscript 下标
  91.   Superscript 上标
  92.   UnBookmark 从当前选中区中删除全部书签。
  93.   Underline 切换当前选中区的下划线显示与否。
  94.   Undo 目前尚未支持。
  95.   Unlink 从当前选中区中删除全部超级链接。
  96.   Unselect 清除当前选中区的选中状态。
  97.   }
  98.   // 选择色彩对话窗
  99.   TUnorderedListType=(ultDisc,ultCricle,ultSquare);
  100.   TOnColorDialog = procedure(Sender: TObject; out vColor: TColor) of object;
  101.   TEditCommander = class(TObject)
  102.   private
  103.     FHTMLDocument: IHTMLDocument2;
  104.     FImageFolder: string;
  105.     FOnColorDialog: TOnColorDialog;
  106.     procedure SetFocus;
  107.     procedure InsertHTML(const html: WideString);
  108.    // procedure InsertObject(const OuterHtml: WideString);
  109.     procedure SetOnColorDialog(const Value: TOnColorDialog);
  110.   protected
  111.     // InsertImage 插入图片 只留一个接口, 图片名必须由外部提供
  112.     procedure InsertImage; overload; virtual;
  113.   public
  114.     SelectedTable: IHTMLElement;
  115.     constructor Create(AHTMLDocument: IHTMLDocument2);
  116.     // BackColor 突出显示
  117.     procedure BackColor; overload;
  118.     //---------------------------added by wp---------------------------------
  119.     procedure InsertH1(InnerText:string); //插入标题
  120.     procedure InsertH2(InnerText:string);
  121.     procedure InsertH3(InnerText:string);
  122.     procedure InsertH4(InnerText:string);
  123.     procedure InsertH5(InnerText:string);
  124.     
  125.     procedure InsertHr;      //插入水平线
  126.     procedure InsertOrderedList(List:TStrings;TypeChar:Char); overload;//插入列表
  127.      //插入不排序的列表,UnorderedListType指出每项前面的符号
  128.     procedure InsertUnorderedList(List:TStrings;UnorderedListType:TUnorderedListType);overload;
  129.     //插入自定义的列表 .每个项目的缩进以前面的tab建个数决定。没有tab建不缩进,有一个tab建缩进一层。
  130.     //(只有缩进1层和没有缩进2中情况。否则忽略改行)。
  131.     procedure InsertDefinedList(List:TStrings );
  132.     procedure InsertButton(Caption:string);
  133.     procedure InsertLabel(Caption:string);
  134.     procedure InsertEdit(DefaultText:string='');
  135.     //----------------------------------------------------------------------
  136.     // BackColor 突出显示
  137.     procedure BackColor(const AColor: TColor); overload;
  138.     // Bold 加粗
  139.     procedure Bold;
  140.     // CreateLink 给选定对象添加超级连接
  141.     procedure CreateLink;
  142.     // 设置或获取当前选中区的字体。
  143.     procedure FontName(const AFontName: string);
  144.     // 设置或获取当前选中区的字体大小。
  145.     procedure FontSize(const AFontSize: Integer);
  146.     // ForeColor 字体颜色
  147.     procedure ForeColor; overload;
  148.     // ForeColor 字体颜色
  149.     procedure ForeColor(const AColor: TColor); overload;
  150.     //执行指令
  151.     procedure Format(const Cmd: string);
  152.     // htmlmode 切换HTML原始码
  153.     //procedure HtmlMode;
  154.     // indent 增加缩进量
  155.     procedure InDent;
  156.     // horizontalrule 水平线
  157.     procedure InsertHorizontalRule;
  158.     // InsertImage 插入图片
  159.     procedure InsertImage(const AImageName: string); overload;
  160.     //
  161.     procedure InsertLineBreak;
  162.     // 项目符号
  163.     procedure InsertOrderedList;  overload;
  164.     // inserttable 插入表格
  165.     procedure InsertTable(const Col: Integer = 2; const Row: Integer = 2;Borlder:integer=1);
  166.     // 切消项目符号
  167.     procedure InsertUnOrderedList;  overload;
  168.     function IsTableSelected: Boolean;
  169.     // italic 斜体
  170.     procedure Italic;
  171.     // justifycenter 位置居中
  172.     procedure JustifyCenter;
  173.     // justifyfull 位置左右平等
  174.     procedure JustifyFull;
  175.     // justifyleft 位置靠左
  176.     procedure JustifyLeft;
  177.     // justifyright 位置靠右
  178.     procedure JustifyRight;
  179.     // orderedlist 顺序清单
  180.     //procedure Orderedlist;
  181.     // outdent 减少缩进量
  182.     procedure OutDent;
  183.     // popupeditor 放大
  184.     //procedure Popupeditor;
  185.     // 精除格式
  186.     procedure RemoveFormat;
  187.     //最后页
  188.     procedure ScrollToBottom;
  189.     //最顶页
  190.     procedure ScrollToTop;
  191.     // strikethrough 删除线
  192.     procedure StrikeThrough;
  193.     // subscript 下标
  194.     procedure SubScript;
  195.     // superscript 上标
  196.     procedure SuperScript;
  197.     // textindicator 字体例子
  198.     //procedure Textindicator;
  199.     // underline 下划线
  200.     procedure UnderLine;
  201.     // unorderedlist 无序清单
  202.     //procedure Unorderedlist;
  203.   published
  204.     // 存放图片的临时目录
  205.     property ImageFolder: string read FImageFolder write FImageFolder;
  206.     // 调用色彩对话窗
  207.     property OnColorDialog: TOnColorDialog read FOnColorDialog write
  208.       SetOnColorDialog;
  209.   end;
  210.   THistoryFile = class
  211.   private
  212.     FFilename: TFilename;
  213.     //FFileStream:TFileStream;
  214.   protected
  215.     class procedure Open;
  216.     constructor CreateInstance;
  217.     class function AccessInstance(Request: Integer): THistoryFile;
  218.   public
  219.     procedure Write(const AText: string); 
  220.     constructor Create;
  221.     class function Instance: THistoryFile;
  222.     class procedure ReleaseInstance;
  223.   //published
  224.     //property Filename: TFilename read FFilename write SetFilename;
  225.   end;
  226.   THtmlInspector=class(TInternetExplorer) ;
  227.   TOnClipboardEvent = procedure(Sender: TObject; AClipboard: TClipboard) of
  228.     object;
  229.   TOnKeyHyperlink = procedure(Sender: TObject; var vHyperlink: string) of
  230.     object;
  231.   THTMLDocumentEvent=procedure(Sender:TObject; const   pEvtObj:
  232.                       IHTMLEventObj) of object;
  233.   THtmlEdit = class(TWebBrowser)
  234.   private
  235.     FEdit: TEditCommander;
  236.     FFont: TFont;
  237.     //FHistory: THistoryFile;
  238.     FHTMLDocument: IHTMLDocument2;
  239.     FImageFolder: string;
  240.     FOnKeyHyperlink: TOnKeyHyperlink;
  241.     FOnPaste: TOnClipboardEvent;
  242.     FReadOnly: Boolean;
  243.     FCharSet: string;
  244.     //FOleInPlaceActiveObject:IOleInPlaceActiveObject;
  245.  
  246.     FoControlRange: IHTMLControlRange;
  247.     FOnDataSetChanged:THTMLDocumentEvent;
  248.     FInspector:THtmlInspector;
  249.     function GetHTML: WideString;
  250.     function GetText: WideString;
  251.     //procedure OnMessage(var Msg: TMsg; var Handled: Boolean);
  252.     // 17,
  253.     procedure SetHTML(const Value: WideString);
  254.     // 17,
  255.     procedure SetImageFolder(const Value: string);
  256.     // 17,
  257.     procedure SetReadOnly(const Value: Boolean);
  258.     procedure SetCharSet(const Value: string);
  259.     function GetModified: boolean;
  260.   public
  261.     constructor Create(AOwner: TComponent); override;
  262.     // Forms.Application.OnMessage := Self.OnMessage;
  263.     destructor Destroy; override;
  264.     // 添加
  265.     procedure Append(AMessage: string);
  266.     // 清除
  267.     procedure Clear;
  268.     // 复制
  269.     procedure Copy;
  270.     // 剪切
  271.     procedure Cut;
  272.     // 删除
  273.     //procedure Delete;
  274.     procedure SearchText;                  //查找  added by wp
  275.     //procedure SetCharSet(ACharSet: String);  overload;  //设置编码     added by wp
  276.     //插入内容
  277.     procedure Insert(AMessage: string);
  278.     // 从文件加载
  279.     procedure LoadFromFile(const AFileName: string);
  280.     // 从流加载
  281.     procedure LoadFromStream(AHtmlStrem: TStream);
  282.     // 新建
  283.     procedure New;
  284.     // 打开
  285.     procedure Open(const AFileName: string);
  286.     // 粘贴
  287.     procedure Paste;
  288.     // 打印
  289.     procedure Print(const APreview: Boolean = FALSE);
  290.     // 页面设置
  291.     procedure PrintPageSetup;
  292.     // 打印预览
  293.     procedure PrintPreview;
  294.     // 重做
  295.     procedure Redo;
  296.     // 保存
  297.     procedure Save;
  298.     // 另存为
  299.     procedure SaveAs;
  300.     // 保存到指定文件
  301.     procedure SaveToFile(const FileName: string);
  302.     // 保存到流
  303.     procedure SaveToStream(Stream: TStream);
  304.     // 全选
  305.     procedure SelectAll;
  306.     // 撒消
  307.     procedure Undo;
  308.     // 写入内容
  309.     procedure Write(AHTML: string);
  310.     //
  311.     procedure SetFocus; override;
  312.     // 编辑指令
  313.     property Edit: TEditCommander read FEdit;
  314.     function CanFocus: Boolean; override;
  315.   published
  316.     property OnDataSetChanged:THTMLDocumentEvent read FOnDataSetChanged write FOnDataSetChanged ;//dispid -2147412072;
  317.     // 只读属性
  318.     property ReadOnly: Boolean read FReadOnly write SetReadOnly;
  319.     
  320.     property TabStop default True;
  321.     property Align;
  322.     property DragCursor;
  323.     property DragMode;
  324.     property ParentShowHint;
  325.     property PopupMenu;
  326.     property ShowHint;
  327.     property TabOrder;
  328.     property OnDragDrop;
  329.     property OnDragOver;
  330.     property OnEndDrag;
  331.     property OnEnter;
  332.     property OnExit;
  333.     property OnStartDrag;
  334.     
  335.     property CharSet: string read FCharSet write SetCharSet;
  336.     // 默认字体
  337.     property Font: TFont read FFont write FFont;
  338.     // 聊天记录
  339.     //property History: THistoryBase read FHistory write FHistory;
  340.     // 内容的HTML格式
  341.     property HTML: WideString read GetHTML write SetHTML;
  342.     // 图片文件临时存放路径
  343.     property ImageFolder: string read FImageFolder write SetImageFolder;
  344.     // 内容的文本格式
  345.     property Text: WideString read GetText;
  346.     // 点击了超联接
  347.     property OnKeyHyperlink: TOnKeyHyperlink read FOnKeyHyperlink write
  348.       FOnKeyHyperlink;
  349.     // 粘贴事件
  350.     property OnPaste: TOnClipboardEvent read FOnPaste write FOnPaste;
  351.     property Modified:boolean read GetModified;
  352.   end;
  353. procedure Register;
  354. implementation
  355. uses uMD5;
  356. procedure Register;
  357. begin
  358.   RegisterComponents('HtmlEdit', [THtmlEdit]);
  359.   //RegisterComponents('HtmlEdit', [THistoryFile]);
  360. end;
  361. function GetTempDir: string;
  362. var
  363.   TmpDir: array[0..255] of Char;
  364. begin
  365.   GetTempPath(255, @TmpDir);
  366.   Result := StrPas(TmpDir);
  367.   TmpDir := '';
  368. end;
  369. { THtmlEdit }
  370. {
  371. ******************************** TEditCommander ********************************
  372. }
  373. constructor TEditCommander.Create(AHTMLDocument: IHTMLDocument2);
  374. begin
  375.   //inherited;
  376.   FHTMLDocument := AHTMLDocument;
  377. end; { TEditCommander.Create }
  378. procedure TEditCommander.BackColor;
  379. var
  380.   Color: TColor;
  381. begin
  382.   if Assigned(FOnColorDialog) then
  383.     FOnColorDialog(Self, Color);
  384.   BackColor(Color);
  385. end; { TEditCommander.BackColor }
  386. procedure TEditCommander.BackColor(const AColor: TColor);
  387. begin
  388.   FHTMLDocument.execCommand('BackColor', True, AColor);
  389.   SetFocus;
  390. end; { TEditCommander.BackColor }
  391. procedure TEditCommander.Bold;
  392. begin
  393.   Format('Bold');
  394. end; { TEditCommander.Bold }
  395. procedure TEditCommander.CreateLink;
  396. begin
  397.   Format('CreateLink');
  398. end; { TEditCommander.CreateLink }
  399. procedure TEditCommander.ForeColor;
  400. var
  401.   Color: TColor;
  402. begin
  403.   if Assigned(FOnColorDialog) then
  404.     FOnColorDialog(Self, Color);
  405.   ForeColor(Color);
  406. end; { TEditCommander.ForeColor }
  407. procedure TEditCommander.ForeColor(const AColor: TColor);
  408. begin
  409.   FHTMLDocument.execCommand('ForeColor', True, AColor);
  410.   SetFocus;
  411. end; { TEditCommander.ForeColor }
  412. procedure TEditCommander.Format(const Cmd: string);
  413. begin
  414.   FHTMLDocument.execCommand(Cmd, True, True);
  415.   SetFocus;
  416. end; { TEditCommander.Format }
  417. //procedure TEditCommander.HtmlMode;
  418. //begin
  419. //  //暂未支持
  420. //end; { TEditCommander.HtmlMode }
  421. procedure TEditCommander.InDent;
  422. begin
  423.   Format('Indent');
  424. end; { TEditCommander.InDent }
  425. procedure TEditCommander.InsertHorizontalRule;
  426. begin
  427.   Format('InsertHorizontalRule');
  428. end; { TEditCommander.InsertHorizontalRule }
  429. procedure TEditCommander.InsertHTML(const html: WideString);
  430. begin
  431.   if LowerCase(FHTMLDocument.selection.type_) <> 'none' then
  432.     FHTMLDocument.selection.clear;
  433.   (FHTMLDocument.selection.createRange as IHTMLTxtRange).pasteHTML(html);
  434.   SetFocus;
  435. end; { TEditCommander.InsertHTML }
  436. procedure TEditCommander.InsertImage;
  437. begin
  438.   Format('InsertImage');
  439. end; { TEditCommander.InsertImage }
  440. procedure TEditCommander.InsertImage(const AImageName: string);
  441. var
  442.   TargetName: string;
  443. begin
  444.   if FileExists(AImageName) and DirectoryExists(FImageFolder) then
  445.   begin
  446.     //返回图片的新名
  447.     TargetName := StrMD5(FormatDateTime('yyyymmddhhnnss', Now) +
  448.       IntToStr(GetTickCount)) + ExtractFileExt(AImageName);
  449.     //将图片以新名称复制到指定的文件夹
  450.     CopyFile(PChar(AImageName), PChar(FImageFolder + TargetName), False);
  451.     InsertHTML('<img src="file://' + FImageFolder + TargetName + '" >');
  452.   end;
  453.   SetFocus;
  454. end; { TEditCommander.InsertImage }
  455. procedure TEditCommander.InsertLineBreak;
  456. begin
  457.   InsertHTML('<BR>');
  458.   (FHTMLDocument.parentWindow as IHTMLWindow2).focus;
  459. end; { TEditCommander.InsertLineBreak }
  460. procedure TEditCommander.InsertOrderedList;
  461. begin
  462.   Format('InsertOrderedList');
  463. end; { TEditCommander.InsertOrderedList }
  464. procedure TEditCommander.InsertTable(const Col: Integer = 2; const Row: Integer = 2;Borlder:integer=1);
  465. var
  466.   ColCnt, RowCnt: Integer;
  467.   sTable: string;
  468. begin
  469.   //sTable是表格的Html代码
  470.   sTable := '<TABLE border='+inttostr(Borlder)+' >';
  471.   for RowCnt := 1 to Row do
  472.   begin
  473.     sTable := sTable + '<TR>';
  474.     for ColCnt := 1 to Col do
  475.       sTable := sTable + '<TD>&nbsp;&nbsp;&nbsp;&nbsp;</TD>';
  476.     sTable := sTable + '</TR>';
  477.   end;
  478.   sTable := sTable + '</TABLE>';
  479.   //插入Html表格
  480.   InsertHTML(sTable);
  481.   SetFocus;
  482. end; { TEditCommander.InsertTable }
  483. procedure TEditCommander.InsertUnOrderedList;
  484. begin
  485.   Format('InsertUnOrderedList');
  486. end; { TEditCommander.InsertUnOrderedList }
  487. function TEditCommander.IsTableSelected: Boolean;
  488. var
  489.   oControlRange: IHTMLControlRange;
  490. begin
  491.   Result := False;
  492.   if UpperCase(FHTMLDocument.selection.type_) = 'CONTROL' then
  493.   begin
  494.     oControlRange := (FHTMLDocument.selection.createRange as IHTMLControlRange);
  495.     if UpperCase((oControlRange.item(0) as IHTMLElement).tagName) = 'TABLE' then
  496.     begin
  497.       SelectedTable := ((FHTMLDocument.selection.createRange as
  498.         IHTMLControlRange).item(0)) as IHTMLElement;
  499.       Result := True;
  500.     end;
  501.   end;
  502. end; { TEditCommander.IsTableSelected }
  503. procedure TEditCommander.Italic;
  504. begin
  505.   Format('Italic');
  506. end; { TEditCommander.Italic }
  507. procedure TEditCommander.JustifyCenter;
  508. begin
  509.   Format('JustifyCenter');
  510. end; { TEditCommander.JustifyCenter }
  511. procedure TEditCommander.JustifyFull;
  512. begin
  513.   Format('JustifyFull');
  514. end; { TEditCommander.JustifyFull }
  515. procedure TEditCommander.JustifyLeft;
  516. begin
  517.   Format('JustifyLeft');
  518. end; { TEditCommander.JustifyLeft }
  519. procedure TEditCommander.JustifyRight;
  520. begin
  521.   Format('JustifyRight');
  522. end; { TEditCommander.JustifyRight }
  523. //procedure TEditCommander.Orderedlist;
  524. //begin
  525. //  //暂未支持
  526. //end; { TEditCommander.Orderedlist }
  527. procedure TEditCommander.OutDent;
  528. begin
  529.   Format('Outdent');
  530. end; { TEditCommander.OutDent }
  531. //procedure TEditCommander.Popupeditor;
  532. //begin
  533. //  //暂未支持
  534. //end; { TEditCommander.Popupeditor }
  535. procedure TEditCommander.RemoveFormat;
  536. begin
  537.   Format('Removeformat');
  538. end; { TEditCommander.RemoveFormat }
  539. procedure TEditCommander.ScrollToBottom;
  540. begin
  541.   if Assigned(FHTMLDocument) then
  542.     FHTMLDocument.parentWindow.scrollBy(0, (FHTMLDocument.body as
  543.       IHTMLElement2).scrollHeight);
  544.   SetFocus;
  545. end; { TEditCommander.ScrollToBottom }
  546. procedure TEditCommander.ScrollToTop;
  547. begin
  548.   if Assigned(FHTMLDocument) then
  549.     FHTMLDocument.parentWindow.scrollTo(0, 0);
  550.   SetFocus;    
  551. end; { TEditCommander.ScrollToTop }
  552. procedure TEditCommander.SetOnColorDialog(const Value: TOnColorDialog);
  553. begin
  554.   FOnColorDialog := Value;
  555. end; { TEditCommander.SetOnColorDialog }
  556. procedure TEditCommander.StrikeThrough;
  557. begin
  558.   Format('Strikethrough');
  559. end; { TEditCommander.StrikeThrough }
  560. procedure TEditCommander.SubScript;
  561. begin
  562.   Format('Subscript');
  563. end; { TEditCommander.SubScript }
  564. procedure TEditCommander.SuperScript;
  565. begin
  566.   Format('Superscript');
  567. end; { TEditCommander.SuperScript }
  568. //procedure TEditCommander.Textindicator;
  569. //begin
  570. //  //暂不支持
  571. //end; { TEditCommander.Textindicator }
  572. procedure TEditCommander.UnderLine;
  573. begin
  574.   Format('Underline');
  575. end; { TEditCommander.UnderLine }
  576. //procedure TEditCommander.Unorderedlist;
  577. //begin
  578. //  //暂不支持
  579. //end; { TEditCommander.Unorderedlist }
  580. var
  581.   FFileStream:TFileStream=nil;
  582.   Active:Boolean=false;
  583. class function THistoryFile.AccessInstance(Request: Integer): THistoryFile;
  584. {$J+}
  585.   const FInstance: THistoryFile = nil;
  586. {$J-}
  587. begin
  588.   case Request of
  589.     0 : ;
  590.     1 : if not Assigned(FInstance) then FInstance := CreateInstance;
  591.     2 : FInstance := nil;
  592.   else
  593.     raise Exception.CreateFmt('Illegal request %d in AccessInstance', [Request]);
  594.   end;
  595.   Result := FInstance;
  596. end;
  597. constructor THistoryFile.Create;
  598. begin
  599.   inherited Create;
  600.   raise Exception.CreateFmt('Access class %s through Instance only', [ClassName]);
  601. end;
  602. constructor THistoryFile.CreateInstance;
  603. begin
  604.   inherited Create;
  605.   FFilename:=IncludeTrailingPathDelimiter(GetTempDir)+ExtractFileName(Application.ExeName)+'.his';
  606.   Open;
  607.   Active:=true;
  608. end;
  609. class function THistoryFile.Instance: THistoryFile;
  610. begin
  611.   Result := AccessInstance(1);
  612. end;
  613. class procedure THistoryFile.Open;
  614. begin
  615.   if not FileExists(IncludeTrailingPathDelimiter(GetTempDir)+ExtractFileName(Application.ExeName)+'.his') then
  616.   begin
  617.     FFileStream := TFileStream.Create(IncludeTrailingPathDelimiter(GetTempDir)+ExtractFileName(Application.ExeName)+'.his', fmCreate or fmShareDenyWrite);
  618.   end
  619.   else
  620.   begin
  621.     FFileStream := TFileStream.Create(IncludeTrailingPathDelimiter(GetTempDir)+ExtractFileName(Application.ExeName)+'.his', fmShareDenyWrite );
  622.     FFileStream.Position := FFileStream.Size;
  623.   end;
  624. end; { THistoryFile.Open }
  625. {procedure THistoryFile.SetFilename(const Value: TFilename);
  626. begin
  627.   FFilename := Value;
  628.   if Active then
  629.     Close;
  630.   Open;
  631. end;  THistoryFile.SetFilename }
  632. class procedure THistoryFile.ReleaseInstance;
  633. begin
  634.   AccessInstance(0).Free;
  635.   Active:=false;
  636.   FreeAndNil(FFileStream);
  637. end;
  638. procedure THistoryFile.Write(const AText: string);
  639. begin
  640.   if Active and (Length(AText) > 0) then
  641.   begin
  642.     FFileStream.WriteBuffer(AText[1], Length(AText));
  643.   end;
  644. end; { THistoryFile.Write }
  645. {
  646. ********************************** THtmlEdit ***********************************
  647. }
  648. constructor THtmlEdit.Create(AOwner: TComponent);
  649. var
  650.   doc:IHtmlDocument3;
  651. begin
  652.   inherited Create(AOwner);
  653.   Self.Navigate('about:blank');
  654.   FHTMLDocument := IHTMLDocument2(Self.Document);
  655.   //编辑指令
  656.   FEdit := TEditCommander.Create(FHTMLDocument);
  657.   //缺省是系统临时文件夹
  658.   ImageFolder := GetTempDir;
  659.   ReadOnly := False;
  660.   CharSet := 'gb2312';
  661.   //here added by wp 
  662.   //  FHtmlFont := THtmlFont.Create(HTMLDocument);
  663.   FoControlRange:=nil;
  664.   //FInspector:=THtmlInspector.Create(nil) ;
  665.   //FInspector.ConnectKind:=ckRunningInstance;
  666.   //FInspector.ConnectTo(self as IWebBrowser2);
  667.   if self.Document.QueryInterface(IHtmlDocument3,Doc)=S_FALSE then
  668.     raise Exception.Create('IHtmlDocument3 interface NOT Implement! ');
  669.   if not doc.attachEvent('ondatasetchanged',self) then
  670.     raise Exception.Create('attachEvent failure! ');
  671.   //FHistory:=THistoryFile.Instance;
  672.   //FOldOnMessage:=Forms.Application.OnMessage;
  673.  // Forms.Application.OnMessage := Self.OnMessage;
  674. end; { THtmlEdit.Create }
  675. destructor THtmlEdit.Destroy;
  676. begin
  677.   //FInspector.disconnect;
  678.   //FInspector.free;
  679.   FreeAndNil(FEdit);
  680.   //self.FHistory.ReleaseInstance;
  681.   //self.FHistory:=nil;
  682.   //Forms.Application.OnMessage:=Self.FOldOnMessage;
  683.   inherited;
  684. end; { THtmlEdit.Destroy }
  685. procedure THtmlEdit.Append(AMessage: string);
  686. begin
  687.   Self.OleObject.document.write(AMessage);
  688. end; { THtmlEdit.Add }
  689. procedure THtmlEdit.Clear;
  690. begin
  691.   Self.New;
  692. end; { THtmlEdit.Clear }
  693. procedure THtmlEdit.Copy;
  694. begin
  695.   Self.ExecWB(OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT); //12,
  696. end; { THtmlEdit.Copy }
  697. procedure THtmlEdit.Cut;
  698. begin
  699.   Self.ExecWB(OLECMDID_CUT, OLECMDEXECOPT_DODEFAULT); //11,
  700. end; { THtmlEdit.Cut }
  701. //procedure THtmlEdit.Delete;
  702. //begin
  703. //  Self.ExecWB(OLECMDID_NEW, OLECMDEXECOPT_DODEFAULT);
  704. //end; { THtmlEdit.Delete }
  705. function THtmlEdit.GetHTML: WideString;
  706. begin
  707.   Result := FHTMLDocument.body.outerHTML;
  708. end; { THtmlEdit.GetHTML }
  709. function THtmlEdit.GetText: WideString;
  710. begin
  711.   Result := FHTMLDocument.body.outerText;
  712. end; { THtmlEdit.GetText }
  713. procedure THtmlEdit.Insert(AMessage: string);
  714. begin
  715.   if LowerCase(FHTMLDocument.selection.type_) <> 'none' then
  716.     FHTMLDocument.selection.clear;
  717.   (FHTMLDocument.selection.createRange as IHTMLTxtRange).pasteHTML(AMessage);
  718. end; { THtmlEdit.Insert }
  719. procedure THtmlEdit.LoadFromFile(const AFileName: string);
  720. var
  721.   Stream: TStream;
  722. begin
  723.   if FileExists(AFileName) then
  724.   begin
  725.     Stream := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyWrite);
  726.     try
  727.       LoadFromStream(Stream);
  728.     finally
  729.       Stream.Free;
  730.     end;
  731.   end;
  732. end; { THtmlEdit.LoadFromFile }
  733. procedure THtmlEdit.LoadFromStream(AHtmlStrem: TStream);
  734. var
  735.   Size: Integer;
  736.   S: string;
  737. begin
  738.   try
  739.     Size := AHtmlStrem.Size - AHtmlStrem.Position;
  740.     SetString(S, nil, Size);
  741.     AHtmlStrem.Read(Pointer(S)^, Size);
  742.     Self.OleObject.document.close();
  743.     Self.OleObject.document.clear();
  744.     Self.OleObject.document.write(S);
  745.   finally
  746.   end;
  747. end; { THtmlEdit.LoadFromStream }
  748. procedure THtmlEdit.New;
  749. var
  750.   Html: string;
  751. begin
  752.   //Self.ExecWB(OLECMDID_NEW, OLECMDEXECOPT_DODEFAULT); //2,
  753.   Html := '<HTML>'#13#10;
  754.   Html := Html + '<HEAD>'#13#10;
  755.   Html := Html + '<META NAME="GENERATOR" CONTENT="PP HTML-WRITER">'#13#10;
  756.   //Html := Html + '<TITLE>' + S + '</TITLE>'#13#10;
  757.   Html := Html + '<TITLE>NewDocument</TITLE>'#13#10;
  758.   Html := Html + '</HEAD>'#13#10;
  759.   Html := Html + '<BODY>'#13#10;
  760.   Html := Html + '</BODY>'#13#10;
  761.   Html := Html + '</HTML>'#13#10;
  762.   Self.OleObject.document.close();
  763.   Self.OleObject.document.clear();
  764.   Self.OleObject.document.write(HTML);
  765. end; { THtmlEdit.NewDocument }
  766. //procedure THtmlEdit.OnMessage(var Msg: TMsg; var Handled: Boolean); //added by wp
  767. //const
  768. //  DialogKeys: set of Byte = [VK_LEFT, VK_RIGHT, VK_BACK, VK_UP, VK_DOWN,
  769. //    $30..$39, $41..42, $44..$55, $57, $59..$5A];
  770. //var
  771. // { p: tpoint;
  772. //  TheName: array[0..255] of char;   }
  773. //  iOIPAO: IOleInPlaceActiveObject;
  774. //  Dispatch: IDispatch;
  775. //
  776. //begin
  777. //  Handled := (IsDialogMessage(self.Handle, Msg) = True);
  778. //
  779. //  if (not Handled )or( Busy) then  Exit;
  780. //
  781. //  if FOleInPlaceActiveObject = nil then
  782. //  begin
  783. //    Dispatch := Self.Application;
  784. //    if Dispatch <> nil then
  785. //    begin
  786. //      Dispatch.QueryInterface(IOleInPlaceActiveObject, iOIPAO);
  787. //      if iOIPAO <> nil then
  788. //        FOleInPlaceActiveObject := iOIPAO;
  789. //    end;
  790. //  end
  791. //  else
  792. //  begin
  793. //    if ((Msg.message = WM_KEYDOWN) or (Msg.message = WM_KEYUP)) then
  794. //    begin
  795. //      case Msg.wParam of
  796. //        VK_DELETE,VK_BACK,VK_CLEAR : if FoControlRange<>nil then FoControlRange.remove(0) ;
  797. //
  798. //      else;
  799. //      end;
  800. //      FoControlRange:=nil;
  801. //    end
  802. //    else if (Msg.message =Messages.WM_MBUTTONDBLCLK) then
  803. //    begin
  804. //      FoControlRange:=nil;
  805. //      if UpperCase(FHTMLDocument.selection.type_) = 'CONTROL' then
  806. //      begin
  807. //
  808. //        if (UpperCase((FoControlRange.item(0) as IHTMLElement).tagName) = 'INPUT') or
  809. //                  (UpperCase((FoControlRange.item(0) as IHTMLElement).tagName)='LABEL')  then
  810. //        begin
  811. //          FoControlRange := (FHTMLDocument.selection.createRange as IHTMLControlRange);
  812. //          FoControlRange.select;
  813. //          //FSelectedItem := ((FHTMLDocument.selection.createRange as
  814. //          //  IHTMLControlRange).item(0)) as IHTMLElement;
  815. //        end;
  816. //      end    // nothing - do not pass on the DialogKeys
  817. //    end
  818. //    else
  819. //    begin
  820. //      FoControlRange:=nil;
  821. //      FOleInPlaceActiveObject.TranslateAccelerator(Msg);
  822. //    end;
  823. //  end;
  824. //
  825. //  //本函数放在 Forms.Application.OnMessage := Self.OnMessage;
  826. // { if (msg.message = WM_RBUTTONDOWN) then
  827. //  begin
  828. //
  829. //    GetCursorPos(p);
  830. //    //取得当前鼠标的控件名。
  831. //    GetClassName(WindowFromPoint(p), TheName, 255);
  832. //    //todo: 禁用鼠标右键不行,因为标题会变
  833. //    if TheName = 'Internet Explorer_Server' then
  834. //    begin
  835. //      if Assigned(Self.PopupMenu) then
  836. //        Self.PopupMenu.Popup(P.X, P.Y);
  837. //      Handled := true;
  838. //    end;
  839. //  end;  }
  840. //
  841. //end; { THtmlEdit.OnMessage }
  842. procedure THtmlEdit.Paste;
  843. begin
  844.   {todo:
  845.   0. 先预处理 粘贴板, 如果是 位图 则先存为 jpg 后再上超联接
  846.   1. 判断事件存在,并粘贴板属于自己  GetClipboardOwner
  847.   2. 如果 文字 CF_TEXT、位图CF_BITMAP、元文件CF_METAFILEPICT
  848.   case of
  849.   CF_TEXT:
  850.   IF 超联接。。。
  851. }
  852.   Self.ExecWB(OLECMDID_PASTE, OLECMDEXECOPT_DODEFAULT); //13,
  853. end; { THtmlEdit.Paste }
  854. procedure THtmlEdit.Print(const APreview: Boolean = FALSE);
  855. begin
  856.   if APreview then
  857.     Self.ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DODEFAULT)
  858.   else
  859.     Self.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DODEFAULT);
  860. end; { THtmlEdit.Print }
  861. procedure THtmlEdit.PrintPageSetup;
  862. begin
  863.   Self.ExecWB(OLECMDID_PAGESETUP, OLECMDEXECOPT_DODEFAULT);
  864. end; { THtmlEdit.PrintPageSetup }
  865. procedure THtmlEdit.PrintPreview;
  866. begin
  867.   Self.ExecWB(OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DODEFAULT)
  868. end; { THtmlEdit.PrintPreview }
  869. procedure THtmlEdit.Redo;
  870. begin
  871.   Self.ExecWB(OLECMDID_REDO, OLECMDEXECOPT_DODEFAULT); //16,
  872. end; { THtmlEdit.Redo }
  873. procedure THtmlEdit.Save;
  874. begin
  875.   Self.ExecWB(OLECMDID_SAVE, OLECMDEXECOPT_DODEFAULT); //3,
  876. end; { THtmlEdit.Save }
  877. procedure THtmlEdit.SaveAs;
  878. begin
  879.   Self.ExecWB(OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT); //4,
  880. end; { THtmlEdit.SaveAs }
  881. procedure THtmlEdit.SaveToFile(const FileName: string);
  882. var
  883.   Stream: TStream;
  884. begin
  885.   Stream := TFileStream.Create(FileName, fmCreate);
  886.   try
  887.     SaveToStream(Stream);
  888.   finally
  889.     Stream.Free;
  890.   end;
  891. end; { THtmlEdit.SaveToFile }
  892. procedure THtmlEdit.SaveToStream(Stream: TStream);
  893. var
  894.   S: string;
  895. begin
  896.   S := string(Self.Html);
  897.   Stream.WriteBuffer(Pointer(S)^, Length(S));
  898. end; { THtmlEdit.SaveToStream }
  899. procedure THtmlEdit.SelectAll;
  900. begin
  901.   Self.ExecWB(OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT); //17,
  902. end; { THtmlEdit.SelectAll }
  903. procedure THtmlEdit.SetHTML(const Value: WideString);
  904. var
  905.   Html: Variant;
  906. begin
  907.   Html := VarArrayCreate([0, 0], varVariant);
  908.   Html[0] := Value;
  909.   FHTMLDocument.write(pSafearray(TVarData(Html).VArray));
  910. end; { THtmlEdit.SetHTML }
  911. procedure THtmlEdit.SetImageFolder(const Value: string);
  912. begin
  913.   FImageFolder := Value;
  914.   FEdit.FImageFolder := Value;
  915. end; { THtmlEdit.SetImageFolder }
  916. {procedure THtmlEdit.SetCharSet(ACharSet:String);
  917. var
  918.  RefreshLevel: OleVariant;
  919. Begin
  920.  IHTMLDocument2(Self.Document).Set_CharSet(ACharSet);
  921.  RefreshLevel :=7;              //这个7应该从注册表来,帮助有Bug。
  922.  Self.Refresh2(RefreshLevel);
  923. End; }
  924. procedure THtmlEdit.SetReadOnly(const Value: Boolean);
  925. begin
  926.   FReadOnly := Value;
  927.   if FReadOnly then
  928.     FHTMLDocument.designMode := 'Off' //非编辑模式
  929.   else
  930.     FHTMLDocument.designMode := 'On'; //编辑模式
  931. end; { THtmlEdit.SetReadOnly }
  932. procedure THtmlEdit.Undo;
  933. begin
  934.   Self.ExecWB(OLECMDID_UNDO, OLECMDEXECOPT_DODEFAULT); //15,
  935. end; { THtmlEdit.Undo }
  936. procedure THtmlEdit.Write(AHTML: string);
  937. begin
  938.   Self.New;
  939.   Self.OleObject.document.write(AHTML);
  940. end; { THtmlEdit.Write }
  941. procedure TEditCommander.FontName(const AFontName: string);
  942. begin
  943.   //FontName 设置或获取当前选中区的字体。
  944.   FHTMLDocument.execCommand('FontName', TRUE, '"' + AFontName + '"');
  945.   SetFocus;
  946. end;
  947. procedure TEditCommander.FontSize(const AFontSize: Integer);
  948. begin
  949.   //FontSize 设置或获取当前选中区的字体大小。
  950.   case AFontSize of
  951.     1..7: FHTMLDocument.execCommand('FontSize', TRUE, AFontSize);
  952.   else
  953.     FHTMLDocument.execCommand('FontSize', TRUE, 3);
  954.   end;
  955.   SetFocus;
  956. end;
  957. procedure THtmlEdit.SetCharSet(const Value: string);
  958. begin
  959.   FCharSet := Value;
  960.   FHTMLDocument.Set_CharSet(FCharSet);
  961. end;
  962. procedure THtmlEdit.Open(const AFileName: string);
  963. begin
  964.   LoadFromFile(AFileName);
  965. end;
  966. procedure THtmlEdit.SetFocus;
  967. begin
  968.   inherited;
  969.   FHTMLDocument.parentWindow.focus;
  970. end;
  971. procedure TEditCommander.SetFocus;
  972. begin
  973.   FHTMLDocument.parentWindow.focus;
  974. end;
  975. function THtmlEdit.CanFocus: Boolean;
  976. var
  977.   Control: TWinControl;
  978.   Form: TCustomForm;
  979. begin
  980.   Result := False;
  981.   Form := GetParentForm(Self);
  982.   if Form <> nil then
  983.   begin
  984.     Control := Self;
  985.     while Control <> Form do
  986.     begin
  987.       if not Control.Enabled then //修改
  988.       Exit;
  989.       Control := Control.Parent;
  990.     end;
  991.     Result := True;
  992.   end;
  993. end;
  994. procedure THtmlEdit.SearchText;
  995. const
  996.   CLSID_WebBrowser: TGUID = '{ED016940-BD5B-11cf-BA4E-00C04FD70816}';
  997. var
  998.   CmdTarget: IOleCommandTarget;
  999. begin
  1000.   try
  1001.     Self.Document.QueryInterface(IOleCommandTarget, CmdTarget);
  1002.     if CmdTarget <> nil then
  1003.     try
  1004.       CmdTarget.Exec(@CLSID_WebBrowser, 1, 0, EmptyParam, EmptyParam);
  1005.     finally
  1006.       CmdTarget._Release;
  1007.     end;
  1008.   except
  1009.   end;
  1010. end;
  1011. procedure TEditCommander.InsertH1(InnerText: string);
  1012. begin
  1013.   InsertHTML('<H1>'+InnerText+'</H1>');
  1014.   SetFocus;
  1015. end;
  1016. procedure TEditCommander.InsertH2(InnerText: string);
  1017. begin
  1018.   InsertHTML('<H2>'+InnerText+'</H2>');
  1019.   SetFocus;
  1020. end;
  1021. procedure TEditCommander.InsertH3;
  1022. begin
  1023.   InsertHTML('<H3>'+InnerText+'</H3>');
  1024.   SetFocus;
  1025. end;
  1026. procedure TEditCommander.InsertHr;
  1027. begin
  1028.   InsertHTML('<Hr/>');
  1029.   SetFocus;
  1030. end;
  1031. procedure TEditCommander.InsertDefinedList(List: TStrings);
  1032. var
  1033.   I,Count:Integer;
  1034.   S,sTemp:string;
  1035.   
  1036.   function TabCount(var S:String):Integer;
  1037.   begin
  1038.     Result:=0;
  1039.     if Length(S)=0 then Exit;
  1040.     while (Length(S)>0) and (S[1]=#9) do
  1041.     begin
  1042.        Inc(Result);
  1043.        S:=Copy(S,2,MAXWORD);
  1044.     end;
  1045.   end;
  1046. begin
  1047.   {
  1048.   <dl>
  1049. <dt>野生动物</dt>
  1050. <dd>所有非经人工饲养而生活于自然环境下的各种动物。</dd>
  1051. <dt>宠物</dt>
  1052. <dd>指猫、狗以及其它供玩赏、陪伴、领养、饲养的动物,又称作同伴动物。</dd>
  1053. </dl>
  1054.   }
  1055.   S:='<dl>';
  1056.   for I:=0 to List.Count-1 do
  1057.   begin
  1058.     sTemp:=List[I];
  1059.     Count:=TabCount(sTemp);
  1060.     if  Count=0 then
  1061.       S:=S+'<dt>'+sTemp+'</dt>'
  1062.     else if Count=1 then
  1063.       S:=S+'<dd>'+sTemp+'</dd>'
  1064.     else
  1065.       raise Exception.Create(SysUtils.Format('最多只有缩进一层的情况出现!而在第%D行发现了%D个Tab建。',[I,Count]));
  1066.     S:=S+'</dl>';
  1067.   end;
  1068.   InsertHTML(S);
  1069.   SetFocus;
  1070. end;
  1071. procedure TEditCommander.InsertOrderedList(List: TStrings; TypeChar: Char);
  1072. var
  1073.   S:string;
  1074.   I:Integer;
  1075. begin
  1076.   {
  1077.   <ol type="A">
  1078.   <li>布啦布啦之网页课程</li>
  1079.   <li>布啦布啦之网页代码</li>
  1080.   <li>布啦布啦之魔兽世界</li>
  1081.   </ol>
  1082.   }
  1083.   S:='<ol type="'+TypeChar+'"> ';
  1084.   for I:=0 to List.Count-1 do
  1085.      S:='<li>'+S+List[I]+'</li>';
  1086.   S:=S+'</ol>';
  1087.   InsertHTML(S);
  1088.   SetFocus;
  1089. end;
  1090. procedure TEditCommander.InsertUnorderedList(List: TStrings;
  1091.   UnorderedListType: TUnorderedListType);
  1092.   var
  1093.   S,Typechar:string;
  1094.   I:Integer;
  1095. begin
  1096.   {
  1097.   <ul type="square">
  1098. <li>布啦布啦之网页课程</li>
  1099. <li>布啦布啦之网页代码</li>
  1100. <li>布啦布啦之魔兽世界</li>
  1101. </ul>
  1102.   }
  1103.   case UnorderedListType of
  1104.     ultDisc: Typechar :='Disc';
  1105.     ultCricle: Typechar:='Cricle';
  1106.     ultSquare: Typechar:='Square';
  1107.   else ;
  1108.   end;
  1109.   S:='<ul type="'+TypeChar+'"> ';
  1110.   for I:=0 to List.Count-1 do
  1111.      S:='<li>'+S+List[I]+'</li>';
  1112.   S:=S+'</ul>';
  1113.   InsertHTML(S);
  1114.   SetFocus;
  1115. end;
  1116. procedure TEditCommander.InsertH4(InnerText: string);
  1117. begin
  1118.   InsertHTML('<H4>'+InnerText+'</H4>');
  1119.   SetFocus;
  1120. end;
  1121. procedure TEditCommander.InsertH5(InnerText: string);
  1122. begin
  1123.   InsertHTML('<H5>'+InnerText+'</H5>');
  1124.   SetFocus;
  1125. end;
  1126. procedure TEditCommander.InsertButton(Caption: string);
  1127. begin
  1128.   InsertHtml('<form><input type="button" value="'+Caption+'" /></Form>');
  1129.   SetFocus;
  1130. end;
  1131. procedure TEditCommander.InsertEdit(DefaultText: string);
  1132. begin
  1133.   InsertHtml('<form><input type="text" value="'+DefaultText+'" /></Form>');
  1134.   SetFocus;
  1135. end;
  1136. procedure TEditCommander.InsertLabel(Caption: string);
  1137. begin
  1138.   InsertHtml('<label >'+caption+'</label>');
  1139.   SetFocus;
  1140. end;
  1141. {procedure TEditCommander.InsertObject(const OuterHtml: WideString);
  1142. var
  1143.   Element:IHTMLDoMNode;
  1144. begin
  1145.   if Self.FHTMLDocument<>nil then
  1146.   begin                            
  1147.     Element:=IHTMLDoMNode(FHTMLDocument.createElement(''));
  1148.     IHTMLDOMNode(FHTMLDocument.body).appendChild(Element) ;
  1149.     IHTMLElement(Element).outerHTML:=OuterHtml;
  1150.   end;
  1151. end;  }
  1152. function THtmlEdit.GetModified: boolean;
  1153. begin
  1154.   Result:= self.FHTMLDocument.lastModified<>'';
  1155. end;
  1156. initialization
  1157.   OleInitialize(nil);
  1158. finalization
  1159.   try
  1160.     OleUninitialize;
  1161.   except
  1162.   end;
  1163. end.