home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 July / Chip_2002-07_cd1.bin / zkuste / delphi / kolekce / d3456 / AWSCRIPT.ZIP / awScript / d6 / aw_SCtrl.pas < prev    next >
Pascal/Delphi Source File  |  2002-04-12  |  19KB  |  743 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. // 12/04/2002 ACW D6 requires the Variants unit. 
  221. uses
  222. {$IFDEF AWD4L}
  223.     DsgnIntf,
  224. {$ENDIF}
  225. {$IFDEF AWD6G}
  226.   Variants,
  227. {$ENDIF}
  228.     Forms, aw_SEditor, aw_SError, OleCtrls;
  229.  
  230. { TawScriptError }
  231.  
  232. function TawScriptError.Get_Column: Integer;
  233. begin
  234.     Result := FScriptError.Column;
  235. end;
  236.  
  237. function TawScriptError.Get_Description: WideString;
  238. begin
  239.     Result := FScriptError.Description;
  240. end;
  241.  
  242. function TawScriptError.Get_HelpContext: Integer;
  243. begin
  244.     Result := FScriptError.HelpContext;
  245. end;
  246.  
  247. function TawScriptError.Get_HelpFile: WideString;
  248. begin
  249.     Result := FScriptError.HelpFile;
  250. end;
  251.  
  252. function TawScriptError.Get_Line: Integer;
  253. begin
  254.     Result := FScriptError.Line;
  255. end;
  256.  
  257. function TawScriptError.Get_Number: Integer;
  258. begin
  259.     Result := FScriptError.Number;
  260. end;
  261.  
  262. function TawScriptError.Get_Source: WideString;
  263. begin
  264.     Result := FScriptError.Source;
  265. end;
  266.  
  267. function TawScriptError.Get_Text: WideString;
  268. begin
  269.     Result := FScriptError.Text;
  270. end;
  271.  
  272.  
  273. { TawAutoObject }
  274.  
  275. constructor TawAutoObject.Create(Collection: TCollection);
  276. begin
  277.     FAutoObjectName := '';
  278.     FAutoObject := nil;
  279.     inherited Create(Collection);
  280. end;
  281.  
  282. procedure TawAutoObject.Assign(Source: TPersistent);
  283. begin
  284.     if Source is TawAutoObject then
  285.     begin
  286.         AutoObjectName := TawAutoObject(Source).AutoObjectName;
  287.         AutoObject := TawAutoObject(Source).AutoObject;
  288.         Changed(False);
  289.     end
  290.     else
  291.         inherited Assign(Source);
  292. end;
  293.  
  294. procedure TawAutoObject.SetAutoObject(const Value: IDispatch);
  295. begin
  296.     FAutoObject := Value;
  297.     Changed(False);
  298. end;
  299.  
  300. procedure TawAutoObject.SetAutoObjectName(const Value: string);
  301. begin
  302.     if FAutoObjectName <> Value then
  303.     begin
  304.         FAutoObjectName := Value;
  305.         Changed(False);
  306.     end;
  307. end;
  308.  
  309.  
  310. { TawAutoObjects }
  311.  
  312. constructor TawAutoObjects.Create(ScriptControl: TawScriptControl);
  313. begin
  314.     inherited Create(TawAutoObject);
  315.     FScriptControl := ScriptControl;
  316. end;
  317.  
  318. function TawAutoObjects.Add: TawAutoObject;
  319. begin
  320.     Result := TawAutoObject(inherited Add);
  321. end;
  322.  
  323. function TawAutoObjects.GetItem(Index: Integer): TawAutoObject;
  324. begin
  325.     Result := TawAutoObject(inherited GetItem(Index));
  326. end;
  327.  
  328. function TawAutoObjects.GetOwner: TPersistent;
  329. begin
  330.     Result := FScriptControl;
  331. end;
  332.  
  333. procedure TawAutoObjects.SetItem(Index: Integer; Value: TawAutoObject);
  334. begin
  335.     inherited SetItem(Index, Value);
  336. end;
  337.  
  338. procedure TawAutoObjects.Update(Item: TCollectionItem);
  339. begin
  340.     FScriptControl.UpdateAutoObjects;
  341. end;
  342.  
  343.  
  344. { TawScriptControl }
  345.  
  346. {
  347.     Create / Destroy
  348. }
  349.  
  350. constructor TawScriptControl.Create(AOwner: TComponent);
  351. begin
  352.     inherited;
  353.  
  354.     // 17/06/99 - Martijn van der Kooij, ACW
  355.     // Do class create bits first, then make sure that if
  356.     // TScriptControl.Create fails, it is handled.
  357.     FLanguage := 'JScript';
  358.     FAllowUI := True;
  359.     FTimeout := 10000;
  360.     FAutoObjects := TawAutoObjects.Create(self);
  361.  
  362.     FCode := TStringList.Create;
  363.     TStringList(FCode).OnChange := CodeOnChange;
  364.  
  365.     FScriptControl := nil;
  366.     if not (csDesigning in ComponentState) then
  367.     begin
  368.         try
  369.             FScriptControl := TScriptControl.Create(self);
  370.             FScriptControl.Language := 'JScript';
  371.             FScriptControl.OnError := SCtrlOnError;
  372.             FScriptControl.OnTimeout := SCtrlOnTimeout;
  373.             FScriptControl.AllowUI := True;
  374.             FScriptControl.Timeout := 10000;
  375.         except
  376.             // 28/11/99 ACW - changed our exception to include the message from this exception
  377.             on E:Exception do
  378.             begin
  379.                 // if create fails, make sure FScriptControl is nil and raise an exception
  380.                 FScriptControl := nil;
  381.                 raise EOleCtrlError.Create('Microsoft ActiveX Script Control create failed.'
  382.                     + #13#10 + E.Message);
  383.             end;
  384.         end;
  385.     end;
  386. end;
  387.  
  388. destructor TawScriptControl.Destroy;
  389. begin
  390. // ACW 10/10/99 Replaced this commented code with a Free to try and stop AV on exit
  391. {
  392.     if FScriptControl <> nil then
  393.     begin
  394.         if FScriptControl.Language <> '' then
  395.             FScriptControl.Reset;
  396.     end;
  397. }
  398.     FScriptControl.Free;
  399.     FCode.Free;
  400.  
  401.     inherited;
  402. end;
  403.  
  404.  
  405. {
  406.     Functions
  407. }
  408.  
  409. // call with standard Delphi array
  410. function TawScriptControl.CallFunction(const FunctionName: string;
  411.     const Params: array of Variant): OleVariant;
  412. var
  413.     l_args_arr: Variant;
  414.     l_args: PSafeArray;
  415.     l_high, i: integer;
  416. begin
  417.     if FScriptControl = nil then Exit;
  418.  
  419.     // 27/8/99 ACW - fire the OnCall event
  420.     if Assigned(FOnCallFunction) then FOnCallFunction(Self, FunctionName, Params); 
  421.  
  422.     // build array of values
  423.     l_high := High(Params);
  424.     l_args_arr := VarArrayCreate([0, l_high], varVariant);
  425.     for i := 0 to l_high do
  426.         l_args_arr[i] := Params[i];
  427.  
  428.     // convert to PSafeArray
  429.     l_args := PSafeArray(TVarData(l_args_arr).VArray);
  430.  
  431.     // call the function
  432.     Result := FScriptControl.Run(FunctionName, l_args);
  433. end;
  434.  
  435. procedure TawScriptControl.Clear;
  436. begin
  437.     // clear the code and objects, then update the script control 
  438.     FCode.Clear;
  439.     FAutoObjects.Clear;
  440.     UpdateAutoObjects;
  441. end;
  442.  
  443. procedure TawScriptControl.SCtrlOnError(Sender: TObject);
  444. var
  445.     l_error: TawScriptError;
  446. begin
  447.     if assigned(FOnError) then
  448.     begin
  449.         l_error := TawScriptError.Create;
  450.         l_error.FScriptError := FScriptControl.Error;
  451.  
  452.         FOnError(self, l_error);
  453.  
  454.         l_error.Free;
  455.     end;
  456. end;
  457.  
  458. procedure TawScriptControl.SCtrlOnTimeout(Sender: TObject);
  459. begin
  460.     if assigned(FOnTimeout) then
  461.         FOnTimeout(self);
  462. end;
  463.  
  464. procedure TawScriptControl.CodeOnChange(Sender: TObject);
  465. begin
  466.     // ACW 22/7/99 check that component is not loading before setting code
  467.     if (FScriptControl <> nil) and not (csLoading in ComponentState) then
  468.         FScriptControl.AddCode(Code.Text);
  469. end;
  470.  
  471. procedure TawScriptControl.UpdateAutoObjects;
  472. var
  473.     i: integer;
  474. begin
  475.     if FScriptControl <> nil then
  476.     begin
  477.         if FScriptControl.Language <> '' then
  478.         begin
  479.             FScriptControl.Reset;
  480.             FScriptControl.Language := FLanguage;
  481.         end;
  482.  
  483.         for i := 0 to AutoObjects.Count-1 do
  484.         begin
  485.             // if we have a valid object, add it in
  486.             if (AutoObjects[i].AutoObject <> nil) and
  487.                 (AutoObjects[i].AutoObjectName <> '') then
  488.             begin
  489.                 FScriptControl.AddObject(AutoObjects[i].AutoObjectName, AutoObjects[i].AutoObject, TRUE);
  490.             end;
  491.         end;
  492.  
  493.         FScriptControl.AddCode(Code.Text);
  494.     end;
  495. end;
  496.  
  497. procedure TawScriptControl.Loaded;
  498. begin
  499.     // ACW 26/7/99 forgot to call inherited
  500.     inherited;
  501.  
  502.     // ACW 22/7/99 Only load code into control once loaded
  503.     if (Code.Text <> '') and (FScriptControl <> nil) then
  504.     begin
  505.         FScriptControl.AddCode(Code.Text);
  506.     end;
  507. end;
  508.  
  509.  
  510. {
  511.     Properties
  512. }
  513.  
  514. function TawScriptControl.GetAllowUI: boolean;
  515. begin
  516.     Result := FAllowUI;
  517. end;
  518.  
  519. function TawScriptControl.GetTimeout: integer;
  520. begin
  521.     Result := FTimeout;
  522. end;
  523.  
  524. procedure TawScriptControl.SetAllowUI(const Value: boolean);
  525. begin
  526.     FAllowUI := Value;
  527.     if FScriptControl <> nil then
  528.         FScriptControl.AllowUI := Value;
  529. end;
  530.  
  531. procedure TawScriptControl.SetAutoObjects(const Value: TawAutoObjects);
  532. begin
  533.     FAutoObjects.Assign(Value);
  534. end;
  535.  
  536. procedure TawScriptControl.SetCode(const Value: TStrings);
  537. begin
  538.     FCode.Assign(Value);
  539.     // ACW 22/7/99 check that component is not loading before setting code
  540.     if (FScriptControl <> nil) and not (csLoading in ComponentState) then
  541.         FScriptControl.AddCode(Code.Text);
  542. end;
  543.  
  544. procedure TawScriptControl.SetLanguage(const Value: string);
  545. begin
  546.     if FLanguage <> Value then
  547.     begin
  548.         FLanguage := Value;
  549.         // ACW 22/7/99 only clear the code if we are not loading
  550.         if not (csLoading in ComponentState) then Code.Clear;
  551.  
  552.         if FScriptControl <> nil then
  553.         begin
  554.             FScriptControl.Language := FLanguage;
  555.             UpdateAutoObjects;
  556.             FScriptControl.AddCode(Code.Text);
  557.         end;
  558.     end;
  559. end;
  560.  
  561. procedure TawScriptControl.SetTimeout(const Value: integer);
  562. begin
  563.     if FTimeout <> Value then
  564.     begin
  565.         FTimeout := Value;
  566.         if FScriptControl <> nil then
  567.             FScriptControl.Timeout := Value;
  568.     end;
  569. end;
  570.  
  571.  
  572. { TawScriptEditor }
  573.  
  574. constructor TawScriptEditor.Create(AOwner: TComponent);
  575. begin
  576.     inherited;
  577.  
  578.     FCaption := 'Script Editor';
  579.     FHeight := 0;
  580.     FWidth := 0;
  581.     FEditorFont := TFont.Create;
  582.     FFont := TFont.Create;
  583.     FCode := TStringList.Create;
  584.     FIsOpen := False;
  585.  
  586.     if Owner is TForm then
  587.         FFont.Assign(TForm(Owner).Font);
  588.  
  589.     FEditorFont.Name := 'Courier New';
  590.     FEditorFont.Size := 8;
  591. end;
  592.  
  593. destructor TawScriptEditor.Destroy;
  594. begin
  595.     FEditorFont.Free;
  596.     FFont.Free;
  597.     FCode.Free;
  598.     inherited;
  599. end;
  600.  
  601. procedure TawScriptEditor.CreateEditWin;
  602. begin
  603.     FIsOpen := True;
  604.  
  605.     awScriptEditorForm := TawScriptEditorForm.Create(self);
  606.  
  607.     if (FWidth > 0) and (FHeight > 0) then
  608.     begin
  609.         awScriptEditorForm.Width := FWidth;
  610.         awScriptEditorForm.Height := FHeight;
  611.         awScriptEditorForm.Position := poDesigned;
  612.     end;
  613.  
  614.     awScriptEditorForm.Caption := FCaption;
  615.     awScriptEditorForm.Font := FFont;
  616.     awScriptEditorForm.Memo.Font := FEditorFont;
  617.  
  618.     awScriptEditorForm.OnDestroy := EditorFormDestroy;
  619.  
  620.     awScriptEditorForm.Open(FCode.Text, FLanguage);
  621. end;
  622.  
  623. procedure TawScriptEditor.Show;
  624. begin
  625.     CreateEditWin;
  626.     awScriptEditorForm.Show;
  627. end;
  628.  
  629. function TawScriptEditor.ShowModal: integer;
  630. begin
  631.     CreateEditWin;
  632.     Result := awScriptEditorForm.ShowModal;
  633. end;
  634.  
  635. procedure TawScriptEditor.SetCode(Value: TStrings);
  636. begin
  637.     FCode.Assign(Value);
  638. end;
  639.  
  640. procedure TawScriptEditor.SetEditorFont(Value: TFont);
  641. begin
  642.     FEditorFont.Assign(Value);
  643. end;
  644.  
  645. procedure TawScriptEditor.SetFont(Value: TFont);
  646. begin
  647.     FFont.Assign(Value);
  648. end;
  649.  
  650. procedure TawScriptEditor.EditorFormDestroy(Sender: TObject);
  651. begin
  652.     FIsOpen := False;
  653. end;
  654.  
  655. { TawScriptErrorDlg }
  656.  
  657. constructor TawScriptErrorDlg.Create(AOwner: TComponent);
  658. begin
  659.     inherited;
  660.  
  661.     FCaption := 'Script Error';
  662.     FWidth := 500;
  663.     FHeight := 150;
  664.     FFont := TFont.Create;
  665.     FErrorFont := TFont.Create;
  666.  
  667.     if Owner is TForm then
  668.         FFont.Assign(TForm(Owner).Font);
  669.  
  670.     FErrorFont.Name := 'Courier New';
  671.     FErrorFont.Size := 8;
  672. end;
  673.  
  674. destructor TawScriptErrorDlg.Destroy;
  675. begin
  676.     FFont.Free;
  677.     inherited;
  678. end;
  679.  
  680. procedure TawScriptErrorDlg.SetErrorFont(const Value: TFont);
  681. begin
  682.     FErrorFont.Assign(Value);
  683. end;
  684.  
  685. procedure TawScriptErrorDlg.SetFont(const Value: TFont);
  686. begin
  687.     FFont.Assign(Value);
  688. end;
  689.  
  690. procedure TawScriptErrorDlg.ShowModalMsg(Msg: string; Icon: TawScriptErrorIcon);
  691. begin
  692.     awScriptErrorForm := TawScriptErrorForm.Create(Application);
  693.     try
  694.         awScriptErrorForm.Width := FWidth;
  695.         awScriptErrorForm.Height := FHeight;
  696.         awScriptErrorForm.Font := FFont;
  697.         awScriptErrorForm.TextEdit.Font := FErrorFont;
  698.         awScriptErrorForm.Caption := FCaption;
  699.  
  700.         if Icon = eiInfo then
  701.         begin
  702.             awScriptErrorForm.InfoImage.Visible := True;
  703.             awScriptErrorForm.ErrorImage.Visible := False;
  704.         end
  705.         else begin
  706.             awScriptErrorForm.InfoImage.Visible := False;
  707.             awScriptErrorForm.ErrorImage.Visible := True;
  708.         end;
  709.  
  710.         awScriptErrorForm.TextEdit.Text := Msg;
  711.         awScriptErrorForm.ShowModal;
  712.     finally
  713.         awScriptErrorForm.Free;
  714.     end;
  715. end;
  716.  
  717. procedure TawScriptErrorDlg.ShowModalError(Error: TawScriptError);
  718. var
  719.     l_msg: string;
  720. begin
  721.     // 27/8/99 Winston R.S, ACW - Added error number to message
  722.     l_msg := Format(
  723.         '[%d] %s:' + CRLF +
  724.         '%s at line:%d, char:%d' + CRLF +
  725.         'near:%s',
  726.         [Error.Number, Error.Source, Error.Description, Error.Line,
  727.             Error.Column, Error.Text]);
  728.     ShowModalMsg(l_msg, eiError);
  729. end;
  730.  
  731.  
  732. {
  733.     Register
  734. }
  735.  
  736. procedure Register;
  737. begin
  738.     RegisterComponents('AW Controls',
  739.         [TawScriptControl, TawScriptEditor, TawScriptErrorDlg]);
  740. end;
  741.  
  742. end.
  743.