大家有没有出现个这样的问题?(200分)

  • 主题发起人 主题发起人 modernman
  • 开始时间 开始时间
M

modernman

Unregistered / Unconfirmed
GUEST, unregistred user!
一个窗口中,按OK键按钮没问题,但是按回车键就出现access violation的内存错,
但他们执行的流程是一样的。
 
不会吧?[:(]
是否有KeyPress等事件?
 
断点调试
 
贴出代码看看
 
你的OK出发了什么事件?是不是访问了不存在的东西,或者没有建立的东西,或者已经Free掉的东西?
 
看看你的窗口都触发了那些事件,检查你的窗体设计和事件设计完全可以解决。
 
帖代码看看
 
哎,别提了我装了2000之后,经常出现XXXXX内存只读然后就中断进程了,
谢程序的时候也有时就不执行某个事件了,原因不明。调试?呵呵呵无效
 
unit ChangePswUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Db, DBClient, ExtCtrls;
type
TChangePswFrm = class(TForm)
GroupBox1: TGroupBox;
lblUserName: TLabel;
edtPsw1: TEdit;
edtPsw2: TEdit;
lblPsw: TLabel;
bbtnOk: TBitBtn;
bbtnCancel: TBitBtn;
lblCurrPsw: TLabel;
edtCurrPsw: TEdit;
Bevel1: TBevel;
cdsOperator: TClientDataSet;
procedure bbtnOkClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
function CheckCurrPsw: boolean;
public
{ Public declarations }
end;

type TDesStr = array[0..16] of char;
function StrEndes(str: TDesStr;strout: TDesStr):integer ;stdcall;
external 'desdll.dll';

var
ChangePswFrm: TChangePswFrm;
implementation
uses PublicUnit, dmCustUnit;
{$R *.DFM}
var
count:integer;
//user can input error 3 times
procedure TChangePswFrm.bbtnOkClick(Sender: TObject);
var
InitPsw,TmpDes:TDesStr;
i,DesLen: integer;
ok: boolean;
bytePsw:array of byte;
DesPsw:variant;
//StrEndes: TStrEndes;
begin
if Trim(edtCurrPsw.Text)='' then
begin
Application.MessageBox('Current password is null,Please input it!','Warning',MB_OK+MB_ICONWARNING);
edtCurrPsw.SetFocus;
ModalResult := mrNone //this form can not be closed
end
else
if Trim(edtPsw1.Text)='' then
begin
Application.MessageBox('New password is null,Please input the new password!','Warning',MB_OK+MB_ICONWARNING);
edtPsw1.SetFocus;
ModalResult := mrNone //this form can not be closed
end
else
if Length(Trim(edtPsw1.Text)) < 6 then
begin
Application.MessageBox('Password cannot less then
6 character,Please re_input the new password!','Warning',MB_OK+MB_ICONWARNING);
edtPsw1.SetFocus;
ModalResult := mrNone //this form can not be closed
end
else
if Trim(edtPsw2.Text)='' then
begin
Application.MessageBox('New password is null,Please input the new password again!','Warning',MB_OK+MB_ICONWARNING);
edtPsw2.SetFocus;
ModalResult := mrNone //this form can not be closed
end
else
if Trim(edtPsw1.Text) <> Trim(edtPsw2.Text) then
begin
Application.MessageBox('The second password not match the first password, Please re-input it!','Warning',MB_OK+MB_ICONWARNING);
edtPsw2.SetFocus;
ModalResult := mrNone //this form can not be closed
end
else
if count=4 then
begin
Application.MessageBox('Sorry! You cannot change your password, you have inputed 3 times wrong password!','Warning',MB_OK+MB_ICONWARNING);
ModalResult := mrOK
end
else
if not CheckCurrPsw then
ModalResult := mrNone //this form can not be closed
else
begin
ok := False;
setLength(bytePsw,16);
//DesEn the customer password
StrCopy(InitPsw,Pchar(edtPsw1.Text));
DesLen := StrEndes(InitPsw, TmpDes);
for i := 0 to DesLen - 1do
bytePsw := Byte(TmpDes);
DesPsw:=bytePsw;
// dmCustInfo.dcomConn.AppServer.UpdatePsw(dbeOperatorID.Text,DesPsw);
if not cdsOperator.Active then
cdsOperator.Active := True;

if not cdsOperator.Locate('OPERATOR_ID', OperatorID, []) then
Application.MessageBox('Try to save the change to database failed, please change it later!','Warning',MB_OK+MB_ICONWARNING)
else
begin
try
dmCustInfo.dcomConn.AppServer.UpdatePsw(OperatorID,DesPsw);
ok := True
except
Application.MessageBox('Try to save the change to database failed, please change it later!','Warning',MB_OK+MB_ICONWARNING);
cdsOperator.RevertRecord;
ok := False
end
end;

if ok then

cdsOperator.Active := False
end
end;

procedure TChangePswFrm.FormCreate(Sender: TObject);
begin
count := 1;
end;

function TChangePswFrm.CheckCurrPsw: boolean;
var
TmpPsw, InitPsw:TDesStr;
DesLen: integer;
begin
//DesEn the customer password
StrCopy(InitPsw,Pchar(edtCurrPsw.Text));
DesLen := StrEndes(InitPsw, TmpPsw);
TmpPsw[DesLen] := #0;
if StrComp(PChar(string(UserPsw)),PChar(string(TmpPsw)))<>0 then
begin
Application.MessageBox('Invalid Password, input it again!','Warning',MB_OK+MB_ICONWARNING);
count := count + 1;
edtCurrPsw.SetFocus;
Result := False;
end
else
Result := True
end;

end.
 
问题可能出在 ModalResult 上.
 
后退
顶部