Entwickeln benutzerdefinierter Anweisungen (FireDAC)

Aus RAD Studio
Wechseln zu: Navigation, Suche

Inhaltsverzeichnis

Beschreibung

Die Anweisungen zur Ausführungssteuerung von Skripten können um benutzerdefinierte Anweisungen erweitert werden. Den Quelltext von vorhandenen Anweisungen finden Sie in der Unit uADCompScriptCommands. Diese können Sie als Vorlage für eigene Anweisungen verwenden. Die Anweisungsklasse muss bei der Anweisungsregistrierung registriert werden. Beispielsweise kann die SPOOL-Anweisung verwendet werden:

 type
   TADSpoolScriptCommand = class(TFDScriptCommand)
   private
     FMode: Integer;
     FFileName: String;
     FAppend: Boolean;
   public
     class function Help(): String; override;
     class procedure Keywords(AKwds: TStrings); override;
     function Parse(const AKwd: String): Boolean; override;
     procedure Execute(); override;
     // -1 - off, 0 - show, 1 - file
     property Mode: Integer read FMode;
     property Append: Boolean read FAppend;
     property FileName: String read FFileName;
   end;
 
 {-------------------------------------------------------------------------------}
 class function TADSpoolScriptCommand.Help(): String;
 begin
   Result := '(SPOol | OUTput) [OFF|[APPend] <spool name>] - turns spooling off, print it status'#13#10 +
             '                                               or redirect it to the name';
 end;
 
 {-------------------------------------------------------------------------------}
 class procedure TADSpoolScriptCommand.Keywords(AKwds: TStrings);
 begin
   AKwds.Add('SPOol');
   AKwds.Add('OUTput');
 end;
 
 {-------------------------------------------------------------------------------}
 function TADSpoolScriptCommand.Parse(const AKwd: String): Boolean;
 var
   iLastBmk: Integer;
   ucS: string;
 begin
   iLastBmk := Parser.GetBookmark;
   ucS := Parser.GetUCWord;
   if ucS = 'OFF' then
     FMode := -1
   else if ucS = '' then
     FMode := 0
   else begin
     FMode := 1;
     FAppend := ADKeyWordMatch(ucS, 'APPEND', 3);
     if not FAppend then
       Parser.SetBookmark(iLastBmk);
     FFileName := Parser.GetLine();
     if FFileName = '' then
       FMode := -1;
   end;
   Result := True;
 end;
 
 {-------------------------------------------------------------------------------}
 procedure TADSpoolScriptCommand.Execute();
 begin
   case FMode of
   -1:
     begin
       Engine.ScriptOptions.SpoolOutput := smNone;
       EngineIntf.UpdateSpool;
     end;
    0:
     if Engine.ScriptOptions.SpoolOutput <> smNone then
       EngineIntf.ConPut('currently spooling to ' + Engine.ScriptOptions.SpoolFileName, soInfo)
     else
       EngineIntf.ConPut('not spooling currently', soInfo);
    1:
     begin
       if FAppend then
         Engine.ScriptOptions.SpoolOutput := smOnAppend
       else
         Engine.ScriptOptions.SpoolOutput := smOnReset;
       Engine.ScriptOptions.SpoolFileName := EngineIntf.ExpandString(FileName);
       EngineIntf.UpdateSpool;
     end;
   end;
 end;
 
 initialization
   ADScriptCommandRegistry().AddCommand(TADSpoolScriptCommand);