求教一个拦截事件的方法
求教一个拦截事件的方法
有个窗体向一个TABLE中添加记录,添加删除的按钮用用了映射插入记录的功能,DELPHI7
所以不用写一个代码也能插入删除,编辑记录,但我想让再删除记录时候提示一个MESSAGE
问是否删除,如果不删除就不进行删除记录操作,但我是映射的插入记录操作.这时候怎么
做才能实现上面的功能?
问题点数:100、回复次数:7Top
1 楼sea_way(狒狒)回复于 2003-06-01 15:42:02 得分 0
知道的请赐教.Top
2 楼microjuz(天才弟弟……》说好了和xgto看流星雨)回复于 2003-06-01 15:57:40 得分 10
你用的dbgrid吗
你说的映射是不是
DBNavigator1.BtnClick(nbFirst);这种样子
那你在这条语句前面插入一个messagedlg不就可以了吗Top
3 楼feng93017(Edge)回复于 2003-06-01 16:32:00 得分 50
你的想法很好!
但是一般来说,我见过的软件,绝大多数都是自己在Button的Click事件里面写代码。
因为这样可以灵活的处理很多实际情况。而且,这些组合按钮连标题都没有。用户使用不是很直观。
更不要说是漂亮的界面了。
但是出于交流技术的角度,我的建议是自己写一个控件,从DBNavigator继承下来。下面是我的部分代码以供参考。
==================================================================
.....
const
InsertRecordQuestion = '确实要添加么?';
EditRecordQuestion = '确实要修改么?';
......
public
procedure BtnClick(Index: TNavigateBtn); override;
......
procedure TDBNavigator.BtnClick(Index: TNavigateBtn);
begin
case Index of
nbInsert:
if (MessageDlg(InsertRecordQuestion, mtConfirmation,
mbOKCancel, 0) = idCancel) then exit;
nbEdit: Edit;
if (MessageDlg(EditRecordQuestion, mtConfirmation,
mbOKCancel, 0) = idCancel) then exit;
//至于Delete方法,该控建议经有这一项属性,不必多此一举。
end;
inherited; //这一句很重要,否则将不能执行父类的动作。
end;Top
4 楼feng93017(Edge)回复于 2003-06-01 16:39:00 得分 40
有个地方写错了。
nbEdit: Edit; //这里的 ( :Edit;)是多余的。应该去掉。
if (MessageDlg(EditRecordQuestion, mtConfirmation,
mbOKCancel, 0) = idCancel) then exit;
建议参考TDBNavigator的源代码。你甚至可以修改它源代码。这样,你就不用另外写一个控见了。因为你的要求很简单,只是要一个提示框。你可以参考它的下面这个事件。其实,我也是参考这个事件才给除了上面的代码。
procedure TDBNavigator.BtnClick(Index: TNavigateBtn);
begin
if (DataSource <> nil) and (DataSource.State <> dsInactive) then
begin
if not (csDesigning in ComponentState) and Assigned(FBeforeAction) then
FBeforeAction(Self, Index);
with DataSource.DataSet do
begin
case Index of
nbPrior: Prior;
nbNext: Next;
nbFirst: First;
nbLast: Last;
nbInsert: Insert;
nbEdit: Edit;
nbCancel: Cancel;
nbPost: Post;
nbRefresh: Refresh;
nbDelete: //下面的代码可以用同样的方式写在它的Insert, 和Edit事件里面。
if not FConfirmDelete or
(MessageDlg(SDeleteRecordQuestion, mtConfirmation,
mbOKCancel, 0) <> idCancel) then Delete;
end;
end;
end;
if not (csDesigning in ComponentState) and Assigned(FOnNavClick) then
FOnNavClick(Self, Index);
end;
Top
5 楼yb3721(yb)回复于 2003-06-01 16:59:17 得分 0
to feng93017(Edge) :
问个简单问题:
with...do 是什么意思 有什么用 我前年学过c++ builder 现在转过来学delphi,工作需要Top
6 楼feng93017(Edge)回复于 2003-06-01 18:03:19 得分 0
A with statement is a shorthand for referencing the fields of a record or the fields, properties, and methods of an object. The syntax of a with statement is
with obj do statement
or
with obj1, ..., objn do statement
where obj is a variable reference denoting an object or record, and statement is any simple or structured statement. Within statement, you can refer to fields, properties, and methods of obj using their identifiers alone梬ithout qualifiers.
For example, given the declarations
type TDate = record
Day: Integer;
Month: Integer;
Year: Integer;
end;
var OrderDate: TDate;
you could write the following with statement.
with OrderDate do
if Month = 12 then
begin
Month := 1;
Year := Year + 1;
end
else
Month := Month + 1;
This is equivalent to
if OrderDate.Month = 12 then
begin
OrderDate.Month := 1;
OrderDate.Year := OrderDate.Year + 1;
end
else
OrderDate.Month := OrderDate.Month + 1;
If the interpretation of obj involves indexing arrays or dereferencing pointers, these actions are performed once, before statement is executed. This makes with statements efficient as well as concise. It also means that assignments to a variable within statement cannot affect the interpretation of obj during the current execution of the with statement.
Each variable reference or method name in a with statement is interpreted, if possible, as a member of the specified object or record. If there is another variable or method of the same name that you want to access from the with statement, you need to prepend it with a qualifier, as in the following example.
with OrderDate do
begin
Year := Unit1.Year
...
end;
When multiple objects or records appear after with, the entire statement is treated like a series of nested with statements. Thus
with obj1, obj2, ..., objn do statement
is equivalent to
with obj1 do
with obj2 do
...
with objn do
statement
In this case, each variable reference or method name in statement is interpreted, if possible, as a member of objn; otherwise it is interpreted, if possible, as a member of objn?; and so forth. The same rule applies to interpreting the objs themselves, so that, for instance, if objn is a member of both obj1 and obj2, it is interpreted as obj2.objn.Top
7 楼microjuz(天才弟弟……》说好了和xgto看流星雨)回复于 2003-06-04 16:04:35 得分 0
我也要试着自己写组件,呵呵
我不太喜欢用with..do..读代码的时候感觉很不爽
with..do..的用法
原来的代码
component1.function1;
component1.property1 := ^^^^;
component1.property2 :=^^^^^;
用with..do..
with component1 do
begin
function1;
property1 := ^^^^;
property2 :=^^^^^;
end;
明白了吗?
Top




