boardtc
asked on
Validating TBookMarkStr
You can use BookMarkValid to validate TBookMark's. Is there anyway to validate TBookMarkStr's?
Thanks, Tom.
Thanks, Tom.
ASKER
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.
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(Valu e))
this is how they move the cursor position when you set the Bookmark...
procedure TDataset.SetBookmarkStr(co nst Value: TBookmarkStr);
begin
GotoBookmark(Pointer(Value ));
end;
Rick...
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(Valu
this is how they move the cursor position when you set the Bookmark...
procedure TDataset.SetBookmarkStr(co
begin
GotoBookmark(Pointer(Value
end;
Rick...
Tom...
Did that fix your problem???
Rick
Did that fix your problem???
Rick
ASKER
Rick,
I think it worked, no blow up now, but need to do more testing. Thanks a lot. Answer so I can grade.
Tom.
I think it worked, no blow up now, but need to do more testing. Thanks a lot. Answer so I can grade.
Tom.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
showmessage(inttostr(DBgri
//Example of the CurrentRowSelected property
procedure TForm1.SelectedClick(Sende
if DBgrid1.SelectedRows.Curre
end;//Example of the Clear Methodprocedure TForm1.ClearClick(Sender: TObject);
begin dbgrid1.SelectedRows.Clear
procedure TForm1.DeleteClick(Sender:
DBgrid1.SelectedRows.Delet
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:
TempBookmark: TBookMark;begin DBGrid1.Datasource.Dataset
with DBgrid1.SelectedRows do if Count > 0 then begin
TempBookmark:= DBGrid1.Datasource.Dataset
for x:= 0 to Count - 1 do begin if IndexOf(Items[x]) > -1 then
begin DBGrid1.Datasource.Dataset
showmessage(DBGrid1.Dataso
end; DBGrid1.Datasource.Dataset
DBGrid1.Datasource.Dataset
DBGrid1.Datasource.Dataset
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(Se
Bookmark1:= DBGrid1.Datasource.Dataset
procedure TForm1.FreeBookmarkClick(S
if assigned(Bookmark1) then begin
DBGrid1.Datasource.Dataset
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(
showmessage(inttostr(z)); end;end;end.