DelphiのコードからFastScriptの変数の値を取得するには、TfsScriptのVariablesプロパティを使用します。
変数の値を取得する
val := fsScript1.Variables['i'];
変数の値を設定する
変数の値を設定することもできます。
fsScript1.Variables['i'] := 10;
##サンプルアプリケーション
次のプログラムでは1秒ごとに1行ずつ処理を進め、変数の値を表示します。
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;