home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 July / Chip_2002-07_cd1.bin / zkuste / delphi / kolekce / d3456 / AWSCRIPT.ZIP / awScript / d3 / aw_SCtrl.pas < prev    next >
Pascal/Delphi Source File  |  2002-04-12  |  19KB  |  739 lines

  1. unit aw_SCtrl;
  2.  
  3. {
  4.     The contents of this file are subject to the Mozilla Public License Version 1.1 (the
  5.     "License"); you may not use this file except in compliance with the License. You may
  6.     obtain a copy of the License at http://www.mozilla.org/MPL/
  7.  
  8.     Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
  9.     WARRANTY OF ANY KIND, either express or implied. See the License for the
  10.     specific language governing rights and limitations under the License.
  11.  
  12.     The Original Code is the ActiveX Scripting Components.
  13.  
  14.     The Initial Developer of the Original Code is Alexander Wingrove <awingrove@bigfoot.com>.
  15.     Portions created by Alexander Wingrove are Copyright (C) 1999-2002 Alexander Wingrove.
  16.     All Rights Reserved.
  17.  
  18.     Contributor(s):
  19.         Martijn van der Kooij <MKGal@geocities.com>
  20.         Winston R.S <winstone@centrin.net.id>
  21. }
  22.  
  23. {
  24.     unit: aw_SCtrl
  25.     version: 1.07, 12/04/2002
  26.     components:
  27.         TawScriptControl
  28.         TawScriptEditor
  29.         TawScriptErrorDlg
  30. }
  31.  
  32. interface
  33.  
  34. uses
  35.     Classes, Graphics, SysUtils, ComObj, ActiveX, AW_MSSC_TLB;
  36.  
  37. const
  38.     CRLF = #13#10;
  39.  
  40. {$I AW_SCTRL.INC}
  41.  
  42. type
  43.     TawScriptError = class(TObject)
  44.     private
  45.         FScriptError: IScriptError;
  46.         function Get_Number: Integer;
  47.         function Get_Source: WideString;
  48.         function Get_Description: WideString;
  49.         function Get_HelpFile: WideString;
  50.         function Get_HelpContext: Integer;
  51.         function Get_Text: WideString;
  52.         function Get_Line: Integer;
  53.         function Get_Column: Integer;
  54.     public
  55.         property Number: Integer read Get_Number;
  56.         property Source: WideString read Get_Source;
  57.         property Description: WideString read Get_Description;
  58.         property HelpFile: WideString read Get_HelpFile;
  59.         property HelpContext: Integer read Get_HelpContext;
  60.         property Text: WideString read Get_Text;
  61.         property Line: Integer read Get_Line;
  62.         property Column: Integer read Get_Column;
  63.     end;
  64.  
  65. { TawScriptControl }
  66.  
  67.     TawScriptControl = class;
  68.  
  69.     TawAutoObject = class(TCollectionItem)
  70.     private
  71.         FAutoObjectName: string;
  72.         FAutoObject: IDispatch;
  73.         procedure SetAutoObject(const Value: IDispatch);
  74.         procedure SetAutoObjectName(const Value: string);
  75.     public
  76.         constructor Create(Collection: TCollection); override;
  77.         procedure Assign(Source: TPersistent); override;
  78.  
  79.         property AutoObject: IDispatch read FAutoObject write SetAutoObject;
  80.     published
  81.         property AutoObjectName: string read FAutoObjectName write SetAutoObjectName;
  82.     end;
  83.  
  84.     TawAutoObjects = class(TCollection)
  85.     private
  86.         FScriptControl: TawScriptControl;
  87.         function GetItem(Index: Integer): TawAutoObject;
  88.         procedure SetItem(Index: Integer; Value: TawAutoObject);
  89.     protected
  90.         function GetOwner: TPersistent; override;
  91.         procedure Update(Item: TCollectionItem); override;
  92.     public
  93.         constructor Create(ScriptControl: TawScriptControl);
  94.         function Add: TawAutoObject;
  95.         property Items[Index: Integer]: TawAutoObject read GetItem write SetItem; default;
  96.     end;
  97.  
  98.     TawScriptControlErrorEvent = procedure (Sender: TObject;
  99.         Error: TawScriptError) of object;
  100.     TawScriptControlCallEvent = procedure (Sender: TObject;
  101.         const FunctionName: string; const Params: array of Variant) of object;
  102.  
  103.     TawScriptControl = class(TComponent)
  104.     private
  105.         FAllowUI: Boolean;
  106.         FAutoObjects: TawAutoObjects;
  107.         FCode: TStrings;
  108.         FLanguage: string;
  109.         FOnError: TawScriptControlErrorEvent;
  110.         FOnCallFunction: TawScriptControlCallEvent;
  111.         FOnTimeout: TNotifyEvent;
  112.         FScriptControl: TScriptControl;
  113.         FTimeout: integer;
  114.         function GetAllowUI: boolean;
  115.         function GetTimeout: integer;
  116.         procedure SetAllowUI(const Value: boolean);
  117.         procedure SetCode(const Value: TStrings);
  118.         procedure SetLanguage(const Value: string);
  119.         procedure SetTimeout(const Value: integer);
  120.         procedure SetAutoObjects(const Value: TawAutoObjects);
  121.     protected
  122.         procedure SCtrlOnError(Sender: TObject); virtual;
  123.         procedure SCtrlOnTimeout(Sender: TObject); virtual;
  124.         procedure CodeOnChange(Sender: TObject); virtual;
  125.         // 27/8/99 ACW - made UpdateAutoObjects a virtual proc
  126.         procedure UpdateAutoObjects; virtual;
  127.         procedure Loaded; override;
  128.     public
  129.         constructor Create(AOwner: TComponent); override;
  130.         destructor Destroy; override;
  131.         // 27/8/99 Winston R.S - this should return an OleVariant
  132.         function CallFunction(const FunctionName: string;
  133.             const Params: array of Variant): OleVariant;
  134.         procedure Clear;    // 27/8/99 ACW - Added clear method to clear code and objects
  135.         // 27/8/99 ACW - Added run-time property to allow access directly
  136.         // to the activex control.
  137.         property ActiveXScriptControl: TScriptControl read FScriptControl;
  138.     published
  139.         property AllowUI: boolean read GetAllowUI write SetAllowUI default True;
  140.         property Language: string read FLanguage write SetLanguage;
  141.         property AutoObjects: TawAutoObjects read FAutoObjects write SetAutoObjects;
  142.         property Code: TStrings read FCode write SetCode;
  143.         property Timeout: integer read GetTimeout write SetTimeout default 10000;
  144.  
  145.         property OnError: TawScriptControlErrorEvent read FOnError write FOnError;
  146.         property OnTimeout: TNotifyEvent read FOnTimeout write FOnTimeout;
  147.         // 27/8/99 ACW - Added new OnCall event
  148.         property OnCallFunction: TawScriptControlCallEvent
  149.             read FOnCallFunction write FOnCallFunction;
  150.     end;
  151.  
  152. { TawScriptEditor }
  153.  
  154.     TawScriptEditor = class(TComponent)
  155.     private
  156.         FCaption: string;
  157.         FCode: TStrings;
  158.         FFont: TFont;
  159.         FEditorFont: TFont;
  160.         FHeight: integer;
  161.         FIsOpen: boolean;
  162.         FLanguage: string;
  163.         FWidth: integer;
  164.         FOnChange: TNotifyEvent;
  165.         procedure SetCode(Value: TStrings);
  166.         procedure SetFont(Value: TFont);
  167.         procedure SetEditorFont(Value: TFont);
  168.     protected
  169.         procedure CreateEditWin;
  170.         procedure EditorFormDestroy(Sender: TObject);
  171.     public
  172.         constructor Create(AOwner: TComponent); override;
  173.         destructor Destroy; override;
  174.         procedure Show;
  175.         function ShowModal: integer; 
  176.         property IsOpen: boolean read FIsOpen;
  177.     published
  178.         property Caption: string read FCaption write FCaption;
  179.         property Code: TStrings read FCode write SetCode;
  180.         property EditorFont: TFont read FEditorFont write SetEditorFont;
  181.         property Font: TFont read FFont write SetFont;
  182.         property Height: integer read FHeight write FHeight default 0;
  183.         property Language: string read FLanguage write FLanguage;
  184.         property Width: integer read FWidth write FWidth default 0;
  185.         property OnChange: TNotifyEvent read FOnChange write FOnChange;
  186.     end;
  187.  
  188. { TawScriptErrorDlg }
  189.  
  190.     TawScriptErrorIcon = (eiInfo, eiError);
  191.  
  192.     TawScriptErrorDlg = class(TComponent)
  193.     private
  194.         FCaption: string;
  195.         FErrorFont: TFont;
  196.         FFont: TFont;
  197.         FHeight: integer;
  198.         FWidth: integer;
  199.         procedure SetErrorFont(const Value: TFont);
  200.         procedure SetFont(const Value: TFont);
  201.     public
  202.         constructor Create(AOwner: TComponent); override;
  203.         destructor Destroy; override;
  204.         procedure ShowModalMsg(Msg: string; Icon: TawScriptErrorIcon);
  205.         procedure ShowModalError(Error: TawScriptError);
  206.     published
  207.         property Caption: string read FCaption write FCaption;
  208.         property ErrorFont: TFont read FErrorFont write SetErrorFont;
  209.         property Font: TFont read FFont write SetFont;
  210.         property Height: integer read FHeight write FHeight default 150;
  211.         property Width: integer read FWidth write FWidth default 500;
  212.     end;
  213.  
  214. procedure Register;
  215.  
  216. implementation
  217.  
  218. // 17/06/99 - ACW - Added OleCtrls
  219. // 10/10/99 ACW used compiler defs to only use DsgnIntf on D4 or less 
  220. uses
  221. {$IFDEF AWD4L}
  222.     DsgnIntf,
  223. {$ENDIF}
  224.     Forms, aw_SEditor, aw_SError, OleCtrls;
  225.  
  226. { TawScriptError }
  227.  
  228. function TawScriptError.Get_Column: Integer;
  229. begin
  230.     Result := FScriptError.Column;
  231. end;
  232.  
  233. function TawScriptError.Get_Description: WideString;
  234. begin
  235.     Result := FScriptError.Description;
  236. end;
  237.  
  238. function TawScriptError.Get_HelpContext: Integer;
  239. begin
  240.     Result := FScriptError.HelpContext;
  241. end;
  242.  
  243. function TawScriptError.Get_HelpFile: WideString;
  244. begin
  245.     Result := FScriptError.HelpFile;
  246. end;
  247.  
  248. function TawScriptError.Get_Line: Integer;
  249. begin
  250.     Result := FScriptError.Line;
  251. end;
  252.  
  253. function TawScriptError.Get_Number: Integer;
  254. begin
  255.     Result := FScriptError.Number;
  256. end;
  257.  
  258. function TawScriptError.Get_Source: WideString;
  259. begin
  260.     Result := FScriptError.Source;
  261. end;
  262.  
  263. function TawScriptError.Get_Text: WideString;
  264. begin
  265.     Result := FScriptError.Text;
  266. end;
  267.  
  268.  
  269. { TawAutoObject }
  270.  
  271. constructor TawAutoObject.Create(Collection: TCollection);
  272. begin
  273.     FAutoObjectName := '';
  274.     FAutoObject := nil;
  275.     inherited Create(Collection);
  276. end;
  277.  
  278. procedure TawAutoObject.Assign(Source: TPersistent);
  279. begin
  280.     if Source is TawAutoObject then
  281.     begin
  282.         AutoObjectName := TawAutoObject(Source).AutoObjectName;
  283.         AutoObject := TawAutoObject(Source).AutoObject;
  284.         Changed(False);
  285.     end
  286.     else
  287.         inherited Assign(Source);
  288. end;
  289.  
  290. procedure TawAutoObject.SetAutoObject(const Value: IDispatch);
  291. begin
  292.     FAutoObject := Value;
  293.     Changed(False);
  294. end;
  295.  
  296. procedure TawAutoObject.SetAutoObjectName(const Value: string);
  297. begin
  298.     if FAutoObjectName <> Value then
  299.     begin
  300.         FAutoObjectName := Value;
  301.         Changed(False);
  302.     end;
  303. end;
  304.  
  305.  
  306. { TawAutoObjects }
  307.  
  308. constructor TawAutoObjects.Create(ScriptControl: TawScriptControl);
  309. begin
  310.     inherited Create(TawAutoObject);
  311.     FScriptControl := ScriptControl;
  312. end;
  313.  
  314. function TawAutoObjects.Add: TawAutoObject;
  315. begin
  316.     Result := TawAutoObject(inherited Add);
  317. end;
  318.  
  319. function TawAutoObjects.GetItem(Index: Integer): TawAutoObject;
  320. begin
  321.     Result := TawAutoObject(inherited GetItem(Index));
  322. end;
  323.  
  324. function TawAutoObjects.GetOwner: TPersistent;
  325. begin
  326.     Result := FScriptControl;
  327. end;
  328.  
  329. procedure TawAutoObjects.SetItem(Index: Integer; Value: TawAutoObject);
  330. begin
  331.     inherited SetItem(Index, Value);
  332. end;
  333.  
  334. procedure TawAutoObjects.Update(Item: TCollectionItem);
  335. begin
  336.     FScriptControl.UpdateAutoObjects;
  337. end;
  338.  
  339.  
  340. { TawScriptControl }
  341.  
  342. {
  343.     Create / Destroy
  344. }
  345.  
  346. constructor TawScriptControl.Create(AOwner: TComponent);
  347. begin
  348.     inherited;
  349.  
  350.     // 17/06/99 - Martijn van der Kooij, ACW
  351.     // Do class create bits first, then make sure that if
  352.     // TScriptControl.Create fails, it is handled.
  353.     FLanguage := 'JScript';
  354.     FAllowUI := True;
  355.     FTimeout := 10000;
  356.     FAutoObjects := TawAutoObjects.Create(self);
  357.  
  358.     FCode := TStringList.Create;
  359.     TStringList(FCode).OnChange := CodeOnChange;
  360.  
  361.     FScriptControl := nil;
  362.     if not (csDesigning in ComponentState) then
  363.     begin
  364.         try
  365.             FScriptControl := TScriptControl.Create(self);
  366.             FScriptControl.Language := 'JScript';
  367.             FScriptControl.OnError := SCtrlOnError;
  368.             FScriptControl.OnTimeout := SCtrlOnTimeout;
  369.             FScriptControl.AllowUI := True;
  370.             FScriptControl.Timeout := 10000;
  371.         except
  372.             // 28/11/99 ACW - changed our exception to include the message from this exception
  373.             on E:Exception do
  374.             begin
  375.                 // if create fails, make sure FScriptControl is nil and raise an exception
  376.                 FScriptControl := nil;
  377.                 raise EOleCtrlError.Create('Microsoft ActiveX Script Control create failed.'
  378.                     + #13#10 + E.Message);
  379.             end;
  380.         end;
  381.     end;
  382. end;
  383.  
  384. destructor TawScriptControl.Destroy;
  385. begin
  386. // ACW 10/10/99 Replaced this commented code with a Free to try and stop AV on exit
  387. {
  388.     if FScriptControl <> nil then
  389.     begin
  390.         if FScriptControl.Language <> '' then
  391.             FScriptControl.Reset;
  392.     end;
  393. }
  394.     FScriptControl.Free;
  395.     FCode.Free;
  396.  
  397.     inherited;
  398. end;
  399.  
  400.  
  401. {
  402.     Functions
  403. }
  404.  
  405. // call with standard Delphi array
  406. function TawScriptControl.CallFunction(const FunctionName: string;
  407.     const Params: array of Variant): OleVariant;
  408. var
  409.     l_args_arr: Variant;
  410.     l_args: PSafeArray;
  411.     l_high, i: integer;
  412. begin
  413.     if FScriptControl = nil then Exit;
  414.  
  415.     // 27/8/99 ACW - fire the OnCall event
  416.     if Assigned(FOnCallFunction) then FOnCallFunction(Self, FunctionName, Params); 
  417.  
  418.     // build array of values
  419.     l_high := High(Params);
  420.     l_args_arr := VarArrayCreate([0, l_high], varVariant);
  421.     for i := 0 to l_high do
  422.         l_args_arr[i] := Params[i];
  423.  
  424.     // convert to PSafeArray
  425.     l_args := PSafeArray(TVarData(l_args_arr).VArray);
  426.  
  427.     // call the function
  428.     Result := FScriptControl.Run(FunctionName, l_args);
  429. end;
  430.  
  431. procedure TawScriptControl.Clear;
  432. begin
  433.     // clear the code and objects, then update the script control 
  434.     FCode.Clear;
  435.     FAutoObjects.Clear;
  436.     UpdateAutoObjects;
  437. end;
  438.  
  439. procedure TawScriptControl.SCtrlOnError(Sender: TObject);
  440. var
  441.     l_error: TawScriptError;
  442. begin
  443.     if assigned(FOnError) then
  444.     begin
  445.         l_error := TawScriptError.Create;
  446.         l_error.FScriptError := FScriptControl.Error;
  447.  
  448.         FOnError(self, l_error);
  449.  
  450.         l_error.Free;
  451.     end;
  452. end;
  453.  
  454. procedure TawScriptControl.SCtrlOnTimeout(Sender: TObject);
  455. begin
  456.     if assigned(FOnTimeout) then
  457.         FOnTimeout(self);
  458. end;
  459.  
  460. procedure TawScriptControl.CodeOnChange(Sender: TObject);
  461. begin
  462.     // ACW 22/7/99 check that component is not loading before setting code
  463.     if (FScriptControl <> nil) and not (csLoading in ComponentState) then
  464.         FScriptControl.AddCode(Code.Text);
  465. end;
  466.  
  467. procedure TawScriptControl.UpdateAutoObjects;
  468. var
  469.     i: integer;
  470. begin
  471.     if FScriptControl <> nil then
  472.     begin
  473.         if FScriptControl.Language <> '' then
  474.         begin
  475.             FScriptControl.Reset;
  476.             FScriptControl.Language := FLanguage;
  477.         end;
  478.  
  479.         for i := 0 to AutoObjects.Count-1 do
  480.         begin
  481.             // if we have a valid object, add it in
  482.             if (AutoObjects[i].AutoObject <> nil) and
  483.                 (AutoObjects[i].AutoObjectName <> '') then
  484.             begin
  485.                 FScriptControl.AddObject(AutoObjects[i].AutoObjectName, AutoObjects[i].AutoObject, TRUE);
  486.             end;
  487.         end;
  488.  
  489.         FScriptControl.AddCode(Code.Text);
  490.     end;
  491. end;
  492.  
  493. procedure TawScriptControl.Loaded;
  494. begin
  495.     // ACW 26/7/99 forgot to call inherited
  496.     inherited;
  497.  
  498.     // ACW 22/7/99 Only load code into control once loaded
  499.     if (Code.Text <> '') and (FScriptControl <> nil) then
  500.     begin
  501.         FScriptControl.AddCode(Code.Text);
  502.     end;
  503. end;
  504.  
  505.  
  506. {
  507.     Properties
  508. }
  509.  
  510. function TawScriptControl.GetAllowUI: boolean;
  511. begin
  512.     Result := FAllowUI;
  513. end;
  514.  
  515. function TawScriptControl.GetTimeout: integer;
  516. begin
  517.     Result := FTimeout;
  518. end;
  519.  
  520. procedure TawScriptControl.SetAllowUI(const Value: boolean);
  521. begin
  522.     FAllowUI := Value;
  523.     if FScriptControl <> nil then
  524.         FScriptControl.AllowUI := Value;
  525. end;
  526.  
  527. procedure TawScriptControl.SetAutoObjects(const Value: TawAutoObjects);
  528. begin
  529.     FAutoObjects.Assign(Value);
  530. end;
  531.  
  532. procedure TawScriptControl.SetCode(const Value: TStrings);
  533. begin
  534.     FCode.Assign(Value);
  535.     // ACW 22/7/99 check that component is not loading before setting code
  536.     if (FScriptControl <> nil) and not (csLoading in ComponentState) then
  537.         FScriptControl.AddCode(Code.Text);
  538. end;
  539.  
  540. procedure TawScriptControl.SetLanguage(const Value: string);
  541. begin
  542.     if FLanguage <> Value then
  543.     begin
  544.         FLanguage := Value;
  545.         // ACW 22/7/99 only clear the code if we are not loading
  546.         if not (csLoading in ComponentState) then Code.Clear;
  547.  
  548.         if FScriptControl <> nil then
  549.         begin
  550.             FScriptControl.Language := FLanguage;
  551.             UpdateAutoObjects;
  552.             FScriptControl.AddCode(Code.Text);
  553.         end;
  554.     end;
  555. end;
  556.  
  557. procedure TawScriptControl.SetTimeout(const Value: integer);
  558. begin
  559.     if FTimeout <> Value then
  560.     begin
  561.         FTimeout := Value;
  562.         if FScriptControl <> nil then
  563.             FScriptControl.Timeout := Value;
  564.     end;
  565. end;
  566.  
  567.  
  568. { TawScriptEditor }
  569.  
  570. constructor TawScriptEditor.Create(AOwner: TComponent);
  571. begin
  572.     inherited;
  573.  
  574.     FCaption := 'Script Editor';
  575.     FHeight := 0;
  576.     FWidth := 0;
  577.     FEditorFont := TFont.Create;
  578.     FFont := TFont.Create;
  579.     FCode := TStringList.Create;
  580.     FIsOpen := False;
  581.  
  582.     if Owner is TForm then
  583.         FFont.Assign(TForm(Owner).Font);
  584.  
  585.     FEditorFont.Name := 'Courier New';
  586.     FEditorFont.Size := 8;
  587. end;
  588.  
  589. destructor TawScriptEditor.Destroy;
  590. begin
  591.     FEditorFont.Free;
  592.     FFont.Free;
  593.     FCode.Free;
  594.     inherited;
  595. end;
  596.  
  597. procedure TawScriptEditor.CreateEditWin;
  598. begin
  599.     FIsOpen := True;
  600.  
  601.     awScriptEditorForm := TawScriptEditorForm.Create(self);
  602.  
  603.     if (FWidth > 0) and (FHeight > 0) then
  604.     begin
  605.         awScriptEditorForm.Width := FWidth;
  606.         awScriptEditorForm.Height := FHeight;
  607.         awScriptEditorForm.Position := poDesigned;
  608.     end;
  609.  
  610.     awScriptEditorForm.Caption := FCaption;
  611.     awScriptEditorForm.Font := FFont;
  612.     awScriptEditorForm.Memo.Font := FEditorFont;
  613.  
  614.     awScriptEditorForm.OnDestroy := EditorFormDestroy;
  615.  
  616.     awScriptEditorForm.Open(FCode.Text, FLanguage);
  617. end;
  618.  
  619. procedure TawScriptEditor.Show;
  620. begin
  621.     CreateEditWin;
  622.     awScriptEditorForm.Show;
  623. end;
  624.  
  625. function TawScriptEditor.ShowModal: integer;
  626. begin
  627.     CreateEditWin;
  628.     Result := awScriptEditorForm.ShowModal;
  629. end;
  630.  
  631. procedure TawScriptEditor.SetCode(Value: TStrings);
  632. begin
  633.     FCode.Assign(Value);
  634. end;
  635.  
  636. procedure TawScriptEditor.SetEditorFont(Value: TFont);
  637. begin
  638.     FEditorFont.Assign(Value);
  639. end;
  640.  
  641. procedure TawScriptEditor.SetFont(Value: TFont);
  642. begin
  643.     FFont.Assign(Value);
  644. end;
  645.  
  646. procedure TawScriptEditor.EditorFormDestroy(Sender: TObject);
  647. begin
  648.     FIsOpen := False;
  649. end;
  650.  
  651. { TawScriptErrorDlg }
  652.  
  653. constructor TawScriptErrorDlg.Create(AOwner: TComponent);
  654. begin
  655.     inherited;
  656.  
  657.     FCaption := 'Script Error';
  658.     FWidth := 500;
  659.     FHeight := 150;
  660.     FFont := TFont.Create;
  661.     FErrorFont := TFont.Create;
  662.  
  663.     if Owner is TForm then
  664.         FFont.Assign(TForm(Owner).Font);
  665.  
  666.     FErrorFont.Name := 'Courier New';
  667.     FErrorFont.Size := 8;
  668. end;
  669.  
  670. destructor TawScriptErrorDlg.Destroy;
  671. begin
  672.     FFont.Free;
  673.     inherited;
  674. end;
  675.  
  676. procedure TawScriptErrorDlg.SetErrorFont(const Value: TFont);
  677. begin
  678.     FErrorFont.Assign(Value);
  679. end;
  680.  
  681. procedure TawScriptErrorDlg.SetFont(const Value: TFont);
  682. begin
  683.     FFont.Assign(Value);
  684. end;
  685.  
  686. procedure TawScriptErrorDlg.ShowModalMsg(Msg: string; Icon: TawScriptErrorIcon);
  687. begin
  688.     awScriptErrorForm := TawScriptErrorForm.Create(Application);
  689.     try
  690.         awScriptErrorForm.Width := FWidth;
  691.         awScriptErrorForm.Height := FHeight;
  692.         awScriptErrorForm.Font := FFont;
  693.         awScriptErrorForm.TextEdit.Font := FErrorFont;
  694.         awScriptErrorForm.Caption := FCaption;
  695.  
  696.         if Icon = eiInfo then
  697.         begin
  698.             awScriptErrorForm.InfoImage.Visible := True;
  699.             awScriptErrorForm.ErrorImage.Visible := False;
  700.         end
  701.         else begin
  702.             awScriptErrorForm.InfoImage.Visible := False;
  703.             awScriptErrorForm.ErrorImage.Visible := True;
  704.         end;
  705.  
  706.         awScriptErrorForm.TextEdit.Text := Msg;
  707.         awScriptErrorForm.ShowModal;
  708.     finally
  709.         awScriptErrorForm.Free;
  710.     end;
  711. end;
  712.  
  713. procedure TawScriptErrorDlg.ShowModalError(Error: TawScriptError);
  714. var
  715.     l_msg: string;
  716. begin
  717.     // 27/8/99 Winston R.S, ACW - Added error number to message
  718.     l_msg := Format(
  719.         '[%d] %s:' + CRLF +
  720.         '%s at line:%d, char:%d' + CRLF +
  721.         'near:%s',
  722.         [Error.Number, Error.Source, Error.Description, Error.Line,
  723.             Error.Column, Error.Text]);
  724.     ShowModalMsg(l_msg, eiError);
  725. end;
  726.  
  727.  
  728. {
  729.     Register
  730. }
  731.  
  732. procedure Register;
  733. begin
  734.     RegisterComponents('AW Controls',
  735.         [TawScriptControl, TawScriptEditor, TawScriptErrorDlg]);
  736. end;
  737.  
  738. end.
  739.