我覺得是我在edit 動態加顏色造成的! 我的代碼是:例如: var focusEdit :Teditif focusEdit<>nil then focusEdit.Color:=clwindow; focusEdit:=sender as TEdit; focusEdit.color:=clyellow;在運行到 focusEdit.color:=clyellow;這一步的時候報的錯
我写错了var focusEdit :Teditif focusEdit<>nil then focusEdit.Color:=clwindow; focusEdit:=sender as TEdit;if focusEdit is TEdit then focusEdit.color:=clyellow;--------------------最好你把代码完整地贴出来
procedure TFROM1.edit1Enter(Sender: TObject); begin if focusEdit<>nil then focusEdit.Color:=clwindow; focusEdit:=sender as TEdit; focusEdit.color:=clyellow;end;這個是我運行的代碼!
var BName:string; PName:Char;begin BName:=(sender as Tbutton).name; PName:=BName[Length(BName)]; if Pos('point',Bname)>0 then Pname:='.'; if focusEdit<>nil then begin focusEdit.color:=clyellow; PostMessage(focusEdit.Handle,WM_CHAR,Ord(PName),0); end; Beep;也是運行到focusEdit.color:=clyellow; 這邊報的錯!
通过alt+F12,查看一下dfm文件中,edit1Enter事件是不是被多个地方引用?procedure TFROM1.edit1Enter(Sender: TObject);begin if focusEdit<>nil then focusEdit.Color:=clwindow; if sender is TEdit then begin focusEdit:=sender as TEdit; focusEdit.color:=clyellow; end;end;