unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, CM2GenInterface, Win32Dlg, comobj, ExtCtrls, CM2VISInterface,
  XPMan, ActnMan, ActnColorMaps;

Const
 TestPlugInClass: TGUID =
 // '{68239528-1274-4A75-B94E-3931D91A4037}'; // These needs to be loaded dynamicly in CM2
    '{3E3EBB94-F1D7-4954-914D-2CB8EEC303C1}';
 TestVisPlugInClass: TGUID =
  '{82072155-8366-4910-8BA3-8D4574DD4A09}';

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    ListBox1: TListBox;
    Button3: TButton;
    ListBox2: TListBox;
    Label1: TLabel;
    Timer1: TTimer;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Bevel1: TBevel;
    ComboBox1: TComboBox;
    Bevel2: TBevel;
    Label2: TLabel;
    Bevel3: TBevel;
    Label3: TLabel;
    XPManifest1: TXPManifest;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ListBox2DblClick(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
  private

  public
   PlugIn: ICM2GenPlug;
   VIS: ICM2VisPlug;
   Str: String;
   V: Extended;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
Var
 Sel: Integer;
 GUIDStr: String;
 GUID: TGUID;
begin
 Sel := Combobox1.ItemIndex;
 GUIDstr := combobox1.Items[sel];
 GUID := StringToGuid(GUIDStr);
 PlugIn := CreateComObject (GUID) as ICM2GenPlug;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 If PlugIn.Init = E_FAIL Then Warning('Failure');
end;

procedure TForm1.Button3Click(Sender: TObject);
Var
 Count, I: Integer;
 SensorName, InfoName, InfoVar: PChar;
begin
 If PlugIn.GetInfoCount(Count) = E_Fail then begin
  Warning('Failure - Get Info Count');
  exit;
 End;
 For I := 0 to Count - 1 do begin
  InfoName := '';
  InfoVar := '';
  If PlugIn.GetInfo(I, InfoName, InfoVar) = E_FAIL Then begin
   Warning('Failure - Get Info #' + IntToStr(I));
   Exit;
  End;
  Listbox1.Items.Add(InfoName + ' = ' + InfoVar);
 End;
 If PlugIn.GetSensorCount(Count) = E_Fail then begin
  Warning('Failure - Get Sensor Count');
  exit;
 End;
 For I := 0 to Count - 1 do begin
  SensorName := '';
  If PlugIn.GetSensorNameOnly(I, SensorName) = E_FAIL Then begin
   Warning('Failure - Get Sensor Name #' + IntToStr(I));
   Exit;
  End;
  Listbox2.Items.Add(SensorName);
 End;
end;

procedure TForm1.ListBox2DblClick(Sender: TObject);
Var
 S: String;
 Parameters: PChar;
 Sel: Integer;
 SensorName, SensorString: PChar;
 SensorValue: Double;
 IsNumeric: Boolean;
begin
 Sel := Listbox2.ItemIndex;
(* Case Sel of
  0: Begin*)
 If PlugIn.GetSensor(Sel, '', SensorName, IsNumeric, SensorString, SensorValue) = E_FAIL Then begin
  Warning('Failure');
  exit;
 End;
 If IsNumeric then Label1.caption := FloatTostr(SensorValue)
  else Label1.caption := SensorString;
 Str := SensorString;
 V := SensorValue;
 Button10.Click;
 Button11.Click;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
 Timer1.Enabled := true;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
 If PlugIn.Setup = E_FAIL then warning('Failure');
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
 VIS := CreateComObject (TestVISPlugInClass) as ICM2VisPlug;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
 If VIS.Init(GetDC(Form1.Handle)) = E_FAIL Then Warning('Failure - Init');
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
 If VIS.SetDimensions(Self.Bevel1.Left, Self.Bevel1.Top, Self.Bevel1.Height, Self.Bevel1.Width) = E_FAIL then warning('Failure');
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
 If VIS.Update(Pchar(Str), V) = E_FAIL Then begin
  Warning('Failure - Update');
  Exit;
 End;
end;

procedure TForm1.Button11Click(Sender: TObject);
begin
 If VIS.Redraw = E_FAIL Then begin
  Error('Failure - Redraw');
  exit;
 End;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
 If Vis.Terminating = E_FAIL Then begin
  Warning('Failure');
 End;
end;

end.
