CM_EXIT 메시지를받을 때 DataLink.UpdateRecord가 호출되는 DB 구성 요소가 있습니다. 이 메시지는 포커스가 사라지면 전송됩니다. 포스트 버튼을 클릭하면 포커스가 사라지지 않고 값이 데이터 소스에 기록되지 않습니다. 다른 요소로 전환하지 않고 포커스를 잃는 구성 요소의 효과에 어떻게 도달 할 수 있습니까?현재 포커스가있는 구성 요소에서 포커스를 제거하는 방법은 무엇입니까?
5
A
답변
7
당신은 사용할 수 있습니다
procedure TCustomForm.DefocusControl(Control: TWinControl; Removing: Boolean);
3
TCustomForm.FocusControl
을 살펴보십시오. 포커스를 다른 것으로 전환하지 않고 포커스를 잃게 만들 수는 없지만 전환 한 다음 즉시 다시 전환 할 수 있습니다.
+0
그리고 어떻게 FocusControl로 할 수 있습니까? 활성 제어에서 호출하면 이벤트가 트리거되지 않습니다. – LukLed
7
우리는 이러한 목표를 달성 Self.ActiveControl 설정하여 : = 전무합니다. 이로 인해 모든 이탈 이벤트가 발생합니다. 우리의 경우에는 저장이 끝난 후 다시 컨트롤에 다시 집중하려고했습니다. 그것은 우리가 초점을 받아 들일 수있는 좋은 통제력을 갖출 수 있도록 몇 가지 추가 검사가 필요했습니다.
procedure TSaleEditor.SaveCurrentState();
var
SavedActiveControl: TWinControl;
AlternateSavedControl: TWinControl;
begin
// Force the current control to exit and save any state.
if Self.ActiveControl <> nil then
begin
SavedActiveControl := Self.ActiveControl;
// We may have an inplace grid editor as the current control. In that case we
// will not be able to reset it as the active control. This will cause the
// Scroll box to scroll to the active control, which will be the lowest tab order
// control. Our "real" controls have names, where the dynamic inplace editor do not
// find an Alternate control to set the focus by walking up the parent list until we
// find a named control.
AlternateSavedControl := SavedActiveControl;
while (AlternateSavedControl.Name = '') and (AlternateSavedControl.Parent <> nil) do
begin
AlternateSavedControl := AlternateSavedControl.Parent;
end;
Self.ActiveControl := nil;
// If the control is a radio button then do not re-set focus
// because if you are un-selecting the radio button this will automatically
// re-select it again
if (SavedActiveControl.CanFocus = true) and
((SavedActiveControl is TcxRadioButton) = false) then
begin
Self.ActiveControl := SavedActiveControl;
end
else if (AlternateSavedControl.CanFocus = true) and
((AlternateSavedControl is TcxRadioButton) = false) then
begin
Self.ActiveControl := AlternateSavedControl;
end;
end;
end;
2
Windows 단위에는 SetFocus 기능이 있습니다. 이것을 시도하십시오 :
Windows.SetFocus(0);
이 절차를보고 사용해 보았는데 작동하지 않았습니다. 이제 다시 한 번 해보았습니다. 잠에 갈 시간이다. – LukLed
발생하면 Self.ActiveControl : = nil을 설정하면 작업이 너무 직관적이다. 분명히 나를 위해하지 않는다. ... – LukLed
@ LukLed : 큰 팁, 고마워! – Sharken