unit Aurelius.Plugin.LoadingForm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls,
  Aurelius.Plugin.Types,
  Aurelius.Plugin.Import,
  Aurelius.Plugin.Database,
  Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TfmLoading = class(TForm)
    pbRetrieveDictionary: TProgressBar;
    Label1: TLabel;
    Timer1: TTimer;
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
    FPluginConnection: IASPluginConnection;
    FDictionary: HDICTIONARY;
  public
    { Public declarations }
    constructor Create(APluginConnection: IASPluginConnection;
      ADictionary: HDICTIONARY); reintroduce;
  end;

var
  fmLoading: TfmLoading;

implementation

{$R *.dfm}

{ TfmLoading }

constructor TfmLoading.Create(APluginConnection: IASPluginConnection;
  ADictionary: HDICTIONARY);
begin
  inherited Create(nil);
  FDictionary := ADictionary;
  FPluginConnection := APluginConnection;
end;

procedure TfmLoading.FormShow(Sender: TObject);
begin
  pbRetrieveDictionary.Max := 1000;
  pbRetrieveDictionary.Step := 1;
  pbRetrieveDictionary.Position := 0;
end;

procedure TfmLoading.Timer1Timer(Sender: TObject);

  procedure OnProgress(Percentage: double; Data: Pointer); stdcall;
  begin
    TProgressBar(Data).Position := Round(Percentage * 1000);
    Application.ProcessMessages;
  end;

begin
  Timer1.Enabled := False;
  try
    PluginCheck(RetrieveDictionary(FPluginConnection, FDictionary, @OnProgress, pbRetrieveDictionary));
    ModalResult := mrOk;
  except
    ModalResult := mrAbort;
    raise;
  end;
end;

end.
