[Lazarus] focus vs. parent changing

u-boot myabos at t-online.de
Tue Jan 25 01:36:55 CET 2011


I know that the other order works for my simple procedure. I asked 
because i inspected a bug,  that is described in the german forum 
(http://www.lazarusforum.de/viewtopic.php?f=18&t=4599 
<http://www.lazarusforum.de/viewtopic.php?f=18&t=4599>):

following code was tried in Stringgrid1.OnSelectEditor:

procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer;
  var Editor: TWinControl);
begin
  if (aCol=2) and (aRow>0) then
  begin
    Memo1.Visible:=True;
    Editor:=Memo1;
    Memo1.BoundsRect:=StringGrid1.CellRect(2,aRow);
    Editor.SetFocus;       //!!! here is the focus that doesn't work
  end;
end;

//looking up the selecteditor-proceure:

procedure TCustomGrid.SelectEditor;
var
  aEditor: TWinControl;
begin
  aEditor := GetDefaultEditor(Col);
  if EditingAllowed(FCol) and Assigned(OnSelectEditor) then begin
    // in some situations there are only non-selectable cells
    // if goAlwaysShowEditor is on set initially editor to nil,
    // user can modify this value in OnSelectEditor if needed
    if not SelectCell(FCol,FRow) then
      aEditor:=nil;
    OnSelectEditor(Self, fCol, FRow, aEditor);    //!! here the above procedure with the setfocus is called
  end;
  if aEditor<>Editor then
     Editor := aEditor;	    //!! here SetEditor is called that contains changing Parent with impact on focus
end;                      






















Mattias Gaertner schrieb:
>
>  
>
>  
>
> u-boot <myabos at t-online.de> hat am 24. Januar 2011 um 17:49 geschrieben:
>
> > Same question here as in irc nobody answered it a few hours ago.
> >
> >
> > I tried the following lines. It does not work with setfocus before
> > parent changing.
> > My question is, if it should work in this order or if this is correct
> > behaviour.
> >
> >
> > procedure TForm1.Button1Click(Sender: TObject);
> > begin
> >   edit1.SetFocus;
> >   if (Edit1.Parent=Panel2) Then Edit1.Parent:=Panel1 else
> > Edit1.Parent:=Panel2;
> > end;
>
>  
>
> Changing the Parent switches the focus to another control.
>
> So, you should set the focus after changing the parent.
>
>  
>
> Mattias
>
>








> ------------------------------------------------------------------------
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110125/86bc4270/attachment-0003.html>


More information about the Lazarus mailing list