unit uOSMarkResults;
{
  COSBI: Comprehensive Open Source Benchmarking Initiative
  Copyright (c) 2004 Van Smith

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  The current web address of the GNU General Public License is:
  http://www.gnu.org/licenses/gpl.html

  You can contact the authors of this software at:
  cosbi@vanshardware.com
  See www.vanshardware.com or www.cosbi.org for more contact details.
}

//==============================================================================
// Unit name: uOSMarkResults
// Unit description: This unit houses the OSMark Result Viewer
// Author: Van Smith
// Date: February 6, 2004
// OS dependent: Yes: Windows
// Resolution dependent: >= 1024x768
// External unit dependencies: ufrmFilter, jpeg, midaslib
//==============================================================================
// Modification History
// ------------ -------
// Ver  Date   Who    Description
// ==== ====== ====== ==========================================================
// 1.0 020604 Van     Created.
//==============================================================================

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeEngine, Series, ExtCtrls, TeeProcs, Chart, StdCtrls, Grids,
  DBGrids, DB, DBClient, DbChart, midaslib, DBCtrls, ufrmFilter, jpeg,
  uCOSBI_SystemInfo, uOSMarkSuite, uCOSBI_TTest, COSBI_Common,
  ufrmExportResults, IniFiles;

type
  TfrmOSMResults = class(TForm)
    DBChartResults: TDBChart;
    dsResults: TDataSource;
    Series22: TBarSeries;
    DBGridResults: TDBGrid;
    Series23: TBarSeries;
    Series24: TBarSeries;
    Series25: TBarSeries;
    Series26: TBarSeries;
    Series27: TBarSeries;
    Series28: TBarSeries;
    Series29: TBarSeries;
    Series30: TBarSeries;
    Series31: TBarSeries;
    Series32: TBarSeries;
    Series33: TBarSeries;
    Series34: TBarSeries;
    Series35: TBarSeries;
    Series36: TBarSeries;
    Series37: TBarSeries;
    Series38: TBarSeries;
    Series39: TBarSeries;
    Series40: TBarSeries;
    Series1: TBarSeries;
    Series2: TBarSeries;
    cdsResults: TClientDataSet;
    Series3: TBarSeries;
    Series4: TBarSeries;
    Series5: TBarSeries;
    Series6: TBarSeries;
    Series7: TBarSeries;
    Series8: TBarSeries;
    Series9: TBarSeries;
    Series10: TBarSeries;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    OpenDialogBGImage: TOpenDialog;
    PrintDialog1: TPrintDialog;
    Panel1: TPanel;
    btnSave: TButton;
    btnImport: TButton;
    btnCopy: TButton;
    btnLoad: TButton;
    btnFilter: TButton;
    btnDefaultFilter: TButton;
    btnShowAll: TButton;
    btnExport: TButton;
    btnLoadBGImage: TButton;
    btnNoImage: TButton;
    btnStretch: TButton;
    DBNavigator1: TDBNavigator;
    btnSaveGraph: TButton;
    btnPrintGraph: TButton;
    btnUnZoom: TButton;
    Button1: TButton;
    Series11: TBarSeries;
    Series12: TBarSeries;
    Series13: TBarSeries;
    Series14: TBarSeries;
    Series15: TBarSeries;
    Series16: TBarSeries;
    Series17: TBarSeries;
    Series18: TBarSeries;
    Series19: TBarSeries;
    Series20: TBarSeries;
    procedure btnSaveClick(Sender: TObject);
    procedure btnImportClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnCopyClick(Sender: TObject);
    procedure btnLoadClick(Sender: TObject);
    procedure DBGridResultsTitleClick(Column: TColumn);
    procedure DBChartResultsClickSeries(Sender: TCustomChart;
      Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure btnFilterClick(Sender: TObject);
    procedure btnShowAllClick(Sender: TObject);
    procedure btnLoadBGImageClick(Sender: TObject);
    procedure btnNoImageClick(Sender: TObject);
    procedure btnStretchClick(Sender: TObject);
//    procedure btnStackedClick(Sender: TObject);
    procedure btnSaveGraphClick(Sender: TObject);
    procedure btnPrintGraphClick(Sender: TObject);
    procedure btnExportClick(Sender: TObject);
    procedure btnUnZoomClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
  private
    { Private declarations }
    fShowingAllSeries : Boolean;
    fNeedToSave : Boolean;
    fOSMarkTestResults    : TOSMarkTestResults;
    fDefaultDatabaseFileName : string;
    fAppFilePath : string;
    fBackgroundImage : string;
    procedure CreateDataset;
    procedure ResizeGridColumns;
    procedure SetOSMarkTestResults( Value : TOSMarkTestResults );
    procedure ReadIniFile;
    procedure WriteIniFile;
  public
    { Public declarations }
    procedure AppendDatasetFromFile( asFileName : string );
    procedure SaveToXML(asFileName: string);
    procedure LoadFromXML(asFileName: string);
    procedure LoadFromXMLBrowse;
    procedure LoadBackgroundImage(asFilename : string);
    procedure LoadBackgroundImageBrowse;
    property OSMarkTestResults : TOSMarkTestResults
                           read fOSMarkTestResults
                           write SetOSMarkTestResults;
    procedure AddNewResults(AOSMarkTestResults: TOSMarkTestResults);
    procedure LoadDefaultDatabase;
  end;

var
  frmOSMResults: TfrmOSMResults;

const
  RESULTS_FILE_NAME = '\osmfiles\osmresults.xml';
  CHART_TITLE = 'OSMark Score Comparison';
  DEFAULT_FILTER = '';
  DEFAULT_INDEX = 'DateTime';
  DEFAULT_BACKGROUND_IMAGE = '\osmfiles\COSBI_50percentLight2.jpg';

implementation

{$R *.dfm}

procedure TfrmOSMResults.ReadIniFile;
var
  Ini: TIniFile;
  lbBGImageStretch : Boolean;
  procedure LoadDefaultBackgroundImage;
  begin
    LoadBackgroundImage( ExtractFilePath( Application.ExeName ) +  DEFAULT_BACKGROUND_IMAGE );
  end; // procedure LoadDefaultBackgroundImage;
begin
  Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.INI' ) );
  try
    // read settings
    cdsResults.Filter :=
      Ini.ReadString( 'ResultViewer', 'Filter', DEFAULT_FILTER );
    cdsResults.IndexFieldNames :=
      Ini.ReadString( 'ResultViewer', 'IndexFieldNames', DEFAULT_INDEX );
    fBackgroundImage := trim(
      Ini.ReadString( 'ResultViewer', 'BackgroundImage', DEFAULT_BACKGROUND_IMAGE )
      );
    try
      // if there is a background image
      if fBackgroundImage <> '' then begin
        if fBackgroundImage = DEFAULT_BACKGROUND_IMAGE then begin
          LoadDefaultBackgroundImage;
        end else begin
          LoadBackgroundImage( fBackgroundImage );
        end; // if
        lbBGImageStretch :=
          Ini.ReadBool( 'ResultViewer', 'BackImageStretch', TRUE );
        if lbBGImageStretch then begin
          DBChartResults.BackImageMode := pbmStretch;
        end else begin
          DBChartResults.BackImageMode := pbmCenter;
        end; // if
      end; // if
    except
      // swallow exception
      DBChartResults.BackImage.Bitmap.FreeImage;
      fBackgroundImage := '';
    end; //
    DBChartResults.RefreshData;
  finally
    FreeAndNil( Ini );
  end; // try..finally
end; // procedure TfrmOSMResults.ReadIniFile

procedure TfrmOSMResults.WriteIniFile;
var
  Ini: TIniFile;
begin
  Ini := TIniFile.Create( ChangeFileExt( Application.ExeName, '.INI' ) );
  try
    // write settings
    Ini.WriteString( 'ResultViewer', 'Filter', cdsResults.Filter );
    Ini.WriteString( 'ResultViewer', 'IndexFieldNames', cdsResults.IndexFieldNames );
    Ini.WriteString( 'ResultViewer', 'BackgroundImage', fBackgroundImage );
    if ( DBChartResults.BackImageMode = pbmStretch ) then begin
      Ini.WriteBool( 'ResultViewer', 'BackImageStretch', TRUE );
    end else begin
      Ini.WriteBool( 'ResultViewer', 'BackImageStretch', FALSE );
    end; // if
  finally
    FreeAndNil( Ini );
  end; // try..finally
end; // procedure TfrmOSMResults.WriteIniFile;

procedure TfrmOSMResults.CreateDataset;
begin
  cdsResults.Active := FALSE;
  cdsResults.FieldDefs.Clear;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'PlatformName';
    DataType := ftString;
    Size := 100;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'DateTime';
    DataType := ftDateTime;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'CPU';
    DataType := ftString;
    Size := 64;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'CPUVendor';
    DataType := ftString;
    Size := 32;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'CPUFamily';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'CPUModel';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'CPUStepping';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'CPUWinMHz';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'CPUClockSpeed';
    DataType := ftLargeInt; //Float; //ftCurrency;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'CPUFSB';
    DataType := ftLargeint;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'CPU Count';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Virtual CPU Count';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'L1 Data';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'L1 Instruction';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Trace Cache';
    DataType := ftString;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'L2';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'L3';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Chipset';
    DataType := ftString;
    Size := 32;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Chipset Driver';
    DataType := ftString;
    Size := 32;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Graphics Adapter';
    DataType := ftString;
    Size := 32;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Graphics Driver';
    DataType := ftString;
    Size := 32;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Memory Type';
    DataType := ftString;
    Size := 32;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Memory Speed';
    DataType := ftLargeint;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Memory Amount';
    DataType := ftLargeint;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Hard Drive';
    DataType := ftString;
    Size := 64;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Motherboard';
    DataType := ftString;
    Size := 64;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Motherboard BIOS';
    DataType := ftString;
    Size := 64;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Video Resolution';
    DataType := ftString;
    Size := 32;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'OS';
    DataType := ftString;
    Size := 32;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'OSVersion';
    DataType := ftString;
    Size := 32;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'OSBuild';
    DataType := ftString;
    Size := 32;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'GridBlast';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'GridBlastFP';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'FibThreads';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'nBody';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'PiThreads';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'PlotTrig';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'PlotTrig2';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'PlotLines';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'RandomDots';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Mandelbrot';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Circles';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Mazes';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'FernFractal';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'RichEdit';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Ellipses';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'CalculatePi';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'DhrystoneThreads';
    DataType := ftFloat;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'WhetstoneThreads';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'MazeThreads';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Rectangles';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'BandwidthBP64';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'MemLatency';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'OThreads';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'IThreads';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Lines';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'JpgDecode';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'ImageResize';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'ImageRotate';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'Mp3Encode';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'WebPageLoad';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'ZipCompress';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'EncryptDecrypt';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'FileCopy';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'LorenzAttractor';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'NBodyOpenGL';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'PNGOut';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := '7zip';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'UPX';
    DataType := ftInteger;
    Required := False;
  end;
  with cdsResults.FieldDefs.AddFieldDef do begin
    Name := 'OSMark';
    DataType := ftInteger;
    Required := False;
  end;
  cdsResults.CreateDataSet;
end;

procedure TfrmOSMResults.AppendDatasetFromFile( asFileName : string );
var
  lTextFile : TextFile;
  lsTemp : string;
begin
  AssignFile( lTextFile, asFileName );
  try
    Reset( lTextFile );
    cdsResults.Append;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('PlatformName').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('DateTime').AsDateTime := StrToDateTime( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('CPU').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('CPUVendor').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('CPUFamily').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('CPUModel').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('CPUStepping').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('CPUWinMHz').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('CPUClockSpeed').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('CPUFSB').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('CPU Count').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Virtual CPU Count').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('L1 Data').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('L1 Instruction').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Trace Cache').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('L2').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('L3').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Chipset').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Chipset Driver').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Graphics Adapter').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Graphics Driver').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Memory Type').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Memory Speed').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Memory Amount').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Hard Drive').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Motherboard').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Motherboard BIOS').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Video Resolution').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('OS').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('OSVersion').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('OSBuild').AsString := lsTemp;
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('GridBlast').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('GridBlastFP').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('FibThreads').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('nBody').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('PiThreads').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('PlotTrig').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('PlotTrig2').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('PlotLines').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('RandomDots').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Mandelbrot').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Circles').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Mazes').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('FernFractal').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('RichEdit').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Ellipses').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('CalculatePi').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('DhrystoneThreads').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('WhetstoneThreads').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('MazeThreads').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Rectangles').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('BandwidthBP64').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('MemLatency').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('OThreads').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('IThreads').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Lines').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('JpgDecode').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('ImageResize').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('ImageRotate').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('MP3Encode').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('WebPageLoad').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('ZipCompress').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('EncryptDecrypt').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('FileCopy').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('LorenzAttractor').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('NBodyOpenGL').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('PNGOut').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('7zip').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('Upx').AsInteger := StrToInt( lsTemp );
    ReadLn( lTextFile, lsTemp );
    cdsResults.FieldByName('OSMark').AsInteger := StrToInt( lsTemp );
    cdsResults.Post;
  finally
    CloseFile( lTextFile );
  end; // try
