Allows the maximum record size in TFixedDataset and descendents to be modifyed.

git-svn-id: trunk@11727 -
This commit is contained in:
sekelsenmat 2008-09-07 19:17:12 +00:00
parent 156acf3817
commit b573908e93

View File

@ -125,9 +125,6 @@ interface
uses uses
DB, Classes, SysUtils; DB, Classes, SysUtils;
const
MAXSTRLEN = 250;
type type
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// TRecInfo // TRecInfo
@ -165,6 +162,7 @@ type
FRecInfoOfs :Integer; FRecInfoOfs :Integer;
FBookmarkOfs :Integer; FBookmarkOfs :Integer;
FSaveChanges :Boolean; FSaveChanges :Boolean;
FMaxRecordLength :Cardinal;
protected protected
function AllocRecordBuffer: PChar; override; function AllocRecordBuffer: PChar; override;
procedure FreeRecordBuffer(var Buffer: PChar); override; procedure FreeRecordBuffer(var Buffer: PChar); override;
@ -199,6 +197,7 @@ type
function BufToStore(Buffer: PChar): String; virtual; function BufToStore(Buffer: PChar): String; virtual;
function StoreToBuf(Source: String): String; virtual; function StoreToBuf(Source: String): String; virtual;
public public
property MaxRecordLength: Cardinal read FMaxRecordLength write FMaxRecordLength default 250;
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
function GetFieldData(Field: TField; Buffer: Pointer): Boolean; override; function GetFieldData(Field: TField; Buffer: Pointer): Boolean; override;
@ -274,20 +273,20 @@ implementation
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
constructor TFixedFormatDataSet.Create(AOwner : TComponent); constructor TFixedFormatDataSet.Create(AOwner : TComponent);
begin begin
FFileMustExist := TRUE; FFileMustExist := TRUE;
FLoadfromStream := False; FLoadfromStream := False;
FRecordSize := 0; FRecordSize := 0;
FTrimSpace := TRUE; FTrimSpace := TRUE;
FSchema := TStringList.Create; FSchema := TStringList.Create;
FData := TStringList.Create; // Load the textfile into a stringlist FData := TStringList.Create; // Load the textfile into a stringlist
inherited Create(AOwner); inherited Create(AOwner);
end; end;
destructor TFixedFormatDataSet.Destroy; destructor TFixedFormatDataSet.Destroy;
begin begin
inherited Destroy; inherited Destroy;
FData.Free; FData.Free;
FSchema.Free; FSchema.Free;
end; end;
procedure TFixedFormatDataSet.SetSchema(const Value: TStringList); procedure TFixedFormatDataSet.SetSchema(const Value: TStringList);
@ -338,7 +337,7 @@ begin
FData.Objects[i] := TObject(Pointer(i+1)); // Fabricate Bookmarks FData.Objects[i] := TObject(Pointer(i+1)); // Fabricate Bookmarks
end; end;
if (Maxlen = 0) then if (Maxlen = 0) then
Maxlen := MAXSTRLEN; Maxlen := FMaxRecordLength;
LstFields := TStringList.Create; LstFields := TStringList.Create;
try try
LoadFieldScheme(LstFields, Maxlen); LoadFieldScheme(LstFields, Maxlen);
@ -368,13 +367,13 @@ begin
end; end;
if not FLoadfromStream then if not FLoadfromStream then
FData.LoadFromFile(FileName); FData.LoadFromFile(FileName);
FRecordSize := MAXSTRLEN; FRecordSize := FMaxRecordLength;
InternalInitFieldDefs; InternalInitFieldDefs;
if DefaultFields then if DefaultFields then
CreateFields; CreateFields;
BindFields(TRUE); BindFields(TRUE);
if FRecordSize = 0 then if FRecordSize = 0 then
FRecordSize := MAXSTRLEN; FRecordSize := FMaxRecordLength;
BookmarkSize := SizeOf(Integer); BookmarkSize := SizeOf(Integer);
FRecInfoOfs := FRecordSize + CalcFieldsSize; // Initialize the offset for TRecInfo in the buffer FRecInfoOfs := FRecordSize + CalcFieldsSize; // Initialize the offset for TRecInfo in the buffer
FBookmarkOfs := FRecInfoOfs + SizeOf(TRecInfo); FBookmarkOfs := FRecInfoOfs + SizeOf(TRecInfo);