Autor Beitrag
Arakis
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 344



BeitragVerfasst: So 15.09.02 12:25 
Hi Leute,
wie kann man in einem DBGrid oder ähnlichem unterbinden, dass zwar editiert(UPDATE), aber nicht gelöscht werden darf(DELETE)? Denn mit STRG-DEL spring mir immer eine Löschabfrage auf den Bildschirm.

Bis dann
user defined image

_________________
Mit dem Computer löst man Probleme, die man ohne ihn nicht hätte.
Entwickler von SpaceTrek: The New Empire - Siehe Hompage!
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: So 15.09.02 13:03 
Hallo,

du kannst dich im BeforeDelete Ereignis des Tabellen-Objektes hängen und den löschvorgang mit einem
ausblenden Quelltext
1:
DataSet.Cancel;					

abbrechen.

Gruß
Klabautermann
Arakis Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 344



BeitragVerfasst: So 15.09.02 13:10 
Hat nicht funktioniert :(
ausblenden Quelltext
1:
2:
3:
4:
procedure TForm_Main.AdressQueryBeforeDelete(DataSet: TDataSet);
begin
  DataSet.Cancel;
end;


Bis dann
user defined image

_________________
Mit dem Computer löst man Probleme, die man ohne ihn nicht hätte.
Entwickler von SpaceTrek: The New Empire - Siehe Hompage!
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: So 15.09.02 13:32 
Hi Akaris,

probiere es mal mit folgendem Code :

ausblenden Quelltext
1:
2:
3:
4:
5:
procedure TKundenformularfenster.DBKundenGesamtKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin                                             
  if (ssctrl in Shift) and (key = VK_DELETE) then key := 0;                    
end;
LCS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1305
Erhaltene Danke: 1

WIN 7, WIN 8
Delphi XE5, Delphi XE, Delphi 2007
BeitragVerfasst: So 15.09.02 14:22 
Oder so:
ausblenden Quelltext
1:
2:
3:
4:
procedure TForm_Main.AdressQueryBeforeDelete(DataSet: TDataSet); 
begin 
  Abort; 
end;


Gruss Lothar

_________________
Der BH ist für die Brust, der Plan ist für'n Ar...
NetSpider
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 123

Windows XP Pro
Delphi 7 Enterprise
BeitragVerfasst: Di 30.01.07 09:33 
Hi Leute,

ist zwar schon lange her - allerdings hatte ich auch eben das Problem mit den DBGrid. Ich habe die Version von bis11 verwendet, da ich glaube, dass LCSs Version zwar funktioniert, allerdings wird jeglicher Delete-Versuch abgebrochen - also auch die evtl. gewollten Loesch-Aktionen.

Find ich nicht so gut, dass die DBGrids keine Option anbieten, bei der man diese Tastenkombinationen disablen kann.

MfG NetSpider

_________________
Wer in die Fußstapfen anderer tritt hinterlässt keine eigenen Spuren!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6393
Erhaltene Danke: 147

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 30.01.07 10:17 
Ich hatte mal ein ähnliches Problem und habe einfach eine Exception ausgelöst.
Zum Beispiel:
ausblenden Delphi-Quelltext
1:
raise EDatabaseError.Create ('Unzulässiger Löschvorgang!');					

Probiere das doch mal im "BeforeDelete". Ich meine, dass Cancel und Abort sich nur auf die Erfassung und das Ändern von Datensätzen bezieht.
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Mi 31.01.07 00:28 
Das sollte funktionieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TfrmBenutzer.DBGrid2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if (ssctrl in Shift) and (key = VK_DELETE) then 
  begin
    (Sender as TDBGrid).DataSource.DataSet.Cancel;  //<<-- WICHTIG!! Löschvorgang wird abgebrochen!!
    key := 0;  
  end;
end;


Ohne die hervorgehobene Zeile bzw Anweisung wird trotzdem der Datensatz gelöscht!!