
{*******************************************************}
{                                                       }
{       Borland Delphi Visual Component Library         }
{                                                       }
{       Copyright (c) 1997,98 Inprise Corporation       }
{                                                       }
{*******************************************************}

unit mxcommon;

interface

uses
  dialogs, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, inifiles,db,dbtables,
  dbcommon, bde, mxarrays, mxconsts ;

  type

	 EDimensionMapError = Class( Exception );
	 TQueryError = (tqeOK, tqeNoDimensions, tqeNoAggs, tqeNotGrouped,
  		 tqeNotInitialized, tqeMapCorrupt, tqeUnKnownDims );
  TBinType = ( binNone, binYear, binQuarter, binMonth, binSet, binCustom );
  TBinTypes = set of TBinType;

  TActiveFlags = ( diActive, diAsNeeded, diInactive );

  TDimFlags = ( dimDimension, dimSum, dimCount, dimAverage, dimMin, dimMax, dimGenericAgg, dimUnknown);

  TCDNotifyType = (tdChanged);

  TDimensionItem = class( TCollectionItem )
  protected
    procedure InitializeRange; virtual;
    procedure NotifyCollection(aType: TCDNotifyType); virtual;
    property Active: boolean;
		property Owner: TCollection read FOwner;
  public
    constructor Create(Collection: TCollection); override;
    procedure Assign(Value: TPersistent); override;
    function IsDimension: Boolean;
    function IsSummary: Boolean;
  published
// changed public and published pg
    property ActiveFlag: TActiveFlags;
    property Format: String;
    property FieldType: TFieldType;
		property Fieldname: string read Ffieldname write Setfieldname;
		property BaseName: string read FBaseName write setBaseName;
    property Name: string;
    property DerivedFrom: integer;
    property DimensionType: TDimFlags;
  end;

  TDimensionItemClass = class of TDimensionItem;

  TDimensionItems = class(TCollection)
  protected
    function GetOwner: TPersistent; override;
    procedure NotifyOwner(aType: TCDNotifyType);
  public
    constructor Create(Owner: TPersistent; ItemClass: TDimensionItemClass);
    function    Add: TDimensionItem;
    procedure Assign(Source: TPersistent); override;
    function AddDerivedField(Index: integer; dimType: tDimFlags): integer;
    Function AverageFieldCheck(Index: integer; var SumIndex, CountIndex: integer): boolean;
    function AlreadyExists(BaseName: String; sType: TDimFlags): boolean;
    property Items[Index: Integer]:TDimensionItem; default;
    property DimensionCount: Integer;
    property SummaryCount: Integer;
    property ActiveDimensionCount: Integer;
    property ActiveSummaryCount: Integer;
  end;


  PTickInfoRec = ^TTickInfoRec;
  TTickInfoRec = Record
    StartTicks,
    EndTicks,
    TotalTicks: Integer;
    SName: string;
  end;

  TTicks = class
  public
   constructor Create( FileName: string );
   destructor Destroy; override;
   procedure Dump( bDetail: Boolean );
   procedure Clear;
   procedure Ticks( SectionName: string );
   procedure TicksIntArray( SectionName: string; IntArray: TIntArray );
   procedure TicksSmallIntArray( SectionName: string; IntArray: TSmallIntArray );
   property NumberOfValues: Integer;
 end;

  TBinData = class( TPersistent )
  public
    constructor create;
    destructor destroy; override;
    procedure Clear;
    procedure Assign( Value: TPersistent ); override;
    procedure AddBinValues( BinName: string; const Values: array of const );
    function AddBinValue( BinName: string; Value: Variant ): Integer;
    function BinValueCount( BinName: string ): Integer;
    function GetAllBinValueCount: Integer;
    function GetBinValue( BinName: string; Index: Integer ): Variant;
    function GetBinValues( BinName: string ): Variant;
    function GetBinName( Index: Integer ): string;
    function GetBinCount: Integer;
    function GetBinNameDataType: TFieldType;
    function GetMaxBinNameSize: Integer;
// added pg
		function AddBin( BinName: string; vType: Integer ): Integer;
		function AddIBinValue( iBin: integer; value: variant): integer;
		function GetIBinValue( iBin: integer; ValueIndex: integer): variant;
		function GetIBinValueCount( iBin: integer): integer;
//
    property OtherBinName: string;
    property BinName[ Index:Integer ]: string;
    property BinCount: Integer;
    property NameList: TStringList;
    property ValueList: TList;
  end;

function FieldTypeToVarType( DataType: TFieldType ): Integer;
function VerifyRTQuery( aDataSet: TDataSet; Map: TDimensionItems; var bDataSetMatch: boolean ): TQueryError;
function BuildDataSetMap(aDataSet: TDataSet; Map: TDimensionItems; var bParsed: boolean; var bDataSetMatch: boolean): TQueryError;
function GetAggName(aType: TDimFlags; FieldName: string): string;
//function isMapLegal(Map: TDimensionItems): TQueryError;
function IsAggValid(AggType: TDimFlags; FieldType: TFieldType): boolean;
procedure AddToQuerySelect(var SQLString: string; Select: string);
function CheckIfEmptyQuery(var SQLString: string): boolean;
procedure UpdateDesigner(Sender: TComponent);
function FormatVariant(Value: Variant; FFormat: String): string;
function NextArg(var aPos: integer; Source: string): string;
function HookToDataBase(aDataSet: TDataSet): TDataBase;
function IsBDEAvailable: Boolean;

implementation
