AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

RecNo gibt ergibt immer -1

Ein Thema von HolgerCW · begonnen am 19. Mai 2021 · letzter Beitrag vom 20. Mai 2021
Antwort Antwort
HolgerCW

Registriert seit: 28. Nov 2006
Ort: Marl
1.207 Beiträge
 
Delphi XE7 Enterprise
 
#1

AW: RecNo gibt ergibt immer -1

  Alt 20. Mai 2021, 16:55
Hallo zusammen,

vielen Dank für Euren Input. nun habe ich es hinbekommen.

Zitat:
procedure TMainForm.DBGridMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ShowMessage(IntToStr((Sender as TDBGrid).DataSource.DataSet.RecNo));
end;
Das ging leider nicht

Zitat:
Das wird eigentlich vom TDBGrid (ohne jedewede weitere Programmierung) unterstützt.
Das ist nur bei dem TJVDBGrid so

So hat es geklappt:

Code:
procedure TForm1.DBG1MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin

 if ssShift in Shift then
  SetBookMarkRange(Sender as TDBGrid,DM1.Query1);

end;

-----------------


procedure TDM1.Query1AfterScroll(DataSet: TDataSet);
begin

 if SettingBookmarkRange then exit;

 PreviousRowID := CurrentRowID;
 CurrentRowID := DM1.Query1.FieldByName('ID').AsInteger;

end;


----------------

var
 SettingBookmarkRange: Boolean;
 CurrentRowID,
 PreviousRowID: Integer;

procedure SetBookmarkRange(DBGrid_Shift:TDBGrid;Query_Shift:TQuery);
var
 BM,
 TempBM : TBookmark;
 NewBM : TBookmarkStr;
 FoundPrevious : Boolean;
begin

  //  This code is called after the user does a Shift-Click in the grid
  //  First we set a flag to temporarily prevent the CurrrentRowID and
  //  PreviousrowID from being updated during the dataset's OnScroll event
  SettingBookmarkRange := True;

  BM := Query_Shift.GetBookmark;

  //  Set a flag to keep track of whether we've found the row with the PreviousRowID
  FoundPrevious := False;
  try

   Query_Shift.DisableControls;

   //  First, search forwards to see if we can find the the row with the PreviousRowID
   //  In other words, we're first checking that the Shift-Click was on a row *above*
   //  the previous row
   Query_Shift.Next;

   while not FoundPrevious and not Query_Shift.Eof do
   begin

    if Query_Shift.FieldByName('ID').AsInteger = PreviousRowID then
    begin

     FoundPrevious := True;

     //  We found the row with the PreviousRowID, so now get the Grid to add it, and
     //  all the rows back to where we started, in its SelectedRows list
     while not Query_Shift.Bof and (Query_Shift.FieldByName('ID').AsInteger <> CurrentRowID) do
     begin

      DBGrid_Shift.SelectedRows.CurrentRowSelected := True;
      Query_Shift.Prior;

     end;

    end
    else

     Query_Shift.Next;

    end;

    if not FoundPrevious then
    begin
     //  If we get here, the Shift-Click must have been in a row further down the
     //  grid than the previously-current one
     while not FoundPrevious and not Query_Shift.Bof do
     begin

      if Query_Shift.FieldByName('ID').AsInteger = PreviousRowID then
      begin

       FoundPrevious := True;
       //  We found the row with the PreviousRowID, so now get the Grid to add it, and
       //  all the rows back to where we started, in its SelectedRows list
       while not Query_Shift.Eof and (Query_Shift.FieldByName('ID').AsInteger <> CurrentRowID) do
       begin

        DBGrid_Shift.SelectedRows.CurrentRowSelected := True;
        Query_Shift.Next;

       end;

      end
      else

       Query_Shift.Prior;

      end;

    end;

  finally

   Query_Shift.GotoBookmark(BM);
   Query_Shift.FreeBookmark(BM);
   Query_Shift.EnableControls;
   SettingBookmarkRange := False;

  end;

end;
Gruss

Holger
  Mit Zitat antworten Zitat
HolgerCW

Registriert seit: 28. Nov 2006
Ort: Marl
1.207 Beiträge
 
Delphi XE7 Enterprise
 
#2

AW: RecNo gibt ergibt immer -1

  Alt 20. Mai 2021, 16:58
Rolf du hast Recht.

Das Projekt ist schon sehr alt, aber sehr groß. es wird auch bald abgelöst durch eine andere Software, aber bis dahin wird es halt noch ein wenig gepflegt und wünsche umgesetzt.

Gruss

Holger
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:27 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz