123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959 |
- {
- This file is part of the Free Component Library (FCL)
- Copyright (c) 1999-2007 by the Free Pascal development team
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- {$mode objfpc}
- {$H+}
- {
- TParadox : Dataset wich can handle paradox files, based on PXLib.
- }
- unit paradox;
- interface
- uses
- sysutils, classes, db, pxlib, bufdataset_parser;
- type
- EParadox=class(Exception);
- { TParadox }
- TParadox = Class(TDataSet)
- private
- FBlobFileName: String;
- FFileName : String;
- FPXLibrary : String;
- FCurrRecNo : Integer;
- FDoc : PPX_Doc;
- FFilterBuffer : PChar;
- FOffsets : PInteger;
- FTableName : String;
- FInputEncoding : String;
- FTargetEncoding : String;
- FParser : TBufDatasetParser;
- function GetInputEncoding: String;
- function GetTableName: String;
- function GetTargetEncoding: String;
- procedure OpenBlobFile;
- procedure PXAppendRecord(Buffer: Pointer);
- function PXFilterRecord(Buffer: PChar): Boolean;
- function PXGetActiveBuffer(var Buffer: PChar): Boolean;
- procedure RaiseError(Fmt: String; Args: array of const);
- procedure SetBlobFileName(const AValue: String);
- procedure SetFileName(const AValue: String);
- procedure SetInputEncoding(const AValue: String);
- procedure SetOpenParams;
- procedure SetTableName(const AValue: String);
- procedure SetTargetEncoding(const AValue: String);
- function GetLibStored : Boolean;
- protected
- // Mandatory
- procedure SetFilterText(const Value: String); override; {virtual;}
- procedure SetFiltered(Value: Boolean); override; {virtual;}
- procedure ParseFilter(const AFilter: string);
- function AllocRecordBuffer: PChar; override;
- procedure FreeRecordBuffer(var Buffer: PChar); override;
- procedure GetBookmarkData(Buffer: PChar; Data: Pointer); override;
- function GetBookmarkFlag(Buffer: PChar): TBookmarkFlag; override;
- function GetFieldData(Field: TField; Buffer: Pointer): Boolean; override;
- function GetRecord(Buffer: PChar; GetMode: TGetMode; DoCheck: Boolean): TGetResult; override;
- function GetRecordSize: Word; override;
- procedure InternalAddRecord(Buffer: Pointer; DoAppend: Boolean); override;
- procedure InternalClose; override;
- procedure InternalDelete; override;
- procedure InternalFirst; override;
- procedure InternalGotoBookmark(ABookmark: Pointer); override;
- procedure InternalInitFieldDefs; override;
- procedure InternalInitRecord(Buffer: PChar); override;
- procedure InternalLast; override;
- procedure InternalOpen; override;
- procedure InternalPost; override;
- procedure InternalSetToRecord(Buffer: PChar); override;
- function IsCursorOpen: Boolean; override;
- procedure SetBookmarkFlag(Buffer: PChar; Value: TBookmarkFlag); override;
- procedure SetBookmarkData(Buffer: PChar; Data: Pointer); override;
- procedure SetFieldData(Field: TField; Buffer: Pointer); override;
- procedure DataConvert(aField: TField; aSource, aDest: Pointer; aToNative: Boolean); override;
- function CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream; override;
- // Optional.
- function GetRecordCount: Integer; override;
- procedure SetRecNo(Value: Integer); override;
- function GetRecNo: Integer; override;
- // Exposed properties/procedures
- Function GetParam(Const ParamName : String) : String;
- Procedure SetParam(Const ParamName,ParamValue : String);
- property Doc : PPX_Doc Read FDoc;
-
- public
- constructor Create(AOwner:tComponent); override;
- destructor Destroy; override;
- published
- Property PXLibrary : String Read FPXLibrary Write FPXLibrary Stored GetLibStored;
- Property FileName : String Read FFileName Write SetFileName;
- Property BlobFileName : String Read FBlobFileName Write SetBlobFileName;
- Property TableName : String Read GetTableName Write SetTableName;
- Property TargetEncoding : String Read GetTargetEncoding Write SetTargetEncoding;
- Property InputEncoding : String Read GetInputEncoding Write SetInputEncoding;
- property filter;
- property Filtered;
- Property Active;
- Property FieldDefs;
- property BeforeOpen;
- property AfterOpen;
- property BeforeClose;
- property AfterClose;
- property BeforeInsert;
- property AfterInsert;
- property BeforeEdit;
- property AfterEdit;
- property BeforePost;
- property AfterPost;
- property BeforeCancel;
- property AfterCancel;
- property BeforeDelete;
- property AfterDelete;
- property BeforeScroll;
- property AfterScroll;
- property OnDeleteError;
- property OnEditError;
- property OnNewRecord;
- property OnPostError;
- property OnFilterRecord;
- end;
-
- // in front of graphic data
- TGraphicHeader = packed record
- Count: Word; { Always 1 }
- HType: Word; { Always $0100 }
- Size: Longint; { Size of actual data }
- end;
- Function PXFieldTypeToFieldType(PXFieldType : Integer) : TFieldType;
- Const
- SParamInputencoding = 'inputencoding';
- SParamTargetencoding = 'targetencoding';
- SParamTableName = 'tablename';
- implementation
- uses ctypes;
- ResourceString
- SErrFieldTypeNotSupported = 'Fieldtype of Field "%s" not supported: %d.';
- SErrBookMarkNotFound = 'Bookmark %d not found.';
- SErrNoFileName = 'Filename must not be empty.';
- SErrNoBlobFile = 'Blob file "%s" does not exist';
- SErrInvalidBlobFile = 'Blob file "%s" is invalid';
- SErrFailedToOpenFile = 'Failed to open file "%s" as a paradox file.';
- SErrParadoxNotOpen = 'Paradox file not opened';
- SErrGetParamFailed = 'Get of parameter %s failed.';
- SErrSetParamFailed = 'Set of parameter %s failed.';
-
- Const
- PXFieldTypes : Array[1..pxfNumTypes] of TFieldType
- = (ftString, ftDate, ftSmallInt, ftInteger,
- ftCurrency, ftFloat, ftUnknown { $07},ftunknown { $08},
- ftBoolean,ftUnknown { $0A}, ftunknown { $0B}, ftMemo,
- ftBlob, ftFmtMemo, ftParadoxOle, ftGraphic,
- ftUnknown { $11}, ftUnknown { $12}, ftUnknown { $13}, ftTime,
- ftDateTime, ftAutoinc, ftBCD, ftBytes);
- {
- Buffer layout :
- Bookmark : Record number
- BookmarkFlag : Flag
- Data : Actual data
- }
- Type
- PPXRecInfo = ^TPXRecInfo;
- TPXRecInfo = packed record
- Bookmark: Longint;
- BookmarkFlag: TBookmarkFlag;
- end;
- PDateTime = ^TDateTime;
-
- Const
- DataOffSet = SizeOf(TPXRecInfo);
- { ---------------------------------------------------------------------
- Utility functions
- ---------------------------------------------------------------------}
-
- Function PXFieldTypeToFieldType(PXFieldType : Integer) : TFieldType;
- begin
- if (PXFieldType<1) or (PXFieldType>pxfNumTypes) then
- Result:=ftUnknown
- else
- Result:=PXFieldTypes[PXFieldType];
- end;
- Var
- PXLibRefcount : Integer = 0;
- Procedure UninitPXLib;
- begin
- If (PXLibRefCount>0) then
- begin
- Dec(PXLibRefCount);
- If (PXLibRefCount=0) then
- begin
- PX_ShutDown();
- FreePXLib;
- end;
- end;
- end;
- Procedure InitPXLib(LibName : String);
- begin
- If (PXLibRefCount=0) then
- begin
- LoadPXLib(LibName);
- PX_Boot();
- end;
- Inc(PXLibRefCount);
- end;
- { ---------------------------------------------------------------------
- TParadox
- ---------------------------------------------------------------------}
- constructor TParadox.Create(AOwner:tComponent);
- begin
- inherited create(aOwner);
- FPXLibrary:=pxlibraryname;
- end;
- Destructor TParadox.Destroy;
- begin
- Close;
- UnInitPXLib;
- inherited Destroy;
- end;
- Procedure TParadox.RaiseError(Fmt : String; Args : Array of const);
- begin
- Raise EParadox.CreateFmt(Fmt,Args);
- end;
- Function TParadox.GetLibStored : boolean;
- begin
- Result:=(FPXLibrary<>pxlibraryname);
- end;
- procedure TParadox.SetBlobFileName(const AValue: String);
- begin
- if (FBlobFileName=AValue) then
- exit;
- CheckInactive;
- FBlobFileName:=AValue;
- end;
- function TParadox.PXFilterRecord(Buffer: PChar): Boolean;
- var
- SaveState: TDatasetState;
- begin
- Result:=True;
- if not Assigned(OnFilterRecord) and Not Filtered then
- Exit;
- SaveState:=SetTempState(dsFilter);
- Try
- FFilterBuffer:=Buffer;
- If Assigned(OnFilterRecord) then
- OnFilterRecord(Self,Result);
- If Result and Filtered and (Filter<>'') then
- Result:=Boolean((FParser.ExtractFromBuffer(FFilterBuffer))^);
- Finally
- RestoreState(SaveState);
- end;
- end;
- {
- procedure TParadox.MDSReadRecord(Buffer:PChar;ARecNo:Integer); //Reads a Rec from Stream in Buffer
- begin
- FStream.Position:=MDSGetRecordOffset(ARecNo);
- FStream.ReadBuffer(Buffer^, FRecSize);
- end;
- procedure TParadox.MDSWriteRecord(Buffer:PChar;ARecNo:Integer); //Writes a Rec from Buffer to Stream
- begin
- FStream.Position:=MDSGetRecordOffset(ARecNo);
- FStream.WriteBuffer(Buffer^, FRecSize);
- FFileModified:=True;
- end;
- procedure TParadox.MDSAppendRecord(Buffer:PChar); //Appends a Rec (from Buffer) to Stream
- begin
- FStream.Position:=MDSGetRecordOffset(FRecCount);
- FStream.WriteBuffer(Buffer^, FRecSize);
- FFileModified:=True;
- end;
- }
- function TParadox.PXGetActiveBuffer(var Buffer: PChar): Boolean;
- begin
- case State of
- dsBrowse:
- if IsEmpty then
- Buffer:=nil
- else
- Buffer:=ActiveBuffer;
- dsEdit,
- dsInsert:
- Buffer:=ActiveBuffer;
- dsFilter:
- Buffer:=FFilterBuffer;
- else
- Buffer:=nil;
- end;
- Result:=(Buffer<>nil);
- end;
- procedure TParadox.SetFileName(const AValue: String);
- begin
- CheckInactive;
- FFileName:=AValue;
- end;
- procedure TParadox.SetInputEncoding(const AValue: String);
- begin
- If Assigned(FDoc) then
- SetParam(SParamInputencoding,AVAlue);
- FInputEncoding:=AValue;
- end;
- procedure TParadox.SetTableName(const AValue: String);
- begin
- If Assigned(FDoc) then
- SetParam(SParamTableName,AVAlue);
- FTableName:=AValue;
- end;
- procedure TParadox.SetTargetEncoding(const AValue: String);
- begin
- If Assigned(FDoc) then
- SetParam(SParamTargetEncoding,AVAlue);
- FTargetEncoding:=AValue;
- end;
- procedure TParadox.SetFilterText(const Value: String);
- begin
- if (Value<>Filter) then
- begin
- ParseFilter(Value);
- inherited;
- if IsCursorOpen and Filtered then
- Refresh;
- end;
- end;
- procedure TParadox.SetFiltered(Value: Boolean);
- begin
- if (Value<>Filtered) then
- begin
- inherited;
- if IsCursorOpen then
- Refresh;
- end;
- end;
- //Abstract Overrides
- function TParadox.AllocRecordBuffer: PChar;
- begin
- Result:=Nil;
- GetMem(Result,SizeOf(TPXRecInfo)+GetRecordSize);
- end;
- procedure TParadox.FreeRecordBuffer (var Buffer: PChar);
- begin
- FreeMem(Buffer);
- end;
- procedure TParadox.InternalInitRecord(Buffer: PChar);
- begin
- fillchar((Buffer+DataOffSet)^,GetRecordSize,0);
- end;
- procedure TParadox.InternalDelete;
- begin
- If (FCurrRecNo<>-1) then
- PX_delete_record(FDoc,FCurrRecNo);
- end;
- procedure TParadox.InternalInitFieldDefs;
- Var
- I, CurrOffSet, ACount : Integer;
- FN : String;
- FS : Integer;
- B : Boolean;
- FT : TFieldType;
- pxf : Ppxfield_t;
- begin
- pxf:=PX_get_fields(FDoc);
- ACount:= PX_get_num_fields(FDoc);
- ReallocMem(FOffsets,ACount*SizeOf(Integer));
- FillChar(FOffSets^,ACount*SizeOf(Integer),0);
- CurrOffSet:=DataOffset;
- For I:=0 to ACount-1 do
- begin
- FOffsets[I]:=CurrOffset;
- FN:=strpas(pxf^.px_fname);
- FT:=PXFieldTypeToFieldType(pxf^.px_ftype);
- If (FT=ftUnKnown) then
- RaiseError(SErrFieldTypeNotSupported,[FN,pxf^.px_ftype]);
- If (FT in [ftString,ftBlob,ftMemo,ftFmtMemo,ftGraphic,ftParadoxOle,ftBytes]) then
- FS:=pxf^.px_flen
- else if (Ft=ftBCD) then
- FS:=pxf^.px_fdc
- else
- FS:=0;
- B:=False; // No way to detect required paradox fields ?
- FieldDefs.Add(FN,ft,FS,B);
- Inc(CurrOffset,pxf^.px_flen);
- Inc(pxf);
- end;
- end;
- procedure TParadox.InternalFirst;
- begin
- FCurrRecNo:=-1;
- end;
- procedure TParadox.InternalLast;
- begin
- FCurrRecNo:=PX_Get_num_records(FDoc);
- end;
- procedure TParadox.SetOpenParams;
- begin
- If (FTargetEncoding<>'') then
- SetParam(SParamTargetEncoding,FTargetEncoding);
- If (FInputEncoding<>'') then
- SetParam(SParamInputEncoding,FInputEncoding);
- end;
- procedure TParadox.OpenBlobFile;
- Var
- BFN : string;
- begin
- BFN:=FBlobFileName;
- If (BFN<>'') then
- if not FileExists(BFN) then
- RaiseError(SErrNoBlobFile,[BFN]);
- If (BFN='') then
- begin
- BFN:=ChangeFileExt(FFileName,'.mb');
- If Not FileExists(BFN) then
- begin
- BFN:=ChangeFileExt(FFileName,'.MB');
- If Not FileExists(BFN) then
- BFN:='';
- end;
- end;
- If (BFN<>'') then
- begin
- Writeln('opening blib file',bfn);
- if PX_set_blob_file(FDoc,PChar(BFN))<>0 then
- RaiseError(SErrInvalidBlobFile,[BFN]);
- FBlobFileName:=BFN;
- end;
- end;
- procedure TParadox.InternalOpen;
- Var
- FN : String;
- begin
- InitPXLib(FPXLibrary);
- If (FFileName='') then
- RaiseError(SErrNoFileName,[]);
- FN:=FFileName;
- FDoc:=PX_New();
- try
- If (px_open_file(FDoc,PChar(FN))<>0) then
- RaiseError(SErrFailedToOpenFile,[FN]);
- SetOpenParams;
- OpenBlobFile;
- InternalInitFieldDefs;
- if DefaultFields then
- CreateFields;
- BindFields(True);
- FCurrRecNo:=-1;
- except
- If Assigned(FDoc) then
- begin
- PX_Delete(FDoc);
- FDoc:=Nil;
- end;
- Raise;
- end;
- try
- ParseFilter(Filter);
- except
- On E : Exception do
- Filter:='';
- end;
- end;
- procedure TParadox.ParseFilter(const AFilter: string);
- begin
- // parser created?
- if Length(AFilter) > 0 then
- begin
- if (FParser = nil) and IsCursorOpen then
- begin
- FParser := TBufDatasetParser.Create(Self);
- end;
- // have a parser now?
- if FParser <> nil then
- begin
- // set options
- FParser.PartialMatch := not (foNoPartialCompare in FilterOptions);
- FParser.CaseInsensitive := foCaseInsensitive in FilterOptions;
- // parse expression
- FParser.ParseExpression(AFilter);
- end;
- end;
- end;
- procedure TParadox.InternalClose;
- begin
- FreeAndNil(FParser);
- FreeMem(FOffsets);
- FOffSets:=Nil;
- FCurrRecNo:=-1;
- If Assigned(FDoc) then
- begin
- PX_close(FDoc);
- PX_Delete(FDOc);
- end;
- FDoc:=Nil;
- end;
- procedure TParadox.InternalPost;
- begin
- CheckActive;
- if ((State<>dsEdit) and (State<>dsInsert)) then
- Exit;
- if (State=dsEdit) then
- PX_put_recordn(FDoc,ActiveBuffer, FCurrRecNo)
- else
- InternalAddRecord(ActiveBuffer,True);
- end;
- function TParadox.IsCursorOpen: Boolean;
- begin
- Result:=(FDoc<>Nil);
- end;
- function TParadox.GetRecord(Buffer: PChar; GetMode: TGetMode; DoCheck: Boolean): TGetResult;
- var
- Accepted: Boolean;
- begin
- Result:=grOk;
- Accepted:=False;
- if (GetRecordCount<1) then
- begin
- Result:=grEOF;
- exit;
- end;
- repeat
- case GetMode of
- gmCurrent:
- if (FCurrRecNo>=GetRecordCount) or (FCurrRecNo<0) then
- Result:=grError;
- gmNext:
- if (FCurrRecNo<GetRecordCount-1) then
- Inc(FCurrRecNo)
- else
- Result:=grEOF;
- gmPrior:
- if (FCurrRecNo>0) then
- Dec(FCurrRecNo)
- else
- result:=grBOF;
- end;
- if result=grOK then
- begin
- PX_get_record(Doc,FCurrRecNo,Buffer+DataOffset);
- PPXRecInfo(Buffer)^.Bookmark:=FCurrRecNo;
- PPXRecInfo(Buffer)^.BookmarkFlag:=bfCurrent;
- if (Filtered) then
- Accepted:=PXFilterRecord(Buffer) //Filtering
- else
- Accepted:=True;
- if (GetMode=gmCurrent) and not Accepted then
- result:=grError;
- end;
- until (result<>grOK) or Accepted;
- end;
- function TParadox.GetFieldData(Field: TField; Buffer: Pointer): Boolean;
- var
- Buf : PChar;
- No,pft,flen : integer;
- pxf : PPx_field;
- Value : Pchar;
- Y,M,D : cint;
- longv : Clong;
- R : Double;
- c : Char;
- begin
- No:=Field.FieldNo-1;
- Buf:=Nil;
- result:=(No>=0) and PXGetActiveBuffer(Buf);
- if result and (buffer <> nil) then
- begin
- pxf:=PX_get_field(FDoc,No);
- Flen:=pxf^.px_flen; // Field length
- pft:=pxf^.px_ftype; // Field type
- Assert(PXFieldTypes[pft]=Field.DataType,'Field types do not match');
- Inc(Buf,FOffsets[No]); // Move to actual field offset
- Case pft of
- pxfAlpha:
- begin
- Result:=PX_get_data_alpha(FDoc,Buf,flen,@value)>0;
- If result then
- begin
- Move(Value^,Buffer^,flen);
- doc^.free(doc,value);
- end;
- end;
- pxfDate:
- begin
- Result:=PX_get_data_long(FDoc,Buf,flen,@longv)>0;
- If Result then
- begin
- // 1721425 is the number of the days between the start of the
- // julian calendar (4714 BC) and jan-00-0000 (Paradox base date)
- // 2415019 is the number of the days between the start of the
- // julian calendar (4714 BC) and dec-30-1899 (TDateTime base date)
- PDateTime(Buffer)^:=Longv+1721425-2415019;
- end;
- end;
- pxfShort:
- begin
- Result:=PX_get_data_short(FDoc,Buf, flen, @D)>0;
- If result then
- PSmallInt(Buffer)^:=D;
- end;
- pxfAutoInc,
- pxfLong:
- begin
- Result:=(PX_get_data_long(FDoc,buf,flen,@longv)>0);
- If Result then
- PInteger(Buffer)^:=Longv;
- end;
- pxfCurrency,
- pxfNumber:
- begin
- Result:=(PX_get_data_double(FDoc,Buf,Flen,@R)>0);
- If Result then
- PDouble(Buffer)^:=R;
- end;
- pxfLogical:
- begin
- Result:=(PX_get_data_byte(FDoc,Buf,flen,@C)>0);
- If result then
- PBoolean(Buffer)^:=(C<>#0);
- end;
- pxfBytes:
- begin
- Result:=PX_get_data_bytes(FDoc,Buf,FLen,@Value)>0;
- If Result then
- begin
- Move(Value^,Buffer^,FLen);
- FDoc^.free(FDoc,value);
- end;
- end;
- pxfMemoBLOb,
- pxfBLOb,
- pxfFmtMemoBLOb,
- pxfOLE,
- pxfGraphic:
- begin
- Result:=True;
- Move(Buf^,Buffer^,FLen);
- end;
- pxfTime:
- begin
- Result:=(PX_get_data_long(FDoc,Buf,flen,@longv)>0);
- If result then
- PDateTime(Buffer)^:=longv/MSecsPerDay;
- end;
- pxfTimestamp:
- begin
- Result:=(PX_get_data_double(FDoc,buf,flen,@R)>0);
- if Result then
- begin
- R:=R/1000.0;
- longv:=trunc(R /86400);
- PX_SdnToGregorian(longv+1721425,@Y,@M,@D);
- longv:=(Trunc(r) mod 86400);
- PDateTime(Buffer)^:=EncodeDate(Y,M,d)+(Longv/MSecsPerday);
- end;
- end;
- pxfBCD:
- begin
- Result:=(PX_get_data_bcd(FDoc,pcuchar(Buf),pxf^.px_fdc,@Value)>0);
- if Result then
- begin
- PCurrency(Buffer)^:=StrToCurr(StrPas(value));
- FDoc^.free(FDoc,value);
- end;
- end;
- else
- RaiseError('Unknown type (%d) (%d)',[pxf^.px_ftype, pxf^.px_flen]);
- end;
- end;
- end;
- procedure TParadox.SetFieldData(Field: TField; Buffer: Pointer);
- var
- DestBuffer: PChar;
- I: integer;
- begin
- DestBuffer:=Nil;
- I:=Field.FieldNo-1;
- if (I >= 0) and PXGetActiveBuffer(DestBuffer) then
- begin
- dataevent(deFieldChange,ptrint(field));
- end;
- end;
- procedure TParadox.DataConvert(aField: TField; aSource, aDest: Pointer;
- aToNative: Boolean);
- begin
- If AField.DataType in [ftDate,ftTime,ftDateTime] then
- PDateTime(aDest)^:=PDateTime(aSource)^
- else
- inherited DataConvert(aField, aSource, aDest, aToNative);
- end;
- function TParadox.CreateBlobStream(Field: TField; Mode: TBlobStreamMode
- ): TStream;
- TYpe
- PGraphicHeader = ^TGraphicHeader;
- Var
- FBuf,Value,V2 : Pchar;
- FLen,Res : Integer;
- M,D : Cint;
- H : PGraphicHeader;
-
- begin
- Result:=Nil;
- FLen:=Field.Size;
- If Mode=bmRead then
- begin
- FBuf:=GetMem(FLen);
- Try
- If Not Field.GetData(FBuf,True) then
- exit;
- if (Field.DataType=ftGraphic) then
- Res:=PX_get_data_graphic(FDoc,FBuf,FLen,@M,@D,@Value)
- else
- Res:=PX_get_data_blob(FDoc,FBuf,FLen,@M,@D,@Value);
- If (Res>0) and (Value<>Nil) then
- begin
- Result:=TMemoryStream.Create;
- V2:=Value;
- if (Field.DataType=ftGraphic) then
- Result.WriteAnsiString('bmp');
- Result.WriteBuffer(V2^,D-SizeOf(TGraphicHeader));
- Result.Position:=0;
- FDoc^.free(FDoc,Value);
- end;
- Finally
- FreeMem(FBuf);
- end;
- end
- else
- Result:=TMemoryStream.Create;
- end;
- function TParadox.GetRecordSize: Word;
- begin
- Result:=PX_Get_RecordSize(FDoc);
- end;
- procedure TParadox.InternalGotoBookmark(ABookmark: Pointer);
- var
- ReqBookmark: integer;
- begin
- ReqBookmark:=PInteger(ABookmark)^;
- if (ReqBookmark>=0) and (ReqBookmark<GetRecordCount) then
- FCurrRecNo:=ReqBookmark
- else
- RaiseError(SErrBookMarkNotFound,[ReqBookmark]);
- end;
- procedure TParadox.InternalSetToRecord(Buffer: PChar);
- var
- ReqBookmark: integer;
- begin
- ReqBookmark:=PPXRecInfo(Buffer)^.Bookmark;
- InternalGotoBookmark (@ReqBookmark);
- end;
- function TParadox.GetBookmarkFlag(Buffer: PChar): TBookmarkFlag;
- begin
- Result:=PPXRecInfo(Buffer)^.BookmarkFlag;
- end;
- procedure TParadox.SetBookmarkFlag(Buffer: PChar; Value: TBookmarkFlag);
- begin
- PPXRecInfo(Buffer)^.BookmarkFlag := Value;
- end;
- procedure TParadox.GetBookmarkData(Buffer: PChar; Data: Pointer);
- begin
- if Data<>nil then
- PInteger(Data)^:=PPXRecInfo(Buffer)^.Bookmark;
- end;
- procedure TParadox.SetBookmarkData(Buffer: PChar; Data: Pointer);
- begin
- if Data<>nil then
- PPXRecInfo(Buffer)^.Bookmark:=PInteger(Data)^
- else
- PPXRecInfo(Buffer)^.Bookmark:=0;
- end;
- procedure TParadox.InternalAddRecord(Buffer: Pointer; DoAppend: Boolean);
- begin
- PXAppendRecord(ActiveBuffer);
- InternalLast;
- end;
- procedure TParadox.PXAppendRecord(Buffer : Pointer);
- begin
- end;
- function TParadox.GetInputEncoding: String;
- begin
- If Assigned(FDoc) then
- Result:=GetParam('inputencoding')
- else
- Result:=FInputEncoding;
- end;
- function TParadox.GetTableName: String;
- begin
- If Assigned(FDoc) then
- Result:=GetParam('tablename')
- else
- Result:=FInputEncoding;
- end;
- function TParadox.GetTargetEncoding: String;
- begin
- If Assigned(FDoc) then
- Result:=GetParam('targetencoding')
- else
- Result:=FTargetEncoding;
- end;
- procedure TParadox.SetRecNo(Value: Integer);
- begin
- CheckBrowseMode;
- if (Value>=1) and (Value<=GetRecordCount) then
- begin
- FCurrRecNo:=Value-1;
- Resync([]);
- end;
- end;
- Function TParadox.GetRecNo: Longint;
- begin
- UpdateCursorPos;
- if (FCurrRecNo<0) then
- Result:=1
- else
- Result:=FCurrRecNo+1;
- end;
- function TParadox.GetParam(const ParamName: String): String;
- Var
- V : Pchar;
- begin
- If Not Assigned(FDoc) then
- RaiseError(SErrParadoxNotOpen,[]);
- if (PX_Get_parameter(FDoc,Pchar(ParamName),@V)<>0) then
- RaiseError(SErrGetParamFailed,[ParamName]);
- If (V<>Nil) then
- Result:=strpas(V);
- end;
- procedure TParadox.SetParam(const ParamName, ParamValue: String);
- begin
- If Not Assigned(FDoc) then
- RaiseError(SErrParadoxNotOpen,[]);
- if (PX_Set_parameter(FDoc,Pchar(ParamName),PChar(ParamValue))<>0) then
- RaiseError(SErrSetParamFailed,[ParamName]);
- end;
- Function TParadox.GetRecordCount: Longint;
- begin
- If Assigned(FDoc) then
- Result:=PX_Get_num_records(FDoc)
- else
- Result:=0;
- end;
- end.
|