Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-12

How to set focus in an Edit in multiple TabSheet?

12 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hi,

I'm trying with ActiveControl, calling "ActiveControl := Edit1" in
OnShow of TabSheet, but it not work. :(

Please se my demo in attached.

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 * =============================================== -------------- next part -------------- A non-text attachment was scrubbed... Name: demo.zip Type: application/zip Size: 2533 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111210/1a3180c6/attachment.zip>

Reply by email

silvioprog
to zeljko

2011/12/10 zeljko :

Show quoted text 15 lines
On Saturday 10 of December 2011 20:54:01 silvioprog wrote: > Hi, > > I'm trying with ActiveControl, calling "ActiveControl := Edit1" in > OnShow of TabSheet, but it not work. :( Edit1.SetFocus doesn't work too ? zeljko

Nope. x(

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 * ===============================================

Reply by email

Bart
to silvioprog

On 12/10/11, silvioprog wrote:

I remeber using SomeContrl.SetFocus in the OnChange of TPageControl (actually I did an override on DoChange) and this works for me (on Windows, not tested yet on other widgetsets).

Here's a snippet of the relevant code.

procedure TEditorPageControl.DoChange;
var
  Ed: TEditor;
begin
  inherited DoChange;
  Ed := GetCurrentEditor;
  InternalEditorStatusChange(Ed,
[scCaretX,scCaretY,scModified,scInsertMode,scFileName]);
  if Assigned(Ed) then
  begin
    try
      Ed.SetFocus;
    except;
      debugln('TEditorPageControl.DoChange: could not set focus to
current editor');
    end;
  end;
end;

Bart

Reply by email

silvioprog
to Bart: I remeber using SomeContrl.SetFocus in the OnChange of TPageControl (actually I did an…

2011/12/11 Bart :

Show quoted text 26 lines
On 12/10/11, silvioprog wrote: I remeber using SomeContrl.SetFocus in the OnChange of TPageControl (actually I did an override on DoChange) and this works for me (on Windows, not tested yet on other widgetsets). Here's a snippet of the relevant code. procedure TEditorPageControl.DoChange; var ?Ed: TEditor; begin ?inherited DoChange; ?Ed := GetCurrentEditor; ?InternalEditorStatusChange(Ed, [scCaretX,scCaretY,scModified,scInsertMode,scFileName]); ?if Assigned(Ed) then ?begin ? ?try ? ? ?Ed.SetFocus; ? ?except; ? ? ?debugln('TEditorPageControl.DoChange: could not set focus to current editor'); ? ?end; ?end; end;

I tried to run this code, but I have not found the function GetCurrentEditor.

This code works with a PageControl over another PageControl?

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 * ===============================================

Reply by email

silvioprog
to Felipe Monteiro de Carvalho: 2011/12/10 silvioprog : Which widgetset? Felipe Monteiro de Carvalho

2011/12/11 Felipe Monteiro de Carvalho :

Show quoted text 5 lines
2011/12/10 silvioprog : > I'm trying with ActiveControl, calling "ActiveControl := Edit1" in > OnShow of TabSheet, but it not work. :( Which widgetset?

Now I tested in GTK2 (Mint), Qt (openSUSE) and Windows (7). Same problem in all.

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 * ===============================================

Reply by email

D. Prameswara
to silvioprog: I'm trying with ActiveControl, calling "ActiveControl := Edit1" in OnShow of TabSheet,…

I have same problem and I try to solve it using Application.QueryAsyncCall and
event OnPageChanged of each pagecontrol.

---

procedure TForm1.TabSheet1Show(Sender: TObject);
begin
  //ActiveControl := Edit1;
end;
procedure TForm1.PageControl1PageChanged(Sender: TObject);
var lPoiter:PtrInt=0;
begin
  if Sender=PageControl1 then
  begin
    if PageControl1.ActivePage=TabSheet1 then
       lPoiter :=PtrInt(Edit1)
    else if PageControl1.ActivePage=TabSheet2 then
    begin
      PageControl1PageChanged(PageControl2);
    end;
  end
  else if Sender=PageControl2 then
  begin
    if PageControl2.ActivePage=TabSheet3 then
       lPoiter :=PtrInt(Edit2);
  end;
  if lPoiter0 then
     Application.QueueAsyncCall(@AsyncSetFocus, lPoiter);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
  PageControl1PageChanged(PageControl1);
end;
procedure TForm1.TabSheet3Show(Sender: TObject);
begin
  //ActiveControl := Edit2;
end;
procedure TForm1.AsyncSetFocus(aPointer: PtrInt);
begin
  if (aPointer0) and TWinControl(aPointer).CanFocus then
     TWinControl(aPointer).SetFocus
end;
procedure TForm1.FormShow(Sender: TObject);
begin
  PageControl1PageChanged(PageControl1);
end;

----

I know it is not best solution. My friend said that it is not safe for using PtrInt.
I re attach your code here
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111212/8d3b22d2/attachment.html> -------------- next part --------------
A non-text attachment was scrubbed...
Name: demo.zip
Type: application/zip
Size: 2959 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111212/8d3b22d2/attachment.zip>

Reply by email

D. Prameswara
to zeljko

Thanks, but can you explain why PtrUInt better than PtrInt.

2011/12/12 zeljko

Show quoted text 28 lines
** On Monday 12 of December 2011 06:35:22 D. Prameswara wrote: > > I know it is not best solution. My friend said that it is not safe for > using PtrInt. Yes, I prefer PtrUInt for tobject pointers. zeljko -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111212/c25f3004/attachment.html>

Reply by email

Bart
to silvioprog: 2011/12/11 Bart : I tried to run this code, but I have not found the function…
silvioprog 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;
This code works with a PageControl over another PageControl?

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

Bart

Reply by email

silvioprog
to Bart

2011/12/12 Bart :

Show quoted text 40 lines
On 12/11/11, silvioprog 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 * ===============================================

Reply by email