Board index » delphi » Only cancel record in dsInsert state

Only cancel record in dsInsert state


2007-07-04 10:20:24 PM
delphi9
Hello,
I have a TSQLQuery, TClientDataSet construction to FireBird 2.
I have next procedure
procedure From.BeforePost(DataSet: TDataSet);
begin
if SomethingWrong then
Abort;
end;
When 2 lines are correctly added and a 3rd one is in the dsInsert state
and SomethingWrong is the case, Abort is called and the 3rd line is removed.
But the first 2 lines are also gone.
Then I tried
procedure From.BeforePost(DataSet: TDataSet);
begin
if SomethingWrong then
try
Abort;
except
Cancel;
end;
end;
This works but causes exceptions when applying updates (can not find
record), I think this is the deleted 3rd (insert) record
Does anyone have a decent solution for this?
Thanks in advance
Herman
 
 

Re:Only cancel record in dsInsert state

After serious thinking Herman wrote :
Quote
Hello,

I have a TSQLQuery, TClientDataSet construction to FireBird 2.
I have next procedure
procedure From.BeforePost(DataSet: TDataSet);
begin
if SomethingWrong then
Abort;
end;

When 2 lines are correctly added and a 3rd one is in the dsInsert state
and SomethingWrong is the case, Abort is called and the 3rd line is removed.
But the first 2 lines are also gone.

Then I tried
procedure From.BeforePost(DataSet: TDataSet);
begin
if SomethingWrong then
try
Abort;
except
Cancel;
end;
end;

This works but causes exceptions when applying updates (can not find record),
I think this is the deleted 3rd (insert) record

Does anyone have a decent solution for this?
Thanks in advance
Herman
More info is required. What is the relationship between those three
records? What do they represent and how they are linked together?
One observation on your second solution. Why do you use abort which
raises an exception just to catch it in the same method and call
cancel? It seems to me that calling cancel directly with out calling
the abort first will have the same results eg.
procedure From.BeforePost(DataSet: TDataSet);
begin
if SomethingWrong then
Cancel;
end;
regards
Yannis.
 

Re:Only cancel record in dsInsert state

Dear Yannis,
There is no relation between the 3 records, the 1st to are manually
added and the 3rd is in Insertmode after the last one was entered.
Because the user leaves the cursor there in the DBGrid we want to get
rid of this record.
When I call only Cancel it leaves an empty record behind.
Regards
Herman
yannis schreef:
Quote
After serious thinking Herman wrote :
>Hello,
>
>I have a TSQLQuery, TClientDataSet construction to FireBird 2.
>I have next procedure
>procedure From.BeforePost(DataSet: TDataSet);
>begin
>if SomethingWrong then
>Abort;
>end;
>
>When 2 lines are correctly added and a 3rd one is in the dsInsert state
>and SomethingWrong is the case, Abort is called and the 3rd line is
>removed.
>But the first 2 lines are also gone.
>
>Then I tried
>procedure From.BeforePost(DataSet: TDataSet);
>begin
>if SomethingWrong then
>try
>Abort;
>except
>Cancel;
>end;
>end;
>
>This works but causes exceptions when applying updates (can not find
>record), I think this is the deleted 3rd (insert) record
>
>Does anyone have a decent solution for this?
>Thanks in advance
>Herman

More info is required. What is the relationship between those three
records? What do they represent and how they are linked together?

One observation on your second solution. Why do you use abort which
raises an exception just to catch it in the same method and call cancel?
It seems to me that calling cancel directly with out calling the abort
first will have the same results eg.

procedure From.BeforePost(DataSet: TDataSet);
begin
if SomethingWrong then
Cancel;
end;


regards
Yannis.


 

Re:Only cancel record in dsInsert state

Dear Bill,
I did but the same happens.
Is there another Abort than SysUtils.Abort?
Regards
Herman
Bill Todd schreef:
Quote
Change Abort to SysUtils.Abort.

 

Re:Only cancel record in dsInsert state

I assume that you mean that the first two records disappear from the
ClientDataSet, not from the database. I have never seen or heard of
this happening. I cannot think of any way that a record can vanish from
a CDS after the record has been posted.
As I understand it all you have done is post the newly inserted
records. You have not called ApplyUpdates. Is that correct?
--
Bill Todd (TeamB)
 

Re:Only cancel record in dsInsert state

Correct,
Sorry for my late reply
Herman
Bill Todd schreef:
Quote
I assume that you mean that the first two records disappear from the
ClientDataSet, not from the database. I have never seen or heard of
this happening. I cannot think of any way that a record can vanish from
a CDS after the record has been posted.

As I understand it all you have done is post the newly inserted
records. You have not called ApplyUpdates. Is that correct?