* Map dfANY to CSV data, allows to use regular Load/Save methods in TCSVDataset. Check if me can introduce dfCSV

git-svn-id: trunk@30433 -
This commit is contained in:
michael 2015-04-05 09:23:28 +00:00
parent 59e2728940
commit 7ad2f934f5
2 changed files with 17 additions and 7 deletions

View File

@ -496,7 +496,6 @@ type
function GetRecordUpdateBufferCached(const ABookmark : TBufBookmark; IncludePrior : boolean = false) : boolean; function GetRecordUpdateBufferCached(const ABookmark : TBufBookmark; IncludePrior : boolean = false) : boolean;
function GetActiveRecordUpdateBuffer : boolean; function GetActiveRecordUpdateBuffer : boolean;
procedure ParseFilter(const AFilter: string); procedure ParseFilter(const AFilter: string);
function GetPacketReader(const Format: TDataPacketFormat; const AStream: TStream): TDataPacketReader;
function GetIndexDefs : TIndexDefs; function GetIndexDefs : TIndexDefs;
function GetIndexFieldNames: String; function GetIndexFieldNames: String;
@ -560,6 +559,7 @@ type
function IsReadFromPacket : Boolean; function IsReadFromPacket : Boolean;
function getnextpacket : integer; function getnextpacket : integer;
procedure ActiveBufferToRecord; procedure ActiveBufferToRecord;
function GetPacketReader(const Format: TDataPacketFormat; const AStream: TStream): TDataPacketReader; virtual;
// abstracts, must be overidden by descendents // abstracts, must be overidden by descendents
function Fetch : boolean; virtual; function Fetch : boolean; virtual;
function LoadField(FieldDef : TFieldDef;buffer : pointer; out CreateBlob : boolean) : boolean; virtual; function LoadField(FieldDef : TFieldDef;buffer : pointer; out CreateBlob : boolean) : boolean; virtual;

View File

@ -81,7 +81,7 @@ Type
function GetCurrentRecord : boolean; override; function GetCurrentRecord : boolean; override;
procedure GotoNextRecord; override; procedure GotoNextRecord; override;
procedure InitLoadRecords; override; procedure InitLoadRecords; override;
procedure RestoreRecord override; procedure RestoreRecord; override;
procedure StoreRecord(ARowState : TRowState; AUpdOrder : integer = 0); override; procedure StoreRecord(ARowState : TRowState; AUpdOrder : integer = 0); override;
class function RecognizeStream(AStream : TStream) : boolean; override; class function RecognizeStream(AStream : TStream) : boolean; override;
Property Options : TCSVOptions Read FOptions; Property Options : TCSVOptions Read FOptions;
@ -95,6 +95,7 @@ Type
FCSVOptions: TCSVOptions; FCSVOptions: TCSVOptions;
procedure SetCSVOptions(AValue: TCSVOptions); procedure SetCSVOptions(AValue: TCSVOptions);
Protected Protected
function GetPacketReader(const Format: TDataPacketFormat; const AStream: TStream): TDataPacketReader; override;
procedure LoadBlobIntoBuffer(FieldDef: TFieldDef;ABlobBuf: PBufBlobField); override; procedure LoadBlobIntoBuffer(FieldDef: TFieldDef;ABlobBuf: PBufBlobField); override;
procedure InternalInitFieldDefs; override; procedure InternalInitFieldDefs; override;
Public Public
@ -120,7 +121,7 @@ implementation
{ TCSVDataPacketReader } { TCSVDataPacketReader }
Procedure TCSVDataPacketReader.ReadNextRow; procedure TCSVDataPacketReader.ReadNextRow;
begin begin
@ -167,7 +168,7 @@ begin
FOwnsOptions:=AOptions=Nil; FOwnsOptions:=AOptions=Nil;
end; end;
Destructor TCSVDataPacketReader.Destroy; destructor TCSVDataPacketReader.Destroy;
begin begin
If FOwnsOptions then If FOwnsOptions then
FreeAndNil(FOPtions); FreeAndNil(FOPtions);
@ -302,6 +303,15 @@ begin
FCSVOptions.Assign(AValue); FCSVOptions.Assign(AValue);
end; end;
function TCustomCSVDataset.GetPacketReader(const Format: TDataPacketFormat;
const AStream: TStream): TDataPacketReader;
begin
If (Format=dfAny) then
Result:=TCSVDataPacketReader.Create(Self,AStream,FCSVOptions)
else
Result:=Inherited GetPacketReader(Format,AStream);
end;
procedure TCustomCSVDataset.LoadBlobIntoBuffer(FieldDef: TFieldDef; procedure TCustomCSVDataset.LoadBlobIntoBuffer(FieldDef: TFieldDef;
ABlobBuf: PBufBlobField); ABlobBuf: PBufBlobField);
begin begin
@ -313,13 +323,13 @@ begin
// Do nothing // Do nothing
end; end;
Constructor TCustomCSVDataset.Create(AOwner: TComponent); constructor TCustomCSVDataset.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
FCSVOptions:=TCSVOptions.Create; FCSVOptions:=TCSVOptions.Create;
end; end;
Destructor TCustomCSVDataset.Destroy; destructor TCustomCSVDataset.Destroy;
begin begin
FreeAndNil(FCSVOptions); FreeAndNil(FCSVOptions);
inherited Destroy; inherited Destroy;
@ -342,7 +352,7 @@ begin
end; end;
end; end;
procedure TCustomCSVDataset.LoadFromCSVFile(Const AFileName: string); procedure TCustomCSVDataset.LoadFromCSVFile(const AFileName: string);
Var Var
F : TFileStream; F : TFileStream;