Solved

Validating TBookMarkStr

Posted on 1998-09-21
6
754 Views
Last Modified: 2010-04-04
You can use BookMarkValid to validate TBookMark's. Is there anyway to validate TBookMarkStr's?

Thanks, Tom.
0
Comment
Question by:tomcorcoran
  • 4
  • 2
6 Comments
 
LVL 3

Expert Comment

by:rickpet
ID: 1340500
Tom...

check out

TI 2976:TDBGrid and Multi-Selecting Records

KEYWORDS: Database, TDBGrid, multi-select, dgMultiSelect, SelectedRows AREA: D
When you add [dgMultiSelect] to the Options
property of a DBGrid, you give yourself the ability
to select multiple records within the grid.
The records you select are represented as bookmarks
and are stored in the SelectedRows property.
The SelectedRows property is an object of type
TBookmarkList.  The properties and methods aredescribed below.
// property SelectedRows: TBookmarkList read FBookmarks;
//   TBookmarkList = class//   public
     {* The Clear method will free all the selected records
        within the DBGrid *}     // procedure Clear;
    {* The Delete method will delete all the selected rows
       from the dataset *}    // procedure Delete;
    {* The Find method determines whether a bookmark is
       in the selected list. *}    // function  Find(const Item: TBookmarkStr;
    //      var Index: Integer): Boolean;
    {* The IndexOf method returns the index of the
       bookmark within the Items property. *}
    // function IndexOf(const Item: TBookmarkStr): Integer;
    {* The Refresh method returns a boolean value to notify
       whether any orphans were dropped (deleted) during the
       time the record has been selected in the grid.  The
       refresh method can be used to update the selected list
       to minimize the possibility of accessing a deleted       record. *}
    // function  Refresh: Boolean;  True = orphans found
    {* The Count property returns the number of currently
       selected items in the DBGrid *}
    // property Count: Integer read GetCount;
    {* The CurrentRowSelected property returns a boolean
       value and determines whether the current row is       selected or not. *}
    // property CurrentRowSelected: Boolean
    //      read GetCurrentRowSelected    //      write SetCurrentRowSelected;
    {* The Items property is a TStringList of       TBookmarkStr *}
    // property Items[Index: Integer]: TBookmarkStr
    //      read GetItem; default;//  end;unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids, DBGrids, DB, DBTables;type  TForm1 = class(TForm)
    Table1: TTable;    DBGrid1: TDBGrid;    Count: TButton;
    Selected: TButton;    Clear: TButton;    Delete: TButton;
    Select: TButton;    GetBookMark: TButton;    Find: TButton;
    FreeBookmark: TButton;    DataSource1: TDataSource;
    procedure CountClick(Sender: TObject);
    procedure SelectedClick(Sender: TObject);
    procedure ClearClick(Sender: TObject);
    procedure DeleteClick(Sender: TObject);
    procedure SelectClick(Sender: TObject);
    procedure GetBookMarkClick(Sender: TObject);
    procedure FindClick(Sender: TObject);
    procedure FreeBookmarkClick(Sender: TObject);  private
    { Private declarations }  public    { Public declarations }  end;var
  Form1: TForm1;  Bookmark1: TBookmark;  z: Integer;implementation{$R *.DFM}
//Example of the Count propertyprocedure TForm1.CountClick(Sender: TObject);
begin  if DBgrid1.SelectedRows.Count > 0 then  begin
    showmessage(inttostr(DBgrid1.SelectedRows.Count));  end;end;
//Example of the CurrentRowSelected property
procedure TForm1.SelectedClick(Sender: TObject);begin
  if DBgrid1.SelectedRows.CurrentRowSelected then    showmessage('Selected');
end;//Example of the Clear Methodprocedure TForm1.ClearClick(Sender: TObject);
begin  dbgrid1.SelectedRows.Clear;end;//Example of the Delete Method
procedure TForm1.DeleteClick(Sender: TObject);begin
  DBgrid1.SelectedRows.Delete;end;{*
   This example iterates through the selected rows
   of the grid and displays the second field of   the dataset.
   The Method DisableControls is used so that the
   DBGrid will not update when the dataset is changed.
   The last position of the dataset is saved as   a TBookmark.
   The IndexOf method is called to check whether or
   not the bookmark is still existent.
   The decision of using the IndexOf method rather
   than the Refresh method should be determined by the   specific application.*}
procedure TForm1.SelectClick(Sender: TObject);var  x: word;
  TempBookmark: TBookMark;begin  DBGrid1.Datasource.Dataset.DisableControls;
  with DBgrid1.SelectedRows do  if Count > 0 then  begin
    TempBookmark:= DBGrid1.Datasource.Dataset.GetBookmark;
    for x:= 0 to Count - 1 do    begin      if IndexOf(Items[x]) > -1 then
      begin        DBGrid1.Datasource.Dataset.Bookmark:= Items[x];
        showmessage(DBGrid1.Datasource.Dataset.Fields[1].AsString);      end;
    end;    DBGrid1.Datasource.Dataset.GotoBookmark(TempBookmark);
    DBGrid1.Datasource.Dataset.FreeBookmark(TempBookmark);  end;
  DBGrid1.Datasource.Dataset.EnableControls;end;{*
This example allows you to set a bookmark and
and then search for the bookmarked record within
selected a record(s) within the DBGrid.*}//Sets a bookmark
procedure TForm1.GetBookMarkClick(Sender: TObject);begin
  Bookmark1:= DBGrid1.Datasource.Dataset.GetBookmark;end;//Frees the bookmark
procedure TForm1.FreeBookmarkClick(Sender: TObject);begin
  if assigned(Bookmark1) then  begin
    DBGrid1.Datasource.Dataset.FreeBookmark(Bookmark1);    Bookmark1:= nil;
  end;end;//Uses the Find method to locate the position of the
//bookmarked record within the selected list in the DBGrid
procedure TForm1.FindClick(Sender: TObject);begin  if assigned(Bookmark1) then
  begin    if DBGrid1.SelectedRows.Find(TBookMarkStr(Bookmark1),z) then
      showmessage(inttostr(z));  end;end;end.
0
 

Author Comment

by:tomcorcoran
ID: 1340501
RickPet, Thanks for the link though I'm not sure why you included it, I need to validate a TBookMarkStr and am not using a grid. Thanks, Tom.
0
 
LVL 3

Expert Comment

by:rickpet
ID: 1340502
Okay...

went browing the VCL source...

seems that you should be able to typecast the bookmarkstr to a pointer to get it to work

BookmarkValid(Pointer(Value))

this is how they move the cursor position when you set the Bookmark...

procedure TDataset.SetBookmarkStr(const Value: TBookmarkStr);
begin
  GotoBookmark(Pointer(Value));
end;


Rick...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:rickpet
ID: 1340503
Tom...

Did that fix your problem???

Rick
0
 

Author Comment

by:tomcorcoran
ID: 1340504
Rick,

I think it worked, no blow up now, but need to do more testing. Thanks a lot. Answer so I can grade.  

Tom.
0
 
LVL 3

Accepted Solution

by:
rickpet earned 50 total points
ID: 1340505
Hope it doesn't GPF you...cross fingers...

Rick
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sending Gmail through Delphi 3 90
Strange code, can use it, but i cant figure out what it does. 3 54
Delphi cmd execution 6 55
Delphi 2 45
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now