end; // procedure TForm1.AppendDatasetFromFile

procedure TfrmOSMResults.btnSaveClick(Sender: TObject);
var
  lsFileName : string;
begin
  lsFileName := ExtractFilePath(Application.ExeName) + RESULTS_FILE_NAME;
  SaveToXML( lsFileName );
  fNeedToSave := FALSE;
end;

procedure TfrmOSMResults.btnImportClick(Sender: TObject);
begin
  OpenDialog1.Filter := 'Text files (*.txt)|*.txt';
  if OpenDialog1.Execute then begin
    AppendDatasetFromFile( OpenDialog1.FileName );
    fNeedToSave := TRUE;
  end;
end; // procedure TfrmOSMResults.btnImportClick(Sender: TObject);

procedure TfrmOSMResults.FormCreate(Sender: TObject);
begin
  fAppFilePath := ExtractFilePath( application.ExeName );
  fDefaultDatabaseFileName := fAppFilePath + 'osmfiles\osmresults.xml';
  CreateDataset;
  ResizeGridColumns;
  fShowingAllSeries := TRUE;
  fNeedToSave := FALSE;
  ReadIniFile;
end; //procedure TfrmOSMResults.FormCreate(Sender: TObject);

procedure TfrmOSMResults.SetOSMarkTestResults( Value : TOSMarkTestResults );
begin
  fOSMarkTestResults := Value;
  LoadDefaultDatabase;
  AddNewResults( fOSMarkTestResults );
  fNeedToSave := TRUE;
