Browse Source

* Fixed IsUniDirectional with help from Thorsten Engler, bug #8211

git-svn-id: trunk@6375 -
joost 18 years ago
parent
commit
74646df93b
2 changed files with 51 additions and 29 deletions
  1. 49 28
      fcl/db/dataset.inc
  2. 2 1
      fcl/db/db.pp

+ 49 - 28
fcl/db/dataset.inc

@@ -36,6 +36,7 @@ begin
   FBufferCount := 0;
   FBufferCount := 0;
   FEOF := True;
   FEOF := True;
   FBOF := True;
   FBOF := True;
+  FIsUniDirectional := False;
 end;
 end;
 
 
 
 
@@ -129,7 +130,7 @@ Function TDataset.BookmarkAvailable: Boolean;
 Const BookmarkStates = [dsBrowse,dsEdit,dsInsert];
 Const BookmarkStates = [dsBrowse,dsEdit,dsInsert];
 
 
 begin
 begin
-  Result:=(Not IsEmpty) and (State in BookmarkStates)
+  Result:=(Not IsEmpty) and  not FIsUniDirectional and (State in BookmarkStates)
           and (getBookMarkFlag(ActiveBuffer)=bfCurrent);
           and (getBookMarkFlag(ActiveBuffer)=bfCurrent);
 end;
 end;
 
 
@@ -139,7 +140,7 @@ var
   I: Integer;
   I: Integer;
 begin
 begin
   FCalcBuffer := Buffer;
   FCalcBuffer := Buffer;
-  if (State <> dsInternalCalc) and (IsUniDirectional = False) then
+  if (State <> dsInternalCalc) and (FIsUniDirectional = False) then
   begin
   begin
     ClearCalcFields(CalcBuffer);
     ClearCalcFields(CalcBuffer);
     for I := 0 to Fields.Count - 1 do
     for I := 0 to Fields.Count - 1 do
@@ -718,6 +719,7 @@ begin
 {$ifdef dsdebug}
 {$ifdef dsdebug}
   Writeln ('GetPriorRecord: Getting previous record');
   Writeln ('GetPriorRecord: Getting previous record');
 {$endif}
 {$endif}
+  CheckBiDirectional;
   If FRecordCount>0 Then SetCurrentRecord(0);
   If FRecordCount>0 Then SetCurrentRecord(0);
   Result:=GetRecord(FBuffers[FBuffercount],gmPrior,True)=grOK;
   Result:=GetRecord(FBuffers[FBuffercount],gmPrior,True)=grOK;
   if result then
   if result then
@@ -863,6 +865,11 @@ begin
     ShowException(ExceptObject,ExceptAddr);
     ShowException(ExceptObject,ExceptAddr);
 end;
 end;
 
 
+procedure TDataSet.SetUniDirectional(const Value: Boolean);
+begin
+  FIsUniDirectional := Value;
+end;
+
 Procedure TDataset.SetActive (Value : Boolean);
 Procedure TDataset.SetActive (Value : Boolean);
 
 
 begin
 begin
@@ -1065,7 +1072,7 @@ begin
       bfBOF : InternalFirst;
       bfBOF : InternalFirst;
       bfEOF : InternalLast;
       bfEOF : InternalLast;
       end;
       end;
-    FCurrentRecord:=index;
+    if not FIsUniDirectional then FCurrentRecord:=index;
     end;
     end;
 end;
 end;
 
 
@@ -1097,6 +1104,7 @@ end;
 Procedure TDataset.SetFiltered(Value: Boolean);
 Procedure TDataset.SetFiltered(Value: Boolean);
 
 
 begin
 begin
+  if Value then CheckBiDirectional;
   FFiltered := value;
   FFiltered := value;
 end;
 end;
 
 
@@ -1537,17 +1545,26 @@ Procedure TDataset.First;
 
 
 
 
 begin
 begin
