1 unit untBaseClass;
2
3 interface
4
5 uses
6 Windows,Messages,SysUtils,Variants,Classes,DB,ADODB;
7
8 type
9 TBaseClass = class
10 private
11 public
12 constructor create;
13 destructor Destroy;override;
14
15 procedure AddData;
16 procedure CancelData;
17 procedure SaveData;
18 procedure DeleteData;
19 procedure ModifyData;
20
21 end;
22
23 implementation
24
25 uses untDM, untGlobal, untMain, untBase;
26
27 constructor TBaseClass.create;
28 begin
29
30 end;
31
32 destructor TBaseClass.Destroy;
33 begin
34 inherited;
35 end;
36
37 procedure TBaseClass.AddData;
38 begin
39 With frmDM do
40 if Assigned(dsMaster.DataSet) then
41 if not(dsMaster.State in [dsEdit,dsInsert]) then
42 begin
43 try
44 (dsMaster.DataSet as TADOQuery).Append;
45 Except
46 on E:exception do
47 MsgBox('增加错误!'+#13+'出错数类名:'+E.ClassName+#13+'出错信息:'+E.Message,0);
48 end;
49 end;
50
51 end;
52
53 procedure TBaseClass.CancelData;
54 begin
55 MsgBox('取消操作',0)
56 end;
57
58 procedure TBaseClass.DeleteData;
59 begin
60
61 end;
62
63 procedure TBaseClass.SaveData;
64 begin
65 With frmDM do
66 if Assigned(dsMaster.DataSet) then
67 if dsMaster.State in [dsEdit,dsInsert] then
68 begin
69 try
70 conDB.BeginTrans;
71 (dsMaster.DataSet as TADOQuery).Post;
72 (dsMaster.DataSet as TADOQuery).UpdateBatch;
73 conDB.CommitTrans;
74 Except
75 conDB.RollbackTrans;
76 Raise exception.Create('增加错误!'
77 end;
78 end;
79 end;
80 procedure TBaseClass.ModifyData;
81 begin
82 MsgBox('修改数据操作',0)
83 end;
84
85 end.
86
87 此时将基窗体的事件关联起来,基窗体的主要功能代码如下:
88 procedure TfrmBase.FormCreate(Sender: TObject);
89 begin
90 objBaseClass:=TBaseClass.create;
91 RelationMainFormEvent;
92 end;
93
94 procedure TfrmBase.FormClose(Sender: TObject; var Action: TCloseAction);
95 begin
96 Action:=caFree;
97 Self:=nil;
98 end;
99
100 procedure TfrmBase.RelationMainFormEvent;
101 begin
102 frmMain.actAdd.OnExecute:=actAdd.OnExecute;
103 frmMain.actAdd.Enabled:=True;
104 frmMain.actModify.OnExecute:=actModify.OnExecute;
105 frmMain.actModify.Enabled:=True;
106 frmMain.actSave.OnExecute:=actSave.OnExecute;
107 frmMain.actSave.Enabled:=true;
108 end;
109
110 procedure TfrmBase.actAddExecute(Sender: TObject);
111 begin
112 objBaseClass.AddData;
113 end;
114
115 procedure TfrmBase.actDeleteExecute(Sender: TObject);
116 begin
117 objBaseClass.DeleteData;
118 end;
119
120 procedure TfrmBase.actSaveExecute(Sender: TObject);
121 begin
122 objBaseClass.SaveData;
123 end;
124
125 procedure TfrmBase.actCancelExecute(Sender: TObject);
126 begin
127 objBaseClass.CancelData;
128 end;
129
130 procedure TfrmBase.actModifyExecute(Sender: TObject);
131 begin
132 objBaseClass.ModifyData;
133 end;
请发表评论