home *** CD-ROM | disk | FTP | other *** search
- {
- Designer: Craig Ward
- Date: 23/8/95
-
- Function: Brief example of how to instigate copy\insert routines for DBGrids
- *******************************************************************************}
- unit DBGD;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables;
-
- type
- TForm1 = class(TForm)
- Database1: TDatabase;
- Table1: TTable;
- Table1Letter: TStringField;
- DataSource1: TDataSource;
- Table2: TTable;
- Table2Letter: TStringField;
- DataSource2: TDataSource;
- DBGrid1: TDBGrid;
- DBGrid2: TDBGrid;
- Button1: TButton;
- Button2: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- procedure CopyRecs;
- procedure InsertRecs;
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- {copy routine}
- procedure TForm1.CopyRecs;
- var
- i: integer;
- s: string;
- begin
- s := table1MyFieldName.value;
- table2.Findkey([s]);
- table2.edit;
- for i := 0 to Table1.FieldCount -1 do
- table2.Fields[i].Assign(table1.fields[i]);
- table2.post;
- end;
-
- {insert routine}
- procedure TForm1.InsertRecs;
- var
- i: integer;
- s: string;
- begin
- {search for key - in case of key violations}
- s := table1MyFieldName.value;
- if table2.Findkey([s]) then
- begin
- showMessage('Can not insert record due to Key Violation!');
- exit;
- end;
- table2.edit;
- table2.insert;
- for i := 0 to Table1.FieldCount -1 do
- table2.Fields[i].Assign(table1.fields[i]);
- table2.post;
- end;
-
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- CopyRecs;
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- InsertRecs;
- end;
-
- end.
-