好奇怪的事,请高手指点。在线=,谢谢。 ( 积分: 100 )

  • 主题发起人 主题发起人 kmchen
  • 开始时间 开始时间
K

kmchen

Unregistered / Unconfirmed
GUEST, unregistred user!
我为edit设置鼠标右键点击事件,一直运行正常,突然:在edit上点击鼠标右键不会响应我的事件,而是出现:粘贴,删除。。。。。从右向左的顺序阅读等等。后发现,包括combobox上点击鼠标右键也是一样的,不懂,请各位大大指点我下。兄弟在电脑前含泪等待中。谢谢。
 
没人愿意看看我的问题吗?。。。。。
 
事件没有链接
 
procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbRight then
ShowMessage('ok');
end;
 
~~~~~~~~描述不清楚~~~
 
应该是事件没有连接吧,楼上linchhero的就是那个事件
 
问题补充:
我的一个小程序。为一个edit写了一个鼠标右键事件,程序肯定没问题,因其已经工作了一段时间了。有一天重新编译了程序,重新运行时,发现在edit上右键鼠标时没有响应我写的事件,而是出现了类似你在浏览器右键鼠标时出现的那个菜单档,感觉是edit进入了编辑状态。菜单内容是:撤销,剪切,复制,粘贴,删除,全选,从右向左的阅读顺序,显示unicode控制字符,插入unicode控制字符。我用delphi进10年了,程序上没有问题。谢谢大家。
 
我做了截图,有兴趣的朋友加我Msn,我发给你看下。我的msn是:chenhaibin@msn.com
 
如果不给Edit写右键事件,就会出现你所描述的菜单。
所以我认为还是没有链接右键事件的缘故
 
好,我再检查一下。
 
肯定链接了,我确认。
还有其它想法吗?
你有msn吗?
 
其实问题可以简化为:为什么程序不响应我的右键事件。
 
unit cmain;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, chbedit, PrnDbgeh, Db, ADODB, Mask, ToolEdit, Grids, DBGridEh,
ovcbase, o32igrid, dxGrClms, dxTL, dxDBGrid, dxCntner, AdvEdit;

type
Tmainform=class(TForm)
ADOQuery1:TADOQuery;
DataSource1:TDataSource;
AdvEdit1:TAdvEdit;
AdvEdit2:TAdvEdit;
dxDBGrid1:TdxDBGrid;
ComboBox1:TComboBox;
Label1:TLabel;
Button1:TButton;
ADOQuery2:TADOQuery;
chbedit1:Tchbedit;
Label2:TLabel;
dxDBGrid1Column2:TdxDBGridMaskColumn;
dxDBGrid1Column4:TdxDBGridMaskColumn;
dxDBGrid1price:TdxDBGridMaskColumn;
dxDBGrid1Column6:TdxDBGridMaskColumn;
dxDBGrid1Column8:TdxDBGridMaskColumn;
dxDBGrid1Column9:TdxDBGridDateColumn;
dxDBGrid1Column10:TdxDBGridMaskColumn;
dxDBGrid1Column11:TdxDBGridMaskColumn;
dxDBGrid1Column12:TdxDBGridMaskColumn;
dxDBGrid1Column14:TdxDBGridMaskColumn;
dxDBGrid1Column15:TdxDBGridMaskColumn;
AdvEdit3:TAdvEdit;
AdvEdit4:TAdvEdit;
Button2:TButton;
O32InspectorGrid1:TO32InspectorGrid;
PrintDBGridEh1:TPrintDBGridEh;
Button3:TButton;
DBGridEh1:TDBGridEh;
ADOQuery3:TADOQuery;
DataSource2:TDataSource;
DateEdit1:TDateEdit;
DateEdit2:TDateEdit;
procedure FormCreate(Sender:TObject);
procedure AdvEdit1ValueValidate(Sender:TObject;value:string;
var IsValid:Boolean);
procedure Button1Click(Sender:TObject);
procedure ComboBox1Change(Sender:TObject);
procedure dxDBGrid1DblClick(Sender:TObject);
procedure Button2Click(Sender:TObject);
procedure Button3Click(Sender:TObject);
procedure dxDBGrid1CustomDrawCell(Sender:TObject;ACanvas:TCanvas;
ARect:TRect;ANode:TdxTreeListNode;AColumn:TdxTreeListColumn;
ASelected,AFocused,ANewItemRow:Boolean;var AText:string;
var AColor:TColor;AFont:TFont;var AAlignment:TAlignment;
var ADone:Boolean);
procedure chbedit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
mainform:Tmainform;