end; // procedure TfrmOSMResults.SetOSMarkTestResults


procedure TfrmOSMResults.btnCopyClick(Sender: TObject);
begin
  DBChartResults.CopyToClipboardBitmap;
end;

procedure TfrmOSMResults.btnLoadClick(Sender: TObject);
begin
  //lsFileName := ExtractFilePath(Application.ExeName) + RESULTS_FILE_NAME;
  LoadFromXMLBrowse; //( lsFileName );
end;

procedure TfrmOSMResults.ResizeGridColumns;
var
  i : integer;
begin
  for i := 0 to DBGridResults.Columns.Count - 1 do begin
    DBGridResults.Columns[i].Width := 80;
  end; // for
  cdsResults.IndexFieldNames := DEFAULT_INDEX;
end; // procedure TfrmOSMResults.ResizeFields;

procedure TfrmOSMResults.DBGridResultsTitleClick(Column: TColumn);
var
  i : integer;
  lsFieldName : string;

  function ThisIsAResultField : Boolean;
  var
    i : integer;
  begin
    result := FALSE;
    for i := 0 to DBChartResults.SeriesCount - 1 do begin
      if lowercase( DBChartResults.SeriesList[i].YValues.ValueSource ) = lsFieldName then begin
        result := TRUE;
        exit;
      end; // if
    end; // for
  end; // function
