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

📄 dxjsextradom.pas

📁 Well known and usefull component for delphi 7
💻 PAS
字号:
////////////////////////////////////////////////////////////////////////////
//    Component: TDXJSExtraDOM
//       Author: Alexander Baranovsky (ab@virtlabor.donbass.com)
//               G.E. Ozz Nixon Jr. (staff@bpdx.com)
// ========================================================================
// Source Owner: DX, Inc. 2002, 2004
//    Copyright: All code is the property of DX, Inc. Licensed for
//               resell by Brain Patchwork DX (tm) and part of the
//               DX (r) product lines, which are (c) 1999-2002
//               DX, Inc. Source may not be distributed without
//               written permission from both Brain Patchwork DX,
//               and DX, Inc.
//      License: (Reminder), None of this code can be added to other
//               developer products without permission. This includes
//               but not limited to DCU's, DCP's, DLL's, OCX's, or
//               any other form of merging our technologies. All of
//               your products released to a public consumer be it
//               shareware, freeware, commercial, etc. must contain a
//               license notification somewhere visible in the
//               application.
// Code Version: (3rd Generation)
// ========================================================================
//  Description: An extra component, the start of a DOCUMENT OBJECT MANAGER.
//
//  When time permits, I will try to get a group of us to work on synchronizing
//  support for THTML from David Baldwin at www.pbear.com as the under the
//  hood HTML section of the DOM.
// ========================================================================
////////////////////////////////////////////////////////////////////////////
unit DXJSExtraDOM;
interface

uses
  DXJavaScript,
  Forms,
  StdCtrls,
  Classes;

type
  TDXJSConsole = class(TForm)
      ConsoleMemo: TMemo;
  end;
  TDXJSExtraDOM = class(TComponent)
  private
    fConsole:TDXJSConsole;
    fJavaScript:TDXJavaScript;
  protected
    { Protected declarations }
    Procedure CreateConsole;
  public
    { Public declarations }
    constructor Create(AOwner:TComponent); override;
    destructor Destroy; override;
    Procedure Write(Const Output:String);
    Procedure Writeln(Const Output:String);
    Procedure RegisterWithJavaScript;
  published
    { Published declarations }
    Property JavaScript:TDXJavaScript read fJavaScript write fJavaScript;
  end;

implementation

Uses
   Controls,
   Graphics,
   SysUtils;

constructor TDXJSExtraDOM.Create(AOwner:TComponent);
Begin
   inherited Create(AOwner);
End;

Procedure TDXJSExtraDOM.CreateConsole;
Begin
   FConsole := TDXJSConsole.CreateNew(Nil);
   with FConsole do begin
      Top  := 50;
      Left := 50;
      Width := 600;
      Height:=300;
      Caption := 'Document Object';
      BorderStyle:=bsDialog;
   end;
   fConsole.ConsoleMemo := TMemo.Create(FConsole);
   with fConsole.ConsoleMemo do Begin
       Parent := TWinControl(FConsole);
       Align := alClient;
       Font.Name := 'Courier new';
       Font.Size := 10;
       Font.Color := clBlack;
       Brush.Color := clWhite;
       ReadOnly := true;
       BorderStyle:=bsNone;
  End;
End;

destructor TDXJSExtraDOM.Destroy;
Begin
   inherited Destroy;
End;

///////////////////////////////////////////////////////////////////////////////
// DXJavaScript Call back hooks!
// ============================================================================
// methods
///////////////////////////////////////////////////////////////////////////////
Procedure TDXJSExtraDOM.Write(Const Output:String);
Begin
  If Not Assigned(fConsole) then CreateConsole;
  fConsole.Show;
  fConsole.BringToFront;
  fConsole.ConsoleMemo.Lines.Text:=fConsole.ConsoleMemo.Lines.Text+Output;
End;

Procedure TDXJSExtraDOM.Writeln(Const Output:String);
Begin
   Write(Output+#13#10);
End;

Function __DOM_Write(Instance:TObject;const Parameters:array of Variant):Variant;
Var
   Loop:Integer;
   Output:String;
Begin
   Output:='';
   for Loop:=0 to Length(Parameters)-1 do
      Output:=Output+(TDXJavaScript.ToString(Parameters[Loop]));
   Output:=StringReplace(Output,'<br>',#13#10,[rfReplaceAll, rfIgnoreCase]);
   TDXJSExtraDOM(Instance).Write(Output);
End;

Function __DOM_Writeln(Instance:TObject;const Parameters:array of Variant):Variant;
Var
   Loop:Integer;
   Output:String;
Begin
   Output:='';
   for Loop:=0 to Length(Parameters)-1 do
      Output:=Output+(TDXJavaScript.ToString(Parameters[Loop]));
   Output:=StringReplace(Output,'<br>',#13#10,[rfReplaceAll, rfIgnoreCase]);
   TDXJSExtraDOM(Instance).Writeln(Output);
End;

///////////////////////////////////////////////////////////////////////////////
// assign these hooks to DXJavaScript
///////////////////////////////////////////////////////////////////////////////
Procedure TDXJSExtraDOM.RegisterWithJavaScript;
Begin
   if Assigned(fJavaScript) then Begin
// Constants (for some of the Properties)
      With fJavaScript do Begin
         AddMethod(TDXJSExtraDOM,'write', @__DOM_write);
         AddMethod(TDXJSExtraDOM,'writeln', @__DOM_writeln);
         AddObject('document', Self);
      End;
   End;
End;

end.

⌨️ 快捷键说明

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