project protject1.exe raised exception class
EInvalidopration with message 'cannot focus a disabled or invisible window'.process stopped.use step or run to continue.这是我的一段代码:
Function XJ_DLDFFhgc(CQH,NY:String):TModalResult;
begin
With TFrmXJ_DLDFFH.Create(AppLication) do
begin
try
pCQH := CQH;
pNY := NY;
Caption := '限价_电量电费查询';
With Query1 do
begin
DisableControls;
Close;
SQL.Clear;
SQl.Add('SELECT * FROM DBO.XJ_DFFHB');
SQL.Add('WHERE XJCQH ='''+' '+'''');
SQL.Add('ORDER BY CBXH');
Open;
end;
Query1.EnableControls;
combobox1.ItemIndex :=0;
edit2.Text :=formatdatetime('yyyy"/"mm',date);
Result :=ShowModal;
Screen.Cursor:=CrArrow;
edit1.SetFocus;
finally
Free;
end;
end;
end;
EInvalidopration with message 'cannot focus a disabled or invisible window'.process stopped.use step or run to continue.这是我的一段代码:
Function XJ_DLDFFhgc(CQH,NY:String):TModalResult;
begin
With TFrmXJ_DLDFFH.Create(AppLication) do
begin
try
pCQH := CQH;
pNY := NY;
Caption := '限价_电量电费查询';
With Query1 do
begin
DisableControls;
Close;
SQL.Clear;
SQl.Add('SELECT * FROM DBO.XJ_DFFHB');
SQL.Add('WHERE XJCQH ='''+' '+'''');
SQL.Add('ORDER BY CBXH');
Open;
end;
Query1.EnableControls;
combobox1.ItemIndex :=0;
edit2.Text :=formatdatetime('yyyy"/"mm',date);
Result :=ShowModal;
Screen.Cursor:=CrArrow;
edit1.SetFocus;
finally
Free;
end;
end;
end;
你的 edit1.SetFocus; 放在ShowModal之后,这里窗体已经关闭了,
把edit1.SetFocus;放在 TFrmXJ_DLDFFH 的 OnShow 事件中。
在关闭的窗口中不能SetFocus
因为是模态(ShowModal)窗体,显示后程序等待用户关闭窗体后才继续执行后面的代码。
edit1.setfocus;
except
end;就这样搞定
我到onshow中试,发现成功了!但是我 想搞清楚为什么这样,
如果是在showmodel后面的语句都是在窗体关闭后才执行,那么
Screen.Cursor:=CrArrow;
edit1.SetFocus;
finally
Free;
是不是都是在窗体关闭后才做呢,我一直以为是
finally
Free;
在关闭窗体的时候做呢!看来我又错了!