理顺 JavaScript - 准备工具
2010-09-14 13:41:20 来源:WEB开发网本文示例源代码或素材下载
学 JavaScript 第一个头痛的问题就是 IDE, 微软的脚本编辑器还不错, 但好像不能独立安装; 还是自己做一个吧.
下载最简单的 JavaScript 测试工具. 此小工具可能会随时修改(最新修改时间: 2009-2-25 22:07), 下面是目前的效果图及源代码:
代码文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls, OleCtrls, SHDocVw, Menus;
type
TForm1 = class(TForm)
Panel1: TPanel;
Memo1: TMemo;
Splitter1: TSplitter;
WebBrowser1: TWebBrowser;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure N1Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses ActiveX;
procedure TForm1.FormCreate(Sender: TObject);
var
path: string;
begin
Text := 'JavaScriptTest';
Position := poDesktopCenter;
WebBrowser1.Navigate('about:blank');
Memo1.ScrollBars := ssBoth;
with Memo1.Font do begin
Name := 'Verdana';
Size := 10;
Color := $000080;
end;
path := ChangeFileExt(ParamStr(0),'.dat');
if FileExists(path) then
ReadComponentResFile(path, Memo1)
else with Memo1.Lines do begin
Clear;
Add('<html>');
Add('<head>');
Add('<title></title>');
Add('<script type="text/javascript">');
Add('alert("Hi");');
Add('</script>');
Add('</head>');
Add('<body>');
Add('JavaScript Test<hr>');
Add('Edit -> F5');
Add('</body>');
Add('</html>');
Self.Text := '编辑代码后用 F5 刷新显示';
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
WriteComponentResFile(ChangeFileExt(ParamStr(0),'.dat'), Memo1);
end;
procedure TForm1.N1Click(Sender: TObject);
var
ms: TMemoryStream;
begin
ms := TMemoryStream.Create;
Memo1.Lines.SaveToStream(ms);
ms.Position := 0;
(WebBrowser1.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms));
ms.Free;
end;
end.
Tags:理顺 JavaScript 准备
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接