begin
  lsFieldName := lowerCase( Column.Field.FieldName );
  if ThisIsAResultField then begin
    if fShowingAllSeries then begin
      DBChartResults.Legend.Visible := FALSE;
      // we need to loop through all series and make them invisible except for the
      // series that was clicked.
      for i := 0 to DBChartResults.SeriesCount - 1 do begin
        if lowerCase( DBChartResults.SeriesList[i].YValues.ValueSource ) <> lsFieldName then begin
          DBChartResults.SeriesList[i].Active := FALSE;
        end else begin
          DBChartResults.SeriesList[i].Marks.Visible := TRUE;
          DBChartResults.Title.Text.Clear;
          DBChartResults.Title.Text.Add( DBChartResults.SeriesList[i].Title );
          fShowingAllSeries := FALSE;
        end; // if
      end; // for
    end else begin
      // we need to loop through all series and make them invisible except for the
      // series that was clicked.
      DBChartResults.Legend.Visible := TRUE;
      //Series.Marks.Visible := FALSE;
      for i := 0 to DBChartResults.SeriesCount - 1 do begin
        DBChartResults.SeriesList[i].Active := TRUE;
        // turn on the mark only for OSMark:
        if i = DBChartResults.SeriesCount - 1 then begin
          DBChartResults.SeriesList[i].Marks.Visible := TRUE;
        end else begin
          DBChartResults.SeriesList[i].Marks.Visible := FALSE;
        end;
        fShowingAllSeries := TRUE;
      end; // for
      DBChartResults.Title.Text.Clear;
      DBChartResults.Title.Text.Add( CHART_TITLE );
    end; // if
    DBChartResults.LeftAxis.Minimum := 0;
    DBChartResults.LeftAxis.Automatic := TRUE;
  end; // if ThisIsAResultField then begin

  if lowerCase( cdsResults.IndexFieldNames ) <> lsFieldName then begin
    cdsResults.IndexFieldNames := Column.Field.FieldName;
    DBChartResults.RefreshData;
  end; // if
