// CodeGear C++Builder
// Copyright (c) 1995, 2012 by Embarcadero Technologies, Inc.
// All rights reserved

// (DO NOT EDIT: machine generated header) 'SMDBISAM.pas' rev: 24.00 (Win32)

#ifndef SmdbisamHPP
#define SmdbisamHPP

#pragma delphiheader begin
#pragma option push
#pragma option -w-      // All warnings off
#pragma option -Vx      // Zero-length empty class member 
#pragma pack(push,8)
#include <System.hpp>	// Pascal unit
#include <SysInit.hpp>	// Pascal unit
#include <System.Classes.hpp>	// Pascal unit
#include <Winapi.Windows.hpp>	// Pascal unit
#include <SMCells.hpp>	// Pascal unit

//-- user supplied -----------------------------------------------------------

namespace Smdbisam
{
//-- type declarations -------------------------------------------------------
enum TDBISAMFieldType : unsigned char { dftUnknow, dftString, dftDate, dftBLOB, dftLogical, dftInt16, dftInt32, dftFloat, dftBCD, dftBytes, dftTime, dftTimeStamp, dftUInt16, dftUInt32, dftDouble, dftVarBytes, dftLockInfo, dftCursor, dftInt64, dftUInt64, dftADT, dftArray, dftRef, dftTable };

enum TDBISAMFieldSubType : unsigned char { dfstUnknown, dfstPassword, dfstMoney, dfstMEMO, dfstBinary, dfstFmtMEMO, dfstOLE, dfstGraphic, dfstDBSOLE, dfstTypedBinary, dfstAutoInc, dfstAccOLE, dfstFixed, dfstUnicode, dfstHMEMO, dfstHBinary, dfstADTNestedTable, dfstBFile, dfstADTDate, dfstGUID, dfstMD5 };

#pragma pack(push,1)
struct DECLSPEC_DRECORD TDBISAMField1
{
public:
	System::Word FieldNum;
	System::SmallString<30>  FieldName;
	System::SmallString<50>  Description;
	TDBISAMFieldType DataType;
	System::Byte SubType;
	System::Byte Length;
	System::Byte Decimals;
	System::Word Offset;
	bool Required;
	bool Encrypted;
	System::SmallString<50>  Minimum;
	System::SmallString<50>  Maximum;
	System::SmallString<50>  Default;
	System::StaticArray<System::Byte, 20> EmptySpace;
};
#pragma pack(pop)


#pragma pack(push,1)
struct DECLSPEC_DRECORD TDBISAMField123
{
public:
	System::Word FieldNum;
	System::SmallString<30>  FieldName;
	System::SmallString<50>  Description;
	TDBISAMFieldType DataType;
	System::Byte SubType;
	System::Byte Length;
	System::Byte Decimals;
	System::Byte DataSize;
	System::Byte DataDecimals;
	System::Word Offset;
	bool Required;
	System::Byte CharCase;
	System::SmallString<50>  Minimum;
	System::SmallString<50>  Maximum;
	System::SmallString<50>  Default;
	bool ExpressionField;
	System::TObject* ExpressionTokens;
	bool Hidden;
	bool SortDescending;
	System::SmallString<100>  FieldOrigin;
	System::Word OriginFieldNum;
	System::Word FieldPos;
	System::SmallString<100>  FieldDatabaseOrigin;
	System::StaticArray<System::Byte, 308> EmptySpace;
};
#pragma pack(pop)


#pragma pack(push,1)
struct DECLSPEC_DRECORD TDBISAMField
{
public:
	System::Word FieldNum;
	System::SmallString<60>  FieldName;
	System::SmallString<100>  Description;
	TDBISAMFieldType FieldType;
	System::Byte FieldSubType;
	System::Word Length;
	System::Byte Decimals;
	System::Word DataSize;
	System::Byte DataDecimals;
	System::Word Offset;
	bool Required;
	System::Byte CharCase;
	System::SmallString<100>  Minimum;
	System::SmallString<100>  Maximum;
	System::SmallString<100>  Default;
	System::Byte Compression;
	bool ExpressionField;
	System::TObject* ExpressionTokens;
	bool Hidden;
	System::SmallString<100>  FieldOrigin;
	System::Word OriginFieldNum;
	System::Word FieldPos;
	System::SmallString<100>  FieldDatabaseOrigin;
	System::StaticArray<System::Byte, 76> EmptySpace;
};
#pragma pack(pop)


typedef System::StaticArray<TDBISAMField, 1025> TDBISAMFields;

typedef System::StaticArray<System::Byte, 16> TMD5DigestArray;

enum TDBISAMRecordStatus : unsigned char { drsValid, drsDeleted, drsError };

#pragma pack(push,1)
struct DECLSPEC_DRECORD TDBISAMRecordHeader
{
public:
	TDBISAMRecordStatus Status;
	int NextFree;
	int ID;
	TMD5DigestArray Signature;
};
#pragma pack(pop)


#pragma pack(push,1)
struct DECLSPEC_DRECORD TDBISAMHeader123
{
public:
	int UpdateStamp;
	int BlobBlockSize;
	System::Byte VersionNum;
	int NextFreeRecord;
	int NextEndingRecord;
	int LastRecordID;
	System::Word RecordSize;
	System::Word NumberOfFields;
	System::Word BlobFieldCount;
	System::TDateTime LastUpdated;
	System::SmallString<50>  Description;
	bool Encrypted;
	System::SmallString<15>  Password;
	System::Word LanguageID;
	System::Word SortID;
	System::Word UserMajorVersion;
	System::Word UserMinorVersion;
	bool IsDirty;
	int LastBlobSignature;
	System::Currency LastEngineVersion;
	System::StaticArray<System::Byte, 3> EmptySpace;
};
#pragma pack(pop)


#pragma pack(push,1)
struct DECLSPEC_DRECORD TDBISAMHeader
{
public:
	int UpdateStamp;
	System::StaticArray<System::Byte, 4> EmptySpace1;
	System::Byte VersionNum;
	TMD5DigestArray FileSignature;
	int NextFreeRecord;
	int NextEndingRecord;
	int LastRecordID;
	int LastAutoIncID;
	int NumberOfRecords;
	System::Word RecordSize;
	System::Word NumberOfFields;
	System::Word BlobFieldCount;
	int BlobBlockSize;
	int LastBlobSignature;
	int IndexPageSize;
	System::TDateTime LastUpdated;
	System::SmallString<100>  Description;
	bool Encrypted;
	TMD5DigestArray Digest;
	int LocaleID;
	System::Word UserMajorVersion;
	System::Word UserMinorVersion;
	bool IsDirty;
	System::StaticArray<System::Byte, 314> EmptySpace2;
};
#pragma pack(pop)


#pragma pack(push,1)
struct DECLSPEC_DRECORD TDBISAMPageHeader
{
public:
	System::Byte PageType;
	System::Word NumberOfKeys;
	int LeftNumber;
	int RightNumber;
	System::Word CompressedSize;
};
#pragma pack(pop)


#pragma pack(push,1)
struct DECLSPEC_DRECORD TDBISAMBlockHeader
{
public:
	int PrevNumber;
	int NextNumber;
	System::Word Length;
	int Signature;
	int TotalLength;
};
#pragma pack(pop)


#pragma pack(push,1)
struct DECLSPEC_DRECORD TDBISAMBlobHeader
{
public:
	int UpdateStamp;
	System::StaticArray<System::Byte, 4> EmptySpace1;
	System::Byte VersionNum;
	TMD5DigestArray FileSignature;
	int NextFreeBlock;
	int NextEndingBlock;
	bool IsDirty;
	System::StaticArray<System::Byte, 478> EmptySpace;
};
#pragma pack(pop)


class DELPHICLASS TDBISAM;
class PASCALIMPLEMENTATION TDBISAM : public Smcells::TSpreadSheetFile
{
	typedef Smcells::TSpreadSheetFile inherited;
	
private:
	System::Classes::TStream* BLOBStream;
	System::UnicodeString FPassword;
	Smcells::TSMIOnPasswordEvent FOnPassword;
	bool __fastcall CompareDigest(System::Byte *d1, System::Byte *d2);
	
protected:
	System::UnicodeString FoldPassword;
	System::Classes::TStream* FCurrentStream;
	virtual void __fastcall ReadBLOBValue(unsigned BlockNo, unsigned ASize, System::UnicodeString &s);
	
public:
	TDBISAMHeader DBHeader;
	TDBISAMBlobHeader BLOBHeader;
	TDBISAMFields Fields;
	__fastcall virtual TDBISAM(System::Classes::TComponent* AOwner);
	__fastcall virtual ~TDBISAM(void);
	virtual void __fastcall LoadFromStream(System::Classes::TStream* AStream);
	virtual void __fastcall LoadFromFile(const System::WideString FileName);
	virtual void __fastcall BeforeLoad(void);
	virtual void __fastcall AfterLoad(void);
	virtual bool __fastcall LoadRecord(int RecNo);
	virtual int __fastcall FindColumn(const System::UnicodeString AFieldName);
	virtual void __fastcall FillColumnList(System::Classes::TStrings* lst, const System::UnicodeString strFieldList);
	System::UnicodeString __fastcall VersionNumToStr(void);
	System::UnicodeString __fastcall GetStrFieldType(TDBISAMFieldType FieldType, TDBISAMFieldSubType FieldSubType);
	TDBISAMFieldSubType __fastcall GetFieldSubType(System::Byte Value);
	virtual bool __fastcall IsEncrypted(void);
	bool __fastcall IsPasswordValid(void);
	__property System::UnicodeString Password = {read=FPassword, write=FPassword};
	
__published:
	__property Smcells::TSMIOnPasswordEvent OnPassword = {read=FOnPassword, write=FOnPassword};
};


typedef void __fastcall (*TSMDBISAMDecryptBufferEvent)(System::TObject* Sender, void *Buffer, int NumBytes, bool IsHeader, bool IsRecord, bool IsPChar);

typedef void __fastcall (*TSMDBISAMGetPasswordDigestEvent)(System::TObject* Sender, const System::UnicodeString APassword, System::Byte *AResult);

typedef void __fastcall (*TSMDBISAMCryptInitEvent)(System::TObject* Sender, System::Byte *ADigest);

//-- var, const, procedure ---------------------------------------------------
extern PACKAGE System::StaticArray<System::Byte, 21> arrFieldSubTypeValue;
extern PACKAGE TSMDBISAMDecryptBufferEvent RegisteredDBISAMDecryptBuffer;
extern PACKAGE TSMDBISAMGetPasswordDigestEvent RegisteredDBISAMGetPasswordDigest;
extern PACKAGE TSMDBISAMCryptInitEvent RegisteredDBISAMCryptInit;
extern PACKAGE Smcells::TSMIOnPasswordEvent RegisteredDBISAMPassword;
}	/* namespace Smdbisam */
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_SMDBISAM)
using namespace Smdbisam;
#endif
#pragma pack(pop)
#pragma option pop

#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif	// SmdbisamHPP
