diff --git a/packages/fcl-db/src/Dataset.txt b/packages/fcl-db/src/Dataset.txt index 78a53eedea..92d1fbd44a 100644 --- a/packages/fcl-db/src/Dataset.txt +++ b/packages/fcl-db/src/Dataset.txt @@ -186,7 +186,6 @@ This method should be called from InternalOpen, and should initialize FieldDef definitions for all fields in a record. It should add these definitions to the FFielddefs object. - procedure InternalInitRecord(Buffer: PChar); virtual; abstract; --------------------------------------------------------------- This method is called to initialize a field buffer when the dataset diff --git a/packages/fcl-db/src/dbase/dbf.pas b/packages/fcl-db/src/dbase/dbf.pas index 5792b17bf0..de278034d8 100644 --- a/packages/fcl-db/src/dbase/dbf.pas +++ b/packages/fcl-db/src/dbase/dbf.pas @@ -157,6 +157,7 @@ type FParser: TDbfParser; FBlobStreams: PDbfBlobList; FUserStream: TStream; // user stream to open + FUserMemoStream: TStream; // user-provided/expected stream backing memo file storage FTableName: string; // table path and file name FRelativePath: string; FAbsolutePath: string; @@ -397,7 +398,10 @@ type property PhysicalRecordCount: Integer read GetPhysicalRecordCount; property KeySize: Integer read GetKeySize; property DbfFile: TDbfFile read FDbfFile; + // Storage for data file if using memory storage property UserStream: TStream read FUserStream write FUserStream; + // Storage for memo file - if any - when using memory storage + property UserMemoStream: TStream read FUserMemoStream write FUserMemoStream; property DisableResyncOnPost: Boolean read FDisableResyncOnPost write FDisableResyncOnPost; published property DateTimeHandling: TDateTimeHandling @@ -1145,6 +1149,7 @@ begin if FStorage = stoMemory then begin FDbfFile.Stream := FUserStream; + FDbfFile.MemoStream := FUserMemoStream; FDbfFile.Mode := FileModeToMemMode[FileOpenMode]; end else begin FDbfFile.FileName := FAbsolutePath + FTableName; @@ -1548,9 +1553,12 @@ begin else FDbfFile.FinishCreate(ADbfFieldDefs, 512); - // if creating memory table, copy stream pointer + // if creating memory table, use user-designated stream if FStorage = stoMemory then + begin FUserStream := FDbfFile.Stream; + FUserMemoStream := FDbfFile.MemoStream; + end; // create all indexes for I := 0 to FIndexDefs.Count-1 do diff --git a/packages/fcl-db/src/dbase/dbf_dbffile.pas b/packages/fcl-db/src/dbase/dbf_dbffile.pas index 221c4113a4..72a09487ec 100644 --- a/packages/fcl-db/src/dbase/dbf_dbffile.pas +++ b/packages/fcl-db/src/dbase/dbf_dbffile.pas @@ -47,6 +47,7 @@ type protected FMdxFile: TIndexFile; FMemoFile: TMemoFile; + FMemoStream: TStream; FFieldDefs: TDbfFieldDefs; FIndexNames: TStringList; FIndexFiles: TList; @@ -138,6 +139,8 @@ type procedure RecordRecalled(RecNo: Integer; Buffer: TRecordBuffer); property MemoFile: TMemoFile read FMemoFile; + // Backing stream for stream/memory-based memo "files" + property MemoStream: TStream read FMemoStream write FMemoStream; property FieldDefs: TDbfFieldDefs read FFieldDefs; property IndexNames: TStringList read FIndexNames; property IndexFiles: TList read FIndexFiles; @@ -505,6 +508,8 @@ begin MemoFileClass := TDbaseMemoFile; //fallback/default FMemoFile := MemoFileClass.Create(Self); FMemoFile.FileName := lMemoFileName; + if (Mode in [pfMemoryOpen,pfMemoryCreate]) then + FMemoFile.Stream:=FMemoStream; FMemoFile.Mode := Mode; FMemoFile.AutoCreate := true; FMemoFile.MemoRecordSize := 0; @@ -869,6 +874,8 @@ begin else FMemoFile := TDbaseMemoFile.Create(Self); FMemoFile.FileName := lMemoFileName; + if (Mode in [pfMemoryOpen,pfMemoryCreate]) then + FMemoFile.Stream:=FMemoStream; FMemoFile.Mode := Mode; FMemoFile.AutoCreate := AutoCreate; FMemoFile.MemoRecordSize := MemoSize; @@ -1386,7 +1393,10 @@ begin if FMemoFile <> nil then DestDbfFile.FinishCreate(DestFieldDefs, FMemoFile.RecordSize) else - DestDbfFile.FinishCreate(DestFieldDefs, 512); + if (DestDbfFile.DbfVersion in [xFoxPro,xVisualFoxPro]) then + DestDbfFile.FinishCreate(DestFieldDefs, 64) {VFP default} + else + DestDbfFile.FinishCreate(DestFieldDefs, 512); // adjust size and offsets of fields GetMem(RestructFieldInfo, sizeof(TRestructFieldInfo)*DestFieldDefs.Count); diff --git a/packages/fcl-db/tests/testspecifictdbf.pas b/packages/fcl-db/tests/testspecifictdbf.pas index a1000cf815..a2816f851b 100644 --- a/packages/fcl-db/tests/testspecifictdbf.pas +++ b/packages/fcl-db/tests/testspecifictdbf.pas @@ -386,9 +386,15 @@ const var ds : TDBF; i: integer; + DBFStream: TMemoryStream; + MemoStream: TMemoryStream; begin ds := TDBF.Create(nil); - ds.Storage:=stoMemory; + DBFStream:=TMemoryStream.Create; + MemoStream:=TMemoryStream.Create; + DS.Storage:=stoMemory; + DS.UserStream:=DBFStream; + DS.UserMemoStream:=MemoStream; DS.FieldDefs.Add('ID',ftInteger); DS.FieldDefs.Add('NAME',ftMemo); DS.OpenMode:=omAutoCreate; //let dbf code create memo etc files when needed @@ -416,6 +422,8 @@ begin DS.Close; ds.free; + DBFStream.Free; + MemoStream.Free; end; procedure TTestSpecificTDBF.TestLargeString;