implementation

uses cselectone,cdatamodule, cprintsj;

{$R *.DFM}

procedure Tmainform.FormCreate(Sender:TObject);
var
i:integer;
begin
DateEdit1.Date:=Now-30;
DateEdit2.Date:=now;
ComboBox1.Text:=ComboBox1.Items[0];
ComboBox1.ItemIndex:=0;
ComboBox1Change(nil);
ADOQuery1.open;
for i:=0 to 2 do with ADOQuery2 do
begin
close;
sql.text:='select * from price where bottletype='+inttostr(i+1);
open;
O32InspectorGrid1.Items.Value:=fieldbyname('price').asstring;
end;
end;

procedure Tmainform.AdvEdit1ValueValidate(Sender:TObject;value:string;
var IsValid:Boolean);
begin
try
StrToInt(value);
except
ShowMessage('只能输入数值');
AdvEdit1.SetFocus;
AdvEdit1.SelectAll;
isvalid:=false;
end;
end;

procedure Tmainform.Button1Click(Sender:TObject);
var
mm:string;
begin
with ADOQuery2 do
begin
close;
sql.text:='insert bottle (日期,客户名称,pym,bottype,旧瓶入,新瓶出,price,返还金额) values (getdate(),'''+chbedit1.text+''','''+chbedit1.Pym+''','+inttostr(combobox1.tag)+',0'+advedit1.Text+',0'+advedit4.text+',0'+advedit2.Text+',0'+advedit3.Text+')';
execsql;
close;
SQL.Text:='select max(id) id from bottle';
open;
mm:=fieldbyname('id').asstring;
ADOQuery1.Requery;
ADOQuery1.Locate('id',mm, [loCaseInsensitive]);
end;
printsj:=tprintsj.create(Self);
printsj.free;
AdvEdit1.Text:='';
AdvEdit2.Text:='';
AdvEdit3.Text:='';
AdvEdit4.Text:='';
end;

procedure Tmainform.ComboBox1Change(Sender:TObject);
begin
ComboBox1.Tag:=ComboBox1.ItemIndex+1;
with ADOQuery2 do
begin
close;
sql.text:='select * from price where bottletype='+inttostr(ComboBox1.ItemIndex+1);
open;
AdvEdit2.Text:=fieldbyname('price').asstring;
end;
end;

procedure Tmainform.dxDBGrid1DblClick(Sender:TObject);
var
mm:string;
begin
if (ADOQuery1.FieldByName('返还金额').AsFloat<>0)and(ADOQuery1.FieldByName('sign').AsInteger=0) then
if Application.MessageBox('执行这个过程意味着你已经收到了客户的现金'+
#13#10#13#10+'它是不可逆的'+#13#10#13#10+'你确认要执行吗?',
PChar(Caption),MB_YESNO+MB_ICONWARNING)=IDYES then with ADOQuery2 do
begin
mm:=adoquery1.fieldbyname('id').asstring;
close;
sql.text:='update bottle set sign=1 where id='+mm;
execsql;
ADOQuery1.Requery;
ADOQuery1.Locate('id',mm, [loCaseInsensitive]);
printsj:=tprintsj.create(Self);
printsj.free;
end;
end;

procedure Tmainform.Button2Click(Sender:TObject);
var
i:integer;
begin
for i:=0 to 2 do with ADOQuery2 do
begin
close;
sql.text:='update price set price='+O32InspectorGrid1.Items.Value+' where bottletype='+inttostr(i+1);
execsql;
end;
end;

procedure Tmainform.Button3Click(Sender:TObject);
begin
ADOQuery3.Close;
ADOQuery3.SQL.Text:='select 客户名称,case when bottype=1 then ''大瓶'' when bottype=2 then ''中瓶'' else ''小瓶'' end 瓶类型,sum(新瓶出)新瓶出,sum(旭然金额入库)旭然金额入库 from bottle where 日期 between :timer1 and :timer2 ';
ADOQuery3.SQL.Add('group by 客户名称,bottype having sum(旭然金额入库)<>0 order by 客户名称,bottype');
ADOQuery3.Parameters[0].Value:=DateEdit1.Date;
ADOQuery3.Parameters[1].Value:=DateEdit2.Date+1;
ADOQuery3.Open;
PrintDBGridEh1.PageHeader.CenterText.Clear;
PrintDBGridEh1.PageHeader.CenterText.Add('更新瓶旭然金额入库清单');
PrintDBGridEh1.PageHeader.CenterText.Add(DateEdit1.Text+'----'+dateedit2.Text);
PrintDBGridEh1.AfterGridText.Clear;
ADOQuery2.close;
ADOQuery2.sql.text:='select sum(旭然金额入库) dd from bottle where 日期 between :timer1 and :timer2 ';
ADOQuery2.Parameters[0].Value:=DateEdit1.Date;
ADOQuery2.Parameters[1].Value:=DateEdit2.Date+1;
ADOQuery2.Open;
PrintDBGridEh1.AfterGridText.Add('总金额:'+adoquery2.fieldbyname('dd').AsString);
PrintDBGridEh1.AfterGridText.Add('打印日期:'+datetimetostr(Now));
PrintDBGridEh1.Print;
ADOQuery3.Close;
ADOQuery3.sql.text:='select 客户名称,sum(客户支付) 客户支付,sum(旭然支付) 旭然支付 from bottle where sign=1 and 日期 between :timer1 and :timer2 group by 客户名称 having sum(旭然支付)>0';
ADOQuery3.Parameters[0].Value:=DateEdit1.Date;
ADOQuery3.Parameters[1].Value:=DateEdit2.Date+1;
ADOQuery3.Open;
PrintDBGridEh1.PageHeader.CenterText.Clear;
PrintDBGridEh1.PageHeader.CenterText.Add('更新瓶补助清单');
PrintDBGridEh1.PageHeader.CenterText.Add(DateEdit1.Text+'----'+dateedit2.Text);
PrintDBGridEh1.AfterGridText.Clear;
ADOQuery2.close;
ADOQuery2.sql.text:='select sum(旭然支付) dd from bottle where sign=1 and 日期 between :timer1 and :timer2 ';
ADOQuery2.Parameters[0].Value:=DateEdit1.Date;
ADOQuery2.Parameters[1].Value:=DateEdit2.Date+1;
ADOQuery2.Open;
PrintDBGridEh1.AfterGridText.Add('总金额:'+adoquery2.fieldbyname('dd').AsString);
PrintDBGridEh1.AfterGridText.Add('打印日期:'+datetimetostr(Now));
PrintDBGridEh1.Print;
end;

procedure Tmainform.dxDBGrid1CustomDrawCell(Sender:TObject;
ACanvas:TCanvas;ARect:TRect;ANode:TdxTreeListNode;
AColumn:TdxTreeListColumn;ASelected,AFocused,ANewItemRow:Boolean;
var AText:string;var AColor:TColor;AFont:TFont;
var AAlignment:TAlignment;var ADone:Boolean);
begin
try
if StrToInt(AText)<0 then AColor:=clred;
except
end;
end;

procedure Tmainform.chbedit1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Button=mbright then
begin
selectedit:='';
selecteditstr:='';
select1:='客户名称';//结果2
selectstr:='客户名称';
select0:='pym';
selecttitle:='客户名称';
select00:='客户名称';
pymid:='';
selectfrom:='bottle';
selectwhere:='';
selectorder:='';
selectinsert:='';
inipym:='';
selectone:=tselectone.create(self);
try
if selecttrue then selectone.showmodal else if not selectonlyone then exit;
finally
selectone.free;
end;
if not selectcancel then chbedit1.Text:=selectreturn;
end;
end;

end.
 
没有MSN:(
我试了一下,在onMouseDown时加入代码,
TEdit不仅会执行OnMouseDown里的代码,同时还是会弹出默认的右键菜单的

你是这个代码没执行吗?
procedure Tmainform.chbedit1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
 
那就不清楚了,

一、要不在
procedure Tmainform.chbedit1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
里加个测试, 如Caption := 'Test';看看是不是执行了而你没看到效果

二、难道是Tchbedit出错了,能不能换个TEdit试试呢
 
chbedit是我继承edit写的一个控件,用了4、5年了。我试过加showmessage('dsfsfsdf').没有执行。真的不解了。。。。
 
单步跟踪能不能进去就ok了,再不行调用cpu调试窗口就可以发现是什么原因了
 
接受答案了.
 

Similar threads

D
回复
0
查看
839
DelphiTeacher的专栏
D
D
回复
0
查看
845
DelphiTeacher的专栏
D
D
回复
0
查看
679
DelphiTeacher的专栏
D
后退
顶部