end;

procedure TfrmOSMResults.DBChartResultsClickSeries(Sender: TCustomChart;
  Series: TChartSeries; ValueIndex: Integer; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  i : integer;
begin
  if fShowingAllSeries then begin
    DBChartResults.Legend.Visible := FALSE;
    // we need to loop through all series and make them invisible except for the
    // series that was clicked.
    for i := 0 to DBChartResults.SeriesCount - 1 do begin
      if DBChartResults.SeriesList[i] <> Series then begin
        DBChartResults.SeriesList[i].Active := FALSE;
      end; // if
      Series.Marks.Visible := TRUE;
      DBChartResults.Title.Text.Clear;
      DBChartResults.Title.Text.Add( Series.Title );
      fShowingAllSeries := FALSE;
    end; // for
  end else begin
    // we need to loop through all series and make them invisible except for the
    // series that was clicked.
    DBChartResults.Legend.Visible := TRUE;
    Series.Marks.Visible := FALSE;
    for i := 0 to DBChartResults.SeriesCount - 1 do begin
      DBChartResults.SeriesList[i].Active := TRUE;
      if i = DBChartResults.SeriesCount - 1 then begin
        DBChartResults.SeriesList[i].Marks.Visible := TRUE;
      end;
      fShowingAllSeries := TRUE;
    end; // for
    DBChartResults.Title.Text.Clear;
    DBChartResults.Title.Text.Add( CHART_TITLE );
  end; // if
  DBChartResults.LeftAxis.Minimum := 0;
  DBChartResults.LeftAxis.Automatic := TRUE;
//  s := Series.Title + ': ' + FloatToStr( Series.YValues[ ValueIndex ] );
//  ShowMessage( s );
//  Series.Marks.  .Draw( ValueIndex, clRed, Series.XLabel[ ValueIndex ] , Series.Marks.Positions[ValueIndex] );
  //Series.Labels .Marks .BackColor := clRed;
end;

procedure TfrmOSMResults.btnFilterClick(Sender: TObject);
var
  lfrmFilter : TfrmFilter;
begin
  lfrmFilter := TfrmFilter.Create(self);
  try
    lfrmFilter.cdsFilter := cdsResults;
    lfrmFilter.PopulateListBoxes;
    lfrmFilter.ShowModal;
    DBChartResults.RefreshData;
  finally
    lfrmFilter.Release;
    FreeAndNil( lfrmFilter );
  end; //try
end;

procedure TfrmOSMResults.btnShowAllClick(Sender: TObject);
begin
  cdsResults.Filter := '';
  cdsResults.Filtered := FALSE;
  DBChartResults.RefreshData;
end; // procedure TfrmOSMResults.btnShowAllClick

procedure TfrmOSMResults.SaveToXML(asFileName: string);
begin
  cdsResults.SaveToFile(asFileName, dfXML);
end; // procedure TfrmOSMResults.SaveToXML

procedure TfrmOSMResults.LoadFromXML(asFileName: string);
begin
  cdsResults.LoadFromFile( asFileName );
  ResizeGridColumns;
end; // procedure TfrmOSMResults.LoadFromXML

procedure TfrmOSMResults.LoadFromXMLBrowse;
begin
  if OpenDialog1.Execute then begin
    LoadFromXML( OpenDialog1.FileName );
  end; // if
end; // procedure TfrmOSMResults.LoadFromXMLBrowse

procedure TfrmOSMResults.LoadBackgroundImage(asFilename : string);
begin
  DBChartResults.BackImage.LoadFromFile( asFilename );
end; // procedure TfrmOSMResults.LoadBackgroundImage

procedure TfrmOSMResults.LoadBackgroundImageBrowse;
begin
  if OpenDialogBGImage.Execute then begin
    fBackgroundImage := OpenDialogBGImage.FileName;
    LoadBackgroundImage( fBackgroundImage );
  end; // if
end; // procedure TfrmOSMResults.LoadBackgroundImageBrowse

procedure TfrmOSMResults.btnLoadBGImageClick(Sender: TObject);
begin
  LoadBackgroundImageBrowse;
end;

procedure TfrmOSMResults.btnNoImageClick(Sender: TObject);
begin
  DBChartResults.BackImage.Bitmap.FreeImage;
end;

procedure TfrmOSMResults.btnStretchClick(Sender: TObject);
begin
  if DBChartResults.BackImageMode = pbmStretch then begin
    DBChartResults.BackImageMode := pbmCenter;
  end else begin
    DBChartResults.BackImageMode := pbmStretch;
  end; // if
end;

//procedure TfrmOSMResults.btnStackedClick(Sender: TObject);
//var
//  i : integer;
//  ldMax : double;
//begin
//  ldMax := 0;
//  if TBarSeries( DBChartResults.SeriesList.Series[1] ).MultiBar = mbStacked then begin
//    for i := 0 to DBChartResults.SeriesCount - 1 do begin
//      TBarSeries( DBChartResults.SeriesList.Series[i] ).MultiBar := mbNone;
////      if ldMax < DBChartResults.SeriesList.Series[i].MaxYValue then begin
////        ldMax := DBChartResults.SeriesList.Series[i].MaxYValue;
////      end; // if
//    end; // for
//    DBChartResults.LeftAxis.Automatic := TRUE;
//  end else begin
//    for i := 0 to DBChartResults.SeriesCount - 1 do begin
//      TBarSeries( DBChartResults.SeriesList.Series[i] ).MultiBar := mbStacked;
//      end; // if
//    end; // for
//    for i := 0 to DBChartResults.SeriesCount - 1 do begin
//      if ldMax < DBChartResults.SeriesList.Series[i].MaxYValue then begin
//        ldMax := DBChartResults.SeriesList.Series[i].MaxYValue;
//    end; // for
//    DBChartResults.LeftAxis.Automatic := FALSE;
//    DBChartResults.LeftAxis.Maximum := ldMax;
//  end;
////  DBChartResults.RefreshData;
//end; // procedure TfrmOSMResults.btnStackedClick

procedure TfrmOSMResults.btnSaveGraphClick(Sender: TObject);
begin
  SaveDialog1.Filter := 'Bitmap files (*.bmp)|*.BMP';
  if SaveDialog1.Execute then begin
    DBChartResults.SaveToBitmapFile(SaveDialog1.FileName);
  end; // if
end;

procedure TfrmOSMResults.btnPrintGraphClick(Sender: TObject);
begin
  if printDialog1.Execute then begin
    DBChartResults.Print;
  end;
end;

procedure TfrmOSMResults.AddNewResults(
  AOSMarkTestResults: TOSMarkTestResults);
begin
    cdsResults.Append;
    cdsResults.FieldByName('PlatformName').AsString :=
      AOSMarkTestResults.SystemInfo.GetCpuName;  //HardwareInfo.PlatformName;
    cdsResults.FieldByName('CPU').AsString :=
      AOSMarkTestResults.HardwareInfo.CPU;
    cdsResults.FieldByName('CPUVendor').AsString :=
      AOSMarkTestResults.HardwareInfo.CPUVendor;
    cdsResults.FieldByName('CPUFamily').AsInteger :=
      AOSMarkTestResults.HardwareInfo.CPUFamily;
    cdsResults.FieldByName('CPUModel').AsInteger :=
      AOSMarkTestResults.HardwareInfo.CPUModel;
    cdsResults.FieldByName('CPUStepping').AsInteger :=
      AOSMarkTestResults.HardwareInfo.CPUStepping;
    cdsResults.FieldByName('CPUWinMHz').AsInteger :=
      AOSMarkTestResults.HardwareInfo.CPUWinMHz;
    cdsResults.FieldByName('CPUClockSpeed').AsCurrency :=
      round( AOSMarkTestResults.HardwareInfo.CPUClockSpeed );
    cdsResults.FieldByName('CPUFSB').AsInteger :=
      round( AOSMarkTestResults.HardwareInfo.CPUFSB );
    cdsResults.FieldByName('CPU Count').AsInteger :=
      AOSMarkTestResults.HardwareInfo.CPUCount;
    cdsResults.FieldByName('Virtual CPU Count').AsInteger :=
      AOSMarkTestResults.HardwareInfo.VirtualCPUCount;
    cdsResults.FieldByName('L1 Data').AsInteger :=
      AOSMarkTestResults.HardwareInfo.CPUL1d;
    cdsResults.FieldByName('L1 Instruction').AsInteger :=
      AOSMarkTestResults.HardwareInfo.CPUL1i;
    cdsResults.FieldByName('Trace Cache').AsString :=
      AOSMarkTestResults.HardwareInfo.CPUTraceCache;
    cdsResults.FieldByName('L2').AsInteger :=
      AOSMarkTestResults.HardwareInfo.CPUL2;
    cdsResults.FieldByName('L3').AsString :=
      AOSMarkTestResults.HardwareInfo.CPUL3;
    cdsResults.FieldByName('Chipset').AsString :=
      AOSMarkTestResults.HardwareInfo.NorthBridge;
    cdsResults.FieldByName('Chipset Driver').AsString :=
      AOSMarkTestResults.HardwareInfo.ChipsetDriver;
    cdsResults.FieldByName('Graphics Adapter').AsString :=
      AOSMarkTestResults.HardwareInfo.GraphicsAdapter;
    cdsResults.FieldByName('Graphics Driver').AsString :=
      AOSMarkTestResults.HardwareInfo.GraphicsDriver;
    cdsResults.FieldByName('Memory Type').AsString :=
      AOSMarkTestResults.HardwareInfo.MemoryType;
    cdsResults.FieldByName('Memory Speed').AsFloat :=
      AOSMarkTestResults.HardwareInfo.MemorySpeed;
    cdsResults.FieldByName('Memory Amount').AsInteger :=
      round( AOSMarkTestResults.HardwareInfo.MemoryAmount );
    cdsResults.FieldByName('Hard Drive').AsString :=
      AOSMarkTestResults.HardwareInfo.HardDrive;
    cdsResults.FieldByName('Motherboard').AsString :=
      AOSMarkTestResults.HardwareInfo.Motherboard;
    cdsResults.FieldByName('Motherboard BIOS').AsString :=
      AOSMarkTestResults.HardwareInfo.MotherboardBIOS;
    cdsResults.FieldByName('Video Resolution').AsString :=
      AOSMarkTestResults.HardwareInfo.VideoResolution;
    cdsResults.FieldByName('OS').AsString :=
      AOSMarkTestResults.OSInfo.OSName;
    cdsResults.FieldByName('OSVersion').AsString :=
      AOSMarkTestResults.OSInfo.Version;
    cdsResults.FieldByName('OSBuild').AsString :=
      AOSMarkTestResults.OSInfo.BuildNumber;
    cdsResults.FieldByName('DateTime').AsDateTime :=
      AOSMarkTestResults.RunDateTime;
    cdsResults.FieldByName('GridBlast').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtGrid) );
    cdsResults.FieldByName('GridBlastFP').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtGridFP) );
    cdsResults.FieldByName('FibThreads').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtFibThreads) );
    cdsResults.FieldByName('nBody').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtNBody) );
    cdsResults.FieldByName('PiThreads').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtPiThreads) );
    cdsResults.FieldByName('PlotTrig').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtPlotTrig) );
    cdsResults.FieldByName('PlotTrig2').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtPlotTrig2) );
    cdsResults.FieldByName('PlotLines').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtPlotLines) );
    cdsResults.FieldByName('RandomDots').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtRandomDots) );
    cdsResults.FieldByName('Mandelbrot').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtMandelbrotThreads) );
    cdsResults.FieldByName('Circles').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtCircles) );
    cdsResults.FieldByName('Mazes').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtMaze) );
    cdsResults.FieldByName('FernFractal').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtFern) );
    cdsResults.FieldByName('RichEdit').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtRichEd) );
    cdsResults.FieldByName('Ellipses').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtDrawEllipses) );
    cdsResults.FieldByName('CalculatePi').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtPi) );
    cdsResults.FieldByName('DhrystoneThreads').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtDhrystoneThreads) );
    cdsResults.FieldByName('WhetstoneThreads').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtWhetstoneThreads) );
    cdsResults.FieldByName('MazeThreads').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtMazeThreads) );
    cdsResults.FieldByName('Rectangles').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtDrawRectangles) );
    cdsResults.FieldByName('BandwidthBP64').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtBandwidthBP64) );
    cdsResults.FieldByName('MemLatency').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtMemLatency) );
    cdsResults.FieldByName('OThreads').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtOrthogonalThreads) );
    cdsResults.FieldByName('IThreads').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtIdenticalThreads) );
    cdsResults.FieldByName('Lines').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtDrawLines) );
    cdsResults.FieldByName('JpgDecode').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtJpgDecode) );
    cdsResults.FieldByName('ImageResize').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtImageResize) );
    cdsResults.FieldByName('ImageRotate').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtImageRotate) );
    cdsResults.FieldByName('MP3Encode').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtMP3Encode) );
    cdsResults.FieldByName('WebPageLoad').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtWebPageLoad) );
    cdsResults.FieldByName('ZipCompress').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtZipCompress) );
    cdsResults.FieldByName('EncryptDecrypt').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtEncryptDecrypt) );
    cdsResults.FieldByName('FileCopy').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtFileCopy) );
    cdsResults.FieldByName('LorenzAttractor').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtLorenz) );
    cdsResults.FieldByName('NBodyOpenGL').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtNBodyOpenGL) );
    cdsResults.FieldByName('PNGOut').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtPngOut) );
    cdsResults.FieldByName('7zip').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qt7zip) );
    cdsResults.FieldByName('UPX').AsInteger :=
      round( AOSMarkTestResults.GetBestScore(qtUpx) );
    cdsResults.FieldByName('OSMark').AsInteger :=
      round( AOSMarkTestResults.GetCosbiScore(FALSE) );
    cdsResults.Post;
