学 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.
窗体文件:
object Form1: TForm1
Left = 0
Top = 0
ActiveControl = Memo1
Caption = 'Form1'
ClientHeight = 303
ClientWidth = 531
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Splitter1: TSplitter
Left = 289
Top = 0
Height = 303
MinSize = 1
ExplicitLeft = 219
ExplicitHeight = 196
end
object Memo1: TMemo
Left = 0
Top = 0
Width = 289
Height = 303
Align = alLeft
Lines.Strings = (
'Memo1')
PopupMenu = PopupMenu1
TabOrder = 0
ExplicitHeight = 340
end
object Panel1: TPanel
Left = 292
Top = 0
Width = 239
Height = 303
Align = alClient
BevelOuter = bvNone
Caption = 'Panel1'
TabOrder = 1
ExplicitLeft = 244
ExplicitWidth = 195
ExplicitHeight = 231
object WebBrowser1: TWebBrowser
Left = 0
Top = 0
Width = 239
Height = 303
Align = alClient
TabOrder = 0
ExplicitLeft = 88
ExplicitTop = 88
ExplicitWidth = 300
ExplicitHeight = 150
ControlData = {
4C000000B4180000511F00000000000000000000000000000000000000000000
000000004C000000000000000000000001000000E0D057007335CF11AE690800
2B2E126208000000000000004C0000000114020000000000C000000000000046
8000000000000000000000000000000000000000000000000000000000000000
00000000000000000100000000000000000000000000000000000000}
end
end
object PopupMenu1: TPopupMenu
AutoHotkeys = maManual
Left = 184
Top = 96
object N1: TMenuItem
Caption = #21047#26032
ShortCut = 116
OnClick = N1Click
end
end
end
浙公网安备 33010602011771号