home *** CD-ROM | disk | FTP | other *** search
- { Demos the use of separate queries to do insertions and deletions. This
- demo is "correct" but inefficient; it re-executes the query after insertions
- and deletions. }
- unit Main;
-
- interface
-
- uses WinTypes, WinProcs, SysUtils, Classes, Graphics, Forms, Dialogs, Controls,
- DB, DBGrids, StdCtrls, DBTables, Grids, ExtCtrls;
-
- type
- TMainForm = class(TForm)
- GridQuery: TQuery;
- DataSource1: TDataSource;
- Grid: TDBGrid;
- DeleteQuery: TQuery;
- Panel1: TPanel;
- Insert: TButton;
- Delete: TButton;
- procedure InsertClick(Sender: TObject);
- procedure DeleteClick(Sender: TObject);
- end;
-
- var
- MainForm: TMainForm;
-
- implementation
-
- uses InsForm;
-
- {$R *.DFM}
-
- procedure TMainForm.InsertClick(Sender: TObject);
- begin
- InsertForm.Clear;
- if InsertForm.ShowModal = mrOK then
- begin
- GridQuery.Close; { re-execute query to pick up insert }
- GridQuery.Open;
- end;
- end;
-
- procedure TMainForm.DeleteClick(Sender: TObject);
- var
- Key: string;
- begin
- Key := Grid.Fields[0].AsString;
- if MessageDlg(Format('Delete "%S" from the Country table?', [Key]),
- mtConfirmation, mbOKCancel, 0) = mrOK then
- begin
- DeleteQuery.Prepare;
- DeleteQuery.Params[0].AsString := Key;
- DeleteQuery.ExecSQL;
- GridQuery.Close; { re-execute query to eliminate deletion }
- GridQuery.Open;
- end;
- end;
-
- end.
-
-