end; // procedure TfrmOSMResults.AddNewResults

procedure TfrmOSMResults.LoadDefaultDatabase;
begin
  try
    LoadFromXML(fDefaultDatabaseFileName);
  except
    ShowMessage(
      'procedure TfrmOSMResults.LoadDefaultDatabase:' + CR_LF
      + 'Could not find default results database:' + CR_LF
      + fDefaultDatabaseFileName
      );
  end;
end; // procedure TfrmOSMResults.LoadDefaultDatabase;

procedure TfrmOSMResults.btnExportClick(Sender: TObject);
var
  lfrmExportResults : TfrmExportResults;
begin
  lfrmExportResults := TfrmExportResults.Create( self );
  try
    lfrmExportResults.DataSourceResults.DataSet := cdsResults;
//    lfrmExportResults.ClientDataSetResults := cdsResults;
//    lfrmExportResults.ClientDataSetResults.Active := TRUE;
    lfrmExportResults.ShowModal;
  finally
    lfrmExportResults.Release;
    FreeAndNil( lfrmExportResults );
  end; // try..finally
end;

procedure TfrmOSMResults.btnUnZoomClick(Sender: TObject);
begin
  DBChartResults.UndoZoom;
end;

procedure TfrmOSMResults.FormClose(Sender: TObject; var Action: TCloseAction);
var
  lsFileName : string;
begin
  WriteIniFile;
  if fNeedToSave then begin
    if (
         MessageDlg( 'Save the new data before closing?', mtWarning, [ mbYes, mbNo ], 0 )
         = mrYes
        ) then begin
      lsFileName := ExtractFilePath( Application.ExeName ) + RESULTS_FILE_NAME;
      SaveToXML( lsFileName );
    end; // if
  end;
end;

procedure TfrmOSMResults.Button1Click(Sender: TObject);
begin
    DBChartResults.RefreshData;
end;

procedure TfrmOSMResults.DBNavigator1Click(Sender: TObject;
  Button: TNavigateBtn);
begin
  if Button = nbPost then fNeedToSave := TRUE;
end;

end.
