[Lazarus] How to set focus in an Edit in multiple TabSheet?

silvioprog silvioprog at gmail.com
Mon Dec 12 15:55:26 CET 2011


2011/12/12 Bart <bartjunk64 at gmail.com>:
> On 12/11/11, silvioprog <silvioprog at gmail.com> wrote:
>> I tried to run this code, but I have not found the function
>> GetCurrentEditor.
>
> This code just finds the active tabsheet, then finds an instance of
> TEditor on it.
> It'rather trivial.
>
> function TEditorPageControl.GetCurrentEditor: TEditor;
> var
>  Pg: TTabSheet;
> begin
>  Result := nil;
>  //ActivePageIndex = -1 when you remove the last (as in no more pages
> available) page
>  //PageCount will still be 1 at this time
>  if (PageCount > 0) and (ActivePageIndex >= 0) then
>  begin
>    Pg := Pages[ActivePageIndex];
>    Result := EditorAtPage(Pg);
>  end;
> end;
>
> And now you want to know the implementation of EditorAtPage()
>
> function TEditorPageControl.EditorAtPage(const APage: TTabSheet): TEditor;
> var
>  cc: Integer;
> begin
>  Result := nil;
>  if not Assigned(APage) then Exit;
>  for cc := 0 to APage.ComponentCount - 1 do
>  begin
>    if APage.Components[cc] is TEditor then
>    begin
>      Result := TEditor(APage.Components[cc]);
>      Exit;
>    end;
>  end;
> end;

Nice code. I'll test it later.

> I never have had that (a PageControl inside anothe PageControl is what
> you mean by that?).

I think the translator was not very clear, but it would be:
http://imagebin.org/188205

Thx.

-- 
Silvio Clécio
===============================================
Blog - <silvioprog.com.br>
Twitter - <twitter.com/silvioprog>
Facebook - <facebook.com/silvioprog>
LazSolutions - <code.google.com/p/lazsolutions>
Lazarus-BR - <groups.google.com.br/group/lazarus-br?hl=pt-BR>
===============================================
   * Conheça nosso canal IRC sobre Lazarus: #lazarus-br *
===============================================




More information about the Lazarus mailing list