I am using the FNC treeview as a parameter viewer and editor. This works great for most cases, but using the TAdvFileNameEdit produces a "Control 'TAdvFileNameEdit' has no parent window" error when handling the keyUp event. This error occurs even though i assign the tree as parent in the "AfterOpenInPlaceEditor" event.
How should i assign the parent window, to avoid this error?
constructor TTree.Create(AOwner: TComponent);
begin
inherited;
Tree.ColumnsAppearance.StretchColumn:=1;
Tree.NodesAppearance.Font.Color:=clBlack;
Tree.NodesAppearance.Stroke.Create();
Tree.Columns[1].CustomEditor:=true;
end;
procedure TTree.TreeGetInplaceEditor(Sender: TObject;
ANode: TTMSFNCTreeViewVirtualNode; AColumn: Integer;
var AInplaceEditorClass: TTMSFNCTreeViewInplaceEditorClass);
begin
case lbl of
Path: AInplaceEditorClass:=TAdvFileNameEdit;
...
end
end;
procedure TTree.TreeAfterOpenInplaceEditor(Sender: TObject;
ANode: TTMSFNCTreeViewVirtualNode; AColumn: Integer;
AInplaceEditor: TTMSFNCTreeViewInplaceEditor; AInplaceEditorRect: TRectF);
begin
if AInplaceEditor is TAdvFileNameEdit then begin
TAdvFileNameEdit(AInplaceEditor).Parent:=tree;
TAdvFileNameEdit(AInplaceEditor).OnKeyup:= editorKeyUp;
TAdvFileNameEdit(AInplaceEditor).OnKeyPress:=editorKeyPress;
end;
end;
procedure TfraSprintDetailTree.editorKeyUp(Sender: TObject; var Key: word;
shift: TShiftState);
begin
case Key of
VK_RETURN: Tree.StopEditing;
VK_ESCAPE: Tree.CancelEditing;
else exit;
end;
key:=0;
end;
The error ‘Control has no parent window’ is raised during the KeyUp event.
As far as i can see, this implementation should resemble the one in your example.
In the editorkeyup implementation, calling StopEditing will effectively remove / destroy the inplace editor. The issue is that the code keeps running and still tries executing code inside the OnKeyUp implementation in TAdvFileNameEdit. To avoid this, please call Abort, after setting Key := 0;