The issue you're encountering is due to the fact that the TStringEditLink is being destroyed before it has finished processing the key press event. This happens because the FEdit.Free call in the TStringEditLink.Destroy method is causing the control to be destroyed immediately, even if the key press event is still being processed.
To fix this issue, you can modify the TStringEditLink.Destroy method to only free the FEdit control if it is still assigned. This way, the control will only be destroyed after the key press event has been fully processed. Here's the modified code:
destructor TStringEditLink.Destroy;
begin
if Assigned(FEdit) then
FEdit.Free;
inherited;
end;
Additionally, you can add a check in the EditKeyDown method to ensure that the FEdit control is still assigned before processing the key press event. This will help prevent any potential access violations if the control has already been destroyed:
procedure TStringEditLink.EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Assigned(FEdit) then
begin
case Key of
VK_ESCAPE:
begin
FTree.CancelEditNode;
Key := 0;
FTree.setfocus;
end;
VK_RETURN:
begin
PostMessage(FTree.Handle, WM_KEYDOWN, VK_DOWN, 0);
Key := 0;
FTree.EndEditNode;
FTree.setfocus;
end;
end; //case
end;
end;
With these modifications, the access violation error should be resolved, and the editor should work as expected.
В контексте данного фрагмента рассматривается проблема доступа к уже удаленному элементу интерфейса в процессе обработки нажатия клавиши в редакторе строк. Для устранения этой проблемы предлагается修改 методы уничтожения и обработки нажати
Комментарии и вопросы
Получайте свежие новости и обновления по Object Pascal, Delphi и Lazarus прямо в свой смартфон. Подпишитесь на наш Telegram-канал delphi_kansoftware и будьте в курсе последних тенденций в разработке под Linux, Windows, Android и iOS
Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.