delphi 使用FastScript调试脚本  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 使用FastScript调试脚本


让我们创建一个应用程序来调试FastScript脚本。


执行脚本时,将调用TfsScript OnRunLine事件。
您可以从参数中看到要执行的代码。

procedure TForm1.fsScript1RunLine(Sender: TfsScript;
  const UnitName, SourcePos: string);
begin
  …
end;
可以使用fsPosToPoint函数将参数SourcePos转换为TPoint类型。
TPoint Y属性设置为行,X属性设置为字符位置。

uses
  fs_itools;
var
  p: TPoint;
begin
  p := fsPosToPoint(SourcePos);
通过在TfsSyntaxMemo组件的SetPos属性中设置获得的执行位置,可以将光标置于正在执行的代码的位置。

fsSyntaxMemo1.SetPos(p.X, p.Y);
通过将正在执行的行号设置为TfsSyntaxMemo组件的SetActiveLine方法,可以激活正在执行的行。

Dec(p.Y);
fsSyntaxMemo1.SetActiveLine(p.Y);
将布尔成员变量FExec添加到窗体。

type
  TForm1 = class(TForm)
  private
    FExec: Boolean;
等待脚本执行,直到成员变量FExec在fsScript1的OnRunLine事件中变为True为止。

FExec := False;
while not FExec do
begin
  Sleep(10);
  Application.ProcessMessages;
end;
fsScript1RunLine函数如下所示:

procedure TForm1.fsScript1RunLine(Sender: TfsScript;
  const UnitName, SourcePos: string);
var
  p: TPoint;
begin
  p := fsPosToPoint(SourcePos);
  fsSyntaxMemo1.SetPos(p.X, p.Y);
  Dec(p.Y);
  fsSyntaxMemo1.SetActiveLine(p.Y);
  fsSyntaxMemo1.SetFocus;

  FExec := False;
  while not FExec do
  begin
    Sleep(10);
    Application.ProcessMessages;
  end;
end;
当按下“下一步处理”按钮时,成员变量FExec设置为True。

procedure TForm1.Button2Click(Sender: TObject);
begin
  FExec := True;
end;
单击“取消”按钮时,将调用fsScript1的Terminate方法停止处理。

procedure TForm1.Button3Click(Sender: TObject);
begin
  fsScript1.Terminate;
end;


要从Delphi代码获取FastScript变量的值,请使用TfsScript变量属性。

获取变量的值
val := fsScript1.Variables['i'];
设置变量的值
您还可以设置变量的值。

fsScript1.Variables['i'] := 10;
##示例应用程序

在下面的程序中,该过程每秒处理一行,并显示变量的值。
procedure TForm1.fsScript1RunLine(Sender: TfsScript;
  const UnitName, SourcePos: string);
var
  P: TPoint;
  I: Integer;
  VariableName: string;
begin

  StatusBar1.SimpleText := SourcePos;
  P := fsPosToPoint(SourcePos);
  Dec(P.Y);
  fsSyntaxMemo1.SetActiveLine(P.Y);


  ValueListEditor1.Strings.BeginUpdate;
  try
    ValueListEditor1.Strings.Clear;
    for I := 0 to fsScript1.Count - 1 do
    begin
      if fsScript1.Items[I] is TfsVariable then
      begin
        VariableName := fsScript1.Items[I].Name;
        ValueListEditor1.Strings.Values[VariableName] :=
          fsScript1.Items[I].Value;
      end;
    end;
  finally
    ValueListEditor1.Strings.EndUpdate;
  end;

  // 1秒待機
  Sleep(1000);
  Application.ProcessMessages;
end;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.13553309440613 seconds