[Lazarus] How to set focus in an Edit in multiple TabSheet?
D. Prameswara
meshwara at gmail.com
Mon Dec 12 06:35:22 CET 2011
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 lPoiter<>0 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 (aPointer<>0) 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-ide.org/pipermail/lazarus/attachments/20111212/8d3b22d2/attachment-0003.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-ide.org/pipermail/lazarus/attachments/20111212/8d3b22d2/attachment-0003.zip>
More information about the Lazarus
mailing list