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

// (DO NOT EDIT: machine generated header) 'Smdbisam.pas' rev: 21.00

#ifndef SmdbisamHPP
#define SmdbisamHPP

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

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

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

#pragma option push -b-
enum TDBISAMFieldSubType { dfstUnknown, dfstPassword, dfstMoney, dfstMEMO, dfstBinary, dfstFmtMEMO, dfstOLE, dfstGraphic, dfstDBSOLE, dfstTypedBinary, dfstAutoInc, dfstAccOLE, dfstFixed, dfstUnicode, dfstHMEMO, dfstHBinary, dfstADTNestedTable, dfstBFile, dfstADTDate, dfstGUID, dfstMD5 };
#pragma option pop

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


#pragma pack(push,1)
struct TDBISAMField123
{
	
public:
	System::Word FieldNum;
	SmallString<30>  FieldName;
	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;
	SmallString<50>  Minimum;
	SmallString<50>  Maximum;
	SmallString<50>  Default;
	bool ExpressionField;
	System::TObject* ExpressionTokens;
	bool Hidden;
	bool SortDescending;
	SmallString<100>  FieldOrigin;
	System::Word OriginFieldNum;
	System::Word FieldPos;
	SmallString<100>  FieldDatabaseOrigin;
	StaticArray<System::Byte, 308> EmptySpace;
};
#pragma pack(pop)


#pragma pack(push,1)
struct TDBISAMField
{
	
public:
	System::Word FieldNum;
	SmallString<60>  FieldName;
	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;
	SmallString<100>  Minimum;
	SmallString<100>  Maximum;
	SmallString<100>  Default;
	System::Byte Compression;
	bool ExpressionField;
	System::TObject* ExpressionTokens;
	bool Hidden;
	SmallString<100>  FieldOrigin;
	System::Word OriginFieldNum;
	System::Word FieldPos;
	SmallString<100>  FieldDatabaseOrigin;
	StaticArray<System::Byte, 76> EmptySpace;
};
#pragma pack(pop)


typedef StaticArray<TDBISAMField, 1025> TDBISAMFields;

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

#pragma option push -b-
enum TDBISAMRecordStatus { drsValid, drsDeleted, drsError };
#pragma option pop

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


#pragma pack(push,1)
struct 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;
	SmallString<50>  Description;
	bool Encrypted;
	SmallString<15>  Password;
	System::Word LanguageID;
	System::Word SortID;
	System::Word UserMajorVersion;
	System::Word UserMinorVersion;
	bool IsDirty;
	int LastBlobSignature;
	System::Currency LastEngineVersion;
	StaticArray<System::Byte, 3> EmptySpace;
};
#pragma pack(pop)


#pragma pack(push,1)
struct TDBISAMHeader
{
	
public:
	int UpdateStamp;
	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;
	SmallString<100>  Description;
	bool Encrypted;
	TMD5DigestArray Digest;
	int LocaleID;
	System::Word UserMajorVersion;
	System::Word UserMinorVersion;
	bool IsDirty;
	StaticArray<System::Byte, 314> EmptySpace2;
};
#pragma pack(pop)


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


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


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


class DELPHICLASS TDBISAM;
class PASCALIMPLEMENTATION TDBISAM : public Smcells::TSpreadSheetFile
{
	typedef Smcells::TSpreadSheetFile inherited;
	
private:
	Classes::TStream* BLOBStream;
	System::UnicodeString FPassword;
	Smcells::TSMIOnPasswordEvent FOnPassword;
	bool __fastcall CompareDigest(System::Byte *d1, System::Byte *d2);
	
protected:
	System::UnicodeString FoldPassword;
	Classes::TStream* FCurrentStream;
	virtual void __fastcall ReadBLOBValue(unsigned BlockNo, unsigned ASize, System::UnicodeString &s);
	
public:
	TDBISAMHeader DBHeader;
	TDBISAMBlobHeader BLOBHeader;
	TDBISAMFields Fields;
	__fastcall virtual TDBISAM(Classes::TComponent* AOwner);
	__fastcall virtual ~TDBISAM(void);
	virtual void __fastcall LoadFromStream(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(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 StaticArray<System::Byte, 21> arrFieldSubTypeValue;
extern PACKAGE TSMDBISAMDecryptBufferEvent RegisteredDBISAMDecryptBuffer;
extern PACKAGE TSMDBISAMGetPasswordDigestEvent RegisteredDBISAMGetPasswordDigest;
extern PACKAGE TSMDBISAMCryptInitEvent RegisteredDBISAMCryptInit;
extern PACKAGE Smcells::TSMIOnPasswordEvent RegisteredDBISAMPassword;

}	/* namespace Smdbisam */
using namespace Smdbisam;
#pragma pack(pop)
#pragma option pop

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