⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 查看html文件的控件
💻 PAS
字号:

{Demo to illustrate the use of the OnStreamRequest and OnImageRequest events
 with TFrameViewer.

 For the purpose of this demo, the streams are obtained from existing files,
 the demo.htm files in the C:\THTML(Demo) directory (assiming the default
 installation is used).

 Usage:

 Enter the Base path where the demo.htm files are located in the TEdit control
 and press "Load Demo.htm".
}

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, FramView, Readhtml;

type
  TForm1 = class(TForm)
    FrameViewer: TFrameViewer;
    Panel1: TPanel;
    LoadButton: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    procedure LoadButtonClick(Sender: TObject);
    procedure FrameViewerStreamRequest(Sender: TObject; const SRC: String;
      var Stream: TStream);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FrameViewerImageRequest(Sender: TObject; const SRC: String;
      var Stream: TMemoryStream);
  private
    { Private declarations }
    AStream: TMemoryStream;
    Base: string;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
{create general purpose Stream}
AStream := TMemoryStream.Create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
AStream.Free;
end;

procedure TForm1.LoadButtonClick(Sender: TObject);
begin
{read the Base}
Base := Edit1.Text;
{start with the "Load" method}
FrameViewer.Load('Demo.htm');
end;

procedure TForm1.FrameViewerStreamRequest(Sender: TObject;
  const SRC: String; var Stream: TStream);
{this is the OnStreamRequest handler}
var
  Name, S: string;
begin
if Pos(':', Src) = 0 then  {don't add Base if filename already complete}
  Name := Base+Src
else Name := Src;
try
  AStream.LoadFromFile(Name);
except
  S := 'Cannot load '+Name;
  AStream.Clear;
  AStream.Write(S[1], Length(S));
  end;
Stream := AStream;
end;

procedure TForm1.FrameViewerImageRequest(Sender: TObject;
  const SRC: String; var Stream: TMemoryStream);
{this is the OnImageRequest handler}  
var
  Name: string;
begin
if Pos(':', Src) = 0 then    {don't add Base if filename already complete}
  Name := Base+Src
else Name := Src;
try
  AStream.LoadFromFile(Base+Src);
  Stream := AStream;
except
  Stream := Nil;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -