Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I "remove" - not delete - a record from TClientDataset ?

1,991 views
Skip to first unread message

Vincent Schmid

unread,
Nov 21, 2001, 9:41:04 AM11/21/01
to
Hello,

Is it possible to remove a record from a ClientDataset, so that we do not
see it anymore in the ClientDataset data, but without deleting it from the
database when we call ApplyUpdates ?
or, saying it another way, to have a dataset as It would be if the record
had never been retrieved
in the first place ?

thanks,

Vincent Schmid
vsc...@polylog.ch


Craig Stuntz (TeamB)

unread,
Nov 21, 2001, 10:21:15 AM11/21/01
to

Vincent Schmid wrote:
>
> Is it possible to remove a record from a ClientDataset, so that we do not
> see it anymore in the ClientDataset data, but without deleting it from the
> database when we call ApplyUpdates ?

Yes. Just use a client-side filter to prevent the record from being
displayed.

HTH,

-Craig

--
Craig Stuntz (TeamB) · Vertex Systems Corp. · Columbus, OH
We're hiring: http://www.vertexsoftware.com/careerops.htm#sd
Delphi/InterBase WebLog: http://delphi.weblogs.com

Guinther de Bitencourt Pauli

unread,
Nov 21, 2001, 12:10:14 PM11/21/01
to
Yeah, is very easy. The sample code below show how I previne the deletes in
my database. I intercept the exclusion in the BeforeUpdateRecord of
DatasetProvider, and change the delete by a update, modifying a field called
FlagDeleted to 1 (true).

procedure TForm1.DataSetProvider1BeforeUpdateRecord(Sender: TObject;
SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;
UpdateKind: TUpdateKind; var Applied: Boolean);
begin
if UpdateKind=ukdelete then
begin
// set a flag in record in database, to sign that the register
// was deleted (but I intercet and just the alter the flag)
SQLConnection1.ExecuteDirect
('Update CustomerTable set FlagDeleted=1 '+
'where CustKey='+DeltaDS.fieldbyname ('CustKey').AsString);
Applied:=true; // don't delete from database when call ApplyUpdates
end;
end;

Then, the Main Select of Query is like "SELECT * FROM CustomerTable where
FlagDeleted<>1". The user never see the old deleted records, but I see
direct in Database, and occasionally restore some records by setting the
flag.


--
Guinther de Bitencourt Pauli - guin...@unifra.br - Santa Maria - RS -
Brazil
Certified Master Delphi Programmer and Delphi 5 - Brainbench
ClubeDelphi Maganize - Author, Oficial Course Borland Midas and App.Corp.


"Vincent Schmid" <vsc...@polylog.ch> escreveu na mensagem
news:3bfbbd49_2@dnews...

Vincent Schmid

unread,
Nov 22, 2001, 1:19:11 AM11/22/01
to
OK,

Thank you all for the suggestions : it is more work than I expected, but I
will try it.

sincerely,
Vincent Schmid


vavan

unread,
Nov 22, 2001, 1:27:43 AM11/22/01
to
On Wed, 21 Nov 2001 15:41:04 +0100, "Vincent Schmid"
<vsc...@polylog.ch> wrote:

>Is it possible to remove a record from a ClientDataset, so that we do not
>see it anymore in the ClientDataset data, but without deleting it from the
>database when we call ApplyUpdates ?
>or, saying it another way, to have a dataset as It would be if the record
>had never been retrieved
>in the first place ?

Take a look at LogChanges property of ClientDataSet...

--
Vladimir Ulchenko aka vavan

Raymond Barlow

unread,
Dec 12, 2001, 12:17:52 AM12/12/01
to
Hi Vincent,

In TDataSetProvider.OnGetData, you can filter out the records before
they even get to the client.

eg:

procedure TdatCallout.dspRosteredResourcesGetData(Sender: TObject;
DataSet: TClientDataSet);
begin
DataSet.First;
while not DataSet.EOF do
begin
if DataSet.FieldByName('Name').AsString = 'Vincent' then
DataSet.Delete
else
DataSet.Next;
end;
end;

Hope this helps,
Cheers,
Raymond Barlow

"Vincent Schmid" <vsc...@polylog.ch> wrote in message news:<3bfbbd49_2@dnews>...

0 new messages