Board index » delphi » How can I prevent users from deleteing records

How can I prevent users from deleteing records

I was wondering if somebody can help me with the following question:

Is there any way to prevent users from deleting records from a Paradox
database? I am using Delphi 4. I want to make sure that the users will
use my application for insert, delete and updates and that the
<ctrl>+<del> option WILL NOT be available to them.

Regards,

Nick Tentomas

 

Re:How can I prevent users from deleteing records


I suggest you write something like :

    if (Key = VK_DELETE) and (ssCtrl in Shift)
    then Key := 0;

in the OnKeyDown event.

Re:How can I prevent users from deleteing records


Quote
On Thu, 07 Oct 1999 08:05:17 -0300, NTentoma <nick.tento...@dal.ca> wrote:
>I was wondering if somebody can help me with the following question:

>Is there any way to prevent users from deleting records from a Paradox
>database? I am using Delphi 4. I want to make sure that the users will
>use my application for insert, delete and updates and that the
><ctrl>+<del> option WILL NOT be available to them.

One way to handle this is to create a handler for the dataset component's
BeforeDelete event. In this event handler, call the silent exception
procedure Abort. This approach traps all the different ways one can attempt
to delete a record: pressing Ctrl-Del in a grid, calling the Delete method,
the delete button on a TDBNavigator, and so on.

  procedure TForm1.Table1BeforeDelete(DataSet: TDataSet);
  begin
    Abort;
  end;

==========================================================================
Steve Koterski                  "Computers are useless. They can only give
Technical Publications          you answers."
Borland                                       -- Pablo Picasso (1881-1973)
http://www.borland.com/techpubs/delphi

Re:How can I prevent users from deleteing records


Thanks Steve,

Is there any way though to allow delets only from my application? For example
can I prevent deletes except if the user presses my <DELETE> button?

Thanks

Nick

Quote
Borland wrote:
> On Thu, 07 Oct 1999 08:05:17 -0300, NTentoma <nick.tento...@dal.ca> wrote:

> >I was wondering if somebody can help me with the following question:

> >Is there any way to prevent users from deleting records from a Paradox
> >database? I am using Delphi 4. I want to make sure that the users will
> >use my application for insert, delete and updates and that the
> ><ctrl>+<del> option WILL NOT be available to them.

> One way to handle this is to create a handler for the dataset component's
> BeforeDelete event. In this event handler, call the silent exception
> procedure Abort. This approach traps all the different ways one can attempt
> to delete a record: pressing Ctrl-Del in a grid, calling the Delete method,
> the delete button on a TDBNavigator, and so on.

>   procedure TForm1.Table1BeforeDelete(DataSet: TDataSet);
>   begin
>     Abort;
>   end;

> ==========================================================================
> Steve Koterski                  "Computers are useless. They can only give
> Technical Publications          you answers."
> Borland                                       -- Pablo Picasso (1881-1973)
> http://www.borland.com/techpubs/delphi

Re:How can I prevent users from deleteing records


Quote
On Fri, 08 Oct 1999 13:57:43 -0300, NTentoma <nick.tento...@dal.ca> wrote:
>Is there any way though to allow delets only from my application?
>For example can I prevent deletes except if the user presses
>my <DELETE> button?

You could have a Boolean variable (globally accessible in the application)
and check that variable in the BeforeDelete event. To do your detele, set
this flag variable to True, otherwise it should be False (preventing
end-user deletes).

  procedure TForm1.Table1BeforeDelete(DataSet: TDataSet);
  begin
    if (DoWeAllowThisDelete) then
      Abort;
    DoWeAllowThisDelete := False;
  end;

==========================================================================
Steve Koterski                  "Computers are useless. They can only give
Technical Publications          you answers."
Borland                                       -- Pablo Picasso (1881-1973)
http://www.borland.com/techpubs/delphi

Re:How can I prevent users from deleteing records


Thanks Steve,

When I complile my program using the "abort" method you suggested I am getting
the following error:

"[Error] Unit1.pas(159): Statement expected, but expression of type 'Integer'
found"

The error is because I am using the BDE unit as well . I am using the
dbisavechanges(table1.handle) after post, but it seems that the BDE and the
"abort" method do not work well together. Is there any way to solve this
problem?

Thanks again,

Nick

Quote
Borland wrote:
> On Fri, 08 Oct 1999 13:57:43 -0300, NTentoma <nick.tento...@dal.ca> wrote:

> >Is there any way though to allow delets only from my application?
> >For example can I prevent deletes except if the user presses
> >my <DELETE> button?

> You could have a Boolean variable (globally accessible in the application)
> and check that variable in the BeforeDelete event. To do your detele, set
> this flag variable to True, otherwise it should be False (preventing
> end-user deletes).

>   procedure TForm1.Table1BeforeDelete(DataSet: TDataSet);
>   begin
>     if (DoWeAllowThisDelete) then
>       Abort;
>     DoWeAllowThisDelete := False;
>   end;

> ==========================================================================
> Steve Koterski                  "Computers are useless. They can only give
> Technical Publications          you answers."
> Borland                                       -- Pablo Picasso (1881-1973)
> http://www.borland.com/techpubs/delphi

Re:How can I prevent users from deleteing records


Write it:

"SysUtils.Abort"

Gert

Quote
> When I complile my program using the "abort" method you suggested I am
getting
> the following error:

Re:How can I prevent users from deleteing records


Quote
>When I complile my program using the "abort" method you suggested I am
getting
>the following error:

>"[Error] Unit1.pas(159): Statement expected, but expression of type
'Integer'
>found"

You can use SysUtils.Abort or declare BDE unit before SysUtils in the uses
interface;

Anderson Franco

Other Threads