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

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

#ifndef SmparadoxHPP
#define SmparadoxHPP

#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
#include <Sysutils.hpp>	// Pascal unit

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

namespace Smparadox
{
//-- type declarations -------------------------------------------------------
struct TFldInfoRec;
typedef TFldInfoRec *PFldInfoRec;

#pragma pack(push,1)
struct TFldInfoRec
{
	
public:
	System::Byte fType;
	System::Byte fSize;
};
#pragma pack(pop)


#pragma pack(push,1)
struct TPxHeader
{
	
public:
	System::Word RecordSize;
	System::Word HeaderSize;
	System::Byte FileType;
	System::Byte MaxTableSize;
	unsigned NumberOfRecords;
	System::Word NextBlock;
	System::Word FileBlocks;
	System::Word FirstBlock;
	System::Word LastBlock;
	System::Word Unknown12x13;
	System::Byte ModifiedFlags1;
	System::Byte IndexFieldNumber;
	int PrimaryIndexWorkspace;
	int UnknownPtr1A;
	StaticArray<System::Byte, 3> Unknown1Ex20;
	System::Word NumberOfFields;
	System::Word PrimaryKeyFields;
	int Encryption1;
	System::Byte SortOrder;
	System::Byte ModifiedFlags2;
	StaticArray<System::Byte, 2> unknown2Bx2C;
	System::Byte ChangeCount1;
	System::Byte ChangeCount2;
	System::Byte Unknown2F;
	System::WideChar * *TableNamePtrPtr;
	TFldInfoRec *FldInfoPtr;
	System::Byte writeProtected;
	System::Byte fileVersionID;
	System::Word maxBlocks;
	System::Byte unknown3C;
	System::Byte auxPasswords;
	StaticArray<System::Byte, 2> unknown3Ex3F;
	void *cryptInfoStartPtr;
	void *cryptInfoEndPtr;
	System::Byte unknown48;
	int autoIncVal;
	StaticArray<System::Byte, 2> unknown4Dx4E;
	System::Byte indexUpdateRequired;
	StaticArray<System::Byte, 5> unknown50x54;
	System::Byte refIntegrity;
	StaticArray<System::Byte, 2> unknown56x57;
};
#pragma pack(pop)


#pragma pack(push,1)
struct TPxHeader4
{
	
public:
	System::Word fileVerID2;
	System::Word fileVerID3;
	int encryption2;
	int fileUpdateTime;
	System::Word hiFieldID;
	System::Word hiFieldIDinfo;
	System::Word sometimesNumFields;
	System::Word dosCodePage;
	StaticArray<System::Byte, 4> unknown6Cx6F;
	System::Word changeCount4;
	StaticArray<System::Byte, 6> unknown72x77;
};
#pragma pack(pop)


#pragma pack(push,1)
struct TParadoxField
{
	
public:
	SmallString<25>  FieldName;
	int FieldType;
	int Start;
	int Length;
};
#pragma pack(pop)


struct TDataBlockHeader;
typedef TDataBlockHeader *PDataBlockHeader;

#pragma pack(push,1)
struct TDataBlockHeader
{
	
public:
	System::Word NextBlock;
	System::Word BlockNumber;
	System::Word AddDataSize;
	void *FileData;
};
#pragma pack(pop)


#pragma pack(push,1)
struct PtrRec
{
	
public:
	System::Word Lo;
	System::Word Hi;
};
#pragma pack(pop)


#pragma pack(push,1)
struct TPdoxBlob
{
	
public:
	int FileLoc;
	int Length;
	System::Word ModCnt;
	System::Byte Index;
};
#pragma pack(pop)


#pragma pack(push,1)
struct TBlobIndex
{
	
public:
	System::Byte Offset;
	System::Byte Len16;
	System::Word ModCnt;
	System::Byte Len;
};
#pragma pack(pop)


typedef void __fastcall (*TPDXDecryptDBBlockEvent)(System::TObject* Sender, System::Byte *tba, int BlockIndex, int BlockSize, int CheckSum, bool IsBLOBBlock);

typedef void __fastcall (*TPDXGetPasswordChecksumEvent)(System::TObject* Sender, const System::UnicodeString APassword, int &AResult);

class DELPHICLASS TDBParadox;
class PASCALIMPLEMENTATION TDBParadox : public Smcells::TSpreadSheetFile
{
	typedef Smcells::TSpreadSheetFile inherited;
	
private:
	Classes::TStream* BLOBStream;
	TDataBlockHeader Block;
	System::UnicodeString FPassword;
	Smcells::TSMIOnPasswordEvent FOnPassword;
	int __fastcall GetBlockSize(void);
	
protected:
	int BlockIndex;
	int RecIndexInBlock;
	Classes::TStream* FCurrentStream;
	void __fastcall LoadNextBlock(void);
	void __fastcall WriteNextBlock(void);
	void __fastcall SetFieldValue(const TParadoxField &fld, int ShiftPos, int RecNo, int FieldNumber);
	void __fastcall WriteFieldValue(const TParadoxField &fld, int ShiftPos, int RecNo, int FieldNumber);
	void __fastcall ReadBLOBValue1(const TPdoxBlob &BI, System::AnsiString &s);
	int __fastcall GetEncryptionCheckSum(void);
	int __fastcall GetPasswordChecksum(const System::UnicodeString APassword);
	bool __fastcall FileIsEncrypted(void);
	System::Word __fastcall GetCreatedTableNameSpace(void);
	
public:
	TPxHeader DBHeader;
	TPxHeader4 DBHeader4;
	System::AnsiString OriginalTableName;
	System::AnsiString SortingName;
	StaticArray<TParadoxField, 256> Fields;
	__fastcall virtual TDBParadox(Classes::TComponent* AOwner);
	__fastcall virtual ~TDBParadox(void);
	virtual void __fastcall LoadFromStream(Classes::TStream* AStream);
	virtual void __fastcall LoadFromFile(const System::WideString FileName);
	void __fastcall WriteToStream(Classes::TStream* AStream);
	void __fastcall WriteToFile(const System::WideString FileName);
	virtual void __fastcall BeforeLoad(void);
	virtual void __fastcall AfterLoad(void);
	virtual bool __fastcall LoadRecord(int RecNo);
	bool __fastcall WriteRecord(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::Word __fastcall GetTableLevel(void);
	void __fastcall FmtMemo2PlainText(System::UnicodeString &s);
	System::UnicodeString __fastcall GetStrFieldType(int i);
	System::UnicodeString __fastcall GetStrFileType(System::Byte FileType);
	virtual bool __fastcall IsEncrypted(void);
	bool __fastcall IsPasswordValid(void);
	
__published:
	__property System::Word TableLevel = {read=GetTableLevel, nodefault};
	__property System::UnicodeString Password = {read=FPassword, write=FPassword};
	__property Smcells::TSMIOnPasswordEvent OnPassword = {read=FOnPassword, write=FOnPassword};
};


//-- var, const, procedure ---------------------------------------------------
static const ShortInt pxfAlpha = 0x1;
static const ShortInt pxfDate = 0x2;
static const ShortInt pxfShort = 0x3;
static const ShortInt pxfLong = 0x4;
static const ShortInt pxfCurrency = 0x5;
static const ShortInt pxfNumber = 0x6;
static const ShortInt pxfLogical = 0x9;
static const ShortInt pxfMemoBLOB = 0xc;
static const ShortInt pxfBLOB = 0xd;
static const ShortInt pxfFmtMemoBLOB = 0xe;
static const ShortInt pxfOLE = 0xf;
static const ShortInt pxfGraphic = 0x10;
static const ShortInt pxfTime = 0x14;
static const ShortInt pxfTimestamp = 0x15;
static const ShortInt pxfAutoInc = 0x16;
static const ShortInt pxfBCD = 0x17;
static const ShortInt pxfBytes = 0x18;
extern PACKAGE TPDXDecryptDBBlockEvent RegisteredParadoxDecryptDBBlock;
extern PACKAGE TPDXGetPasswordChecksumEvent RegisteredParadoxGetPasswordChecksum;
extern PACKAGE Smcells::TSMIOnPasswordEvent RegisteredParadoxPassword;

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

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