-  CheckBrowseMode;
-  DoBeforeScroll;
-  ClearBuffers;
-  try
-    InternalFirst;
-    GetNextRecords;
-  finally
-    FBOF:=True;
-    DataEvent(deDatasetChange,0);
-    DoAfterScroll;
-  end;
+  if not FBof then
+    begin
+    CheckBrowseMode;
+    DoBeforeScroll;
+    if FIsUniDirectional then
+      begin
+      Active := False;
+      Active := True;
+      end
+    else
+      ClearBuffers;
+    try
+      InternalFirst;
+      if not FIsUniDirectional then GetNextRecords;
+    finally
+      FBOF:=True;
+      DataEvent(deDatasetChange,0);
+      DoAfterScroll;
+      end;
+    end;
 end;
 end;
 
 
 Procedure TDataset.FreeBookmark(ABookmark: TBookmark);
 Procedure TDataset.FreeBookmark(ABookmark: TBookmark);
@@ -1672,19 +1689,23 @@ end;
 Procedure TDataset.Last;
 Procedure TDataset.Last;
 
 
 begin
 begin
-  CheckBrowseMode;
-  DoBeforeScroll;
-  ClearBuffers;
-  try
-    InternalLast;
-    GetPriorRecords;
-    if FRecordCount>0 then
-      FActiveRecord:=FRecordCount-1
-  finally
-    FEOF:=true;
-    DataEvent(deDataSetChange, 0);
-    DoAfterScroll;
-  end;
+  CheckBiDirectional;
+  if not FEOF then
+    begin
+    CheckBrowseMode;
+    DoBeforeScroll;
+    ClearBuffers;
+    try
+      InternalLast;
+      GetPriorRecords;
+      if FRecordCount>0 then
+        FActiveRecord:=FRecordCount-1
+    finally
+      FEOF:=true;
+      DataEvent(deDataSetChange, 0);
+      DoAfterScroll;
+      end;
+    end;
 end;
 end;
 
 
 Function TDataset.MoveBy(Distance: Longint): Longint;
 Function TDataset.MoveBy(Distance: Longint): Longint;
@@ -1883,7 +1904,7 @@ begin
 {$ifdef dsdebug}
 {$ifdef dsdebug}
     Writeln ('Resync called');
     Writeln ('Resync called');
 {$endif}
 {$endif}
-
+  CheckBiDirectional;
 // place the cursor of the underlying dataset to the active record
 // place the cursor of the underlying dataset to the active record
 //  SetCurrentRecord(FActiverecord);
 //  SetCurrentRecord(FActiverecord);
 
 

+ 2 - 1
fcl/db/db.pp

@@ -1131,6 +1131,7 @@ type
     function IsCursorOpen: Boolean; virtual; abstract;
     function IsCursorOpen: Boolean; virtual; abstract;
     procedure SetBookmarkFlag(Buffer: PChar; Value: TBookmarkFlag); virtual; abstract;
     procedure SetBookmarkFlag(Buffer: PChar; Value: TBookmarkFlag); virtual; abstract;
     procedure SetBookmarkData(Buffer: PChar; Data: Pointer); virtual; abstract;
     procedure SetBookmarkData(Buffer: PChar; Data: Pointer); virtual; abstract;
+    procedure SetUniDirectional(const Value: Boolean);
   public
   public
     constructor Create(AOwner: TComponent); override;
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
     destructor Destroy; override;
@@ -1199,7 +1200,7 @@ type
 //    property Fields[Index: Longint]: TField read GetField write SetField;
 //    property Fields[Index: Longint]: TField read GetField write SetField;
     property Found: Boolean read FFound;
     property Found: Boolean read FFound;
     property Modified: Boolean read FModified write SetModified;
     property Modified: Boolean read FModified write SetModified;
-    property IsUniDirectional: Boolean read FIsUniDirectional write FIsUniDirectional default False;
+    property IsUniDirectional: Boolean read FIsUniDirectional default False;
     property RecordCount: Longint read GetRecordCount;
     property RecordCount: Longint read GetRecordCount;
     property RecNo: Longint read GetRecNo write SetRecNo;
     property RecNo: Longint read GetRecNo write SetRecNo;
     property RecordSize: Word read GetRecordSize;
     property RecordSize: Word read GetRecordSize;