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

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

#ifndef SmparadoxHPP
#define SmparadoxHPP

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

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

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

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


#pragma pack(push,1)
struct DECLSPEC_DRECORD 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;
	System::StaticArray<System::Byte, 3> Unknown1Ex20;
	System::Word NumberOfFields;
	System::Word PrimaryKeyFields;
	int Encryption1;
	System::Byte SortOrder;
	System::Byte ModifiedFlags2;
	System::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;
	System::StaticArray<System::Byte, 2> unknown3Ex3F;
	void *cryptInfoStartPtr;
	void *cryptInfoEndPtr;
	System::Byte unknown48;
	int autoIncVal;
	System::StaticArray<System::Byte, 2> unknown4Dx4E;
	System::Byte indexUpdateRequired;
	System::StaticArray<System::Byte, 5> unknown50x54;
	System::Byte refIntegrity;
	System::StaticArray<System::Byte, 2> unknown56x57;
};
#pragma pack(pop)


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


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


struct TDataBlockHeader;
typedef TDataBlockHeader *PDataBlockHeader;

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


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


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


#pragma pack(push,1)
struct DECLSPEC_DRECORD 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:
	System::Classes::TStream* BLOBStream;
	TDataBlockHeader Block;
	System::UnicodeString FPassword;
	Smcells::TSMIOnPasswordEvent FOnPassword;
	int __fastcall GetBlockSize(void);
	
protected:
	int BlockIndex;
	int RecIndexInBlock;
	System::Classes::TStream* FCurrentStream;
	void __fastcall LoadNextBlock(void);
	void __fastcall WriteNextBlock(void);
	System::UnicodeString __fastcall TranslateString(const System::UnicodeString s);
	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;
	System::StaticArray<TParadoxField, 256> Fields;
	__fastcall virtual TDBParadox(System::Classes::TComponent* AOwner);
	__fastcall virtual ~TDBParadox(void);
	virtual void __fastcall LoadFromStream(System::Classes::TStream* AStream);
	virtual void __fastcall LoadFromFile(const System::WideString FileName);
	void __fastcall WriteToStream(System::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(System::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 System::Int8 pxfAlpha = System::Int8(0x1);
static const System::Int8 pxfDate = System::Int8(0x2);
static const System::Int8 pxfShort = System::Int8(0x3);
static const System::Int8 pxfLong = System::Int8(0x4);
static const System::Int8 pxfCurrency = System::Int8(0x5);
static const System::Int8 pxfNumber = System::Int8(0x6);
static const System::Int8 pxfLogical = System::Int8(0x9);
static const System::Int8 pxfMemoBLOB = System::Int8(0xc);
static const System::Int8 pxfBLOB = System::Int8(0xd);
static const System::Int8 pxfFmtMemoBLOB = System::Int8(0xe);
static const System::Int8 pxfOLE = System::Int8(0xf);
static const System::Int8 pxfGraphic = System::Int8(0x10);
static const System::Int8 pxfTime = System::Int8(0x14);
static const System::Int8 pxfTimestamp = System::Int8(0x15);
static const System::Int8 pxfAutoInc = System::Int8(0x16);
static const System::Int8 pxfBCD = System::Int8(0x17);
static const System::Int8 pxfBytes = System::Int8(0x18);
extern PACKAGE TPDXDecryptDBBlockEvent RegisteredParadoxDecryptDBBlock;
extern PACKAGE TPDXGetPasswordChecksumEvent RegisteredParadoxGetPasswordChecksum;
extern PACKAGE Smcells::TSMIOnPasswordEvent RegisteredParadoxPassword;
}	/* namespace Smparadox */
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_SMPARADOX)
using namespace Smparadox;
#endif
#pragma pack(pop)
#pragma option pop

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