Hi,
I'm trying with ActiveControl, calling "ActiveControl := Edit1" in
OnShow of TabSheet, but it not work. :(Please se my demo in attached.
Thx.

Mailing lists / lazarus / 2011-12
12 messages · 5 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi,
I'm trying with ActiveControl, calling "ActiveControl := Edit1" in
OnShow of TabSheet, but it not work. :(Please se my demo in attached.
Thx.
silvioprog wroteHi, I'm trying with ActiveControl, calling "ActiveControl := Edit1" in OnShow of TabSheet, but it not work. :(
Edit1.SetFocus doesn't work too ?
zeljko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111210/00f2ce49/attachment.html>
2011/12/10 zeljko :
Nope. x(
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
I'm trying with ActiveControl, calling "ActiveControl := Edit1" in OnShow of TabSheet,…
2011/12/10 silvioprog :
I'm trying with ActiveControl, calling "ActiveControl := Edit1" in OnShow of TabSheet, but it not work. :(
Which widgetset?
I remeber using SomeContrl.SetFocus in the OnChange of TPageControl (actually I did an…
2011/12/11 Bart :
I tried to run this code, but I have not found the function GetCurrentEditor.
This code works with a PageControl over another PageControl?
2011/12/10 silvioprog : Which widgetset? Felipe Monteiro de Carvalho
2011/12/11 Felipe Monteiro de Carvalho :
Now I tested in GTK2 (Mint), Qt (openSUSE) and Windows (7). Same problem in all.
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>
D. Prameswara wroteI 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111212/a2183fac/attachment-0001.html>
Thanks, but can you explain why PtrUInt better than PtrInt.
2011/12/12 zeljko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20111212/c25f3004/attachment.html>
2011/12/11 Bart : I tried to run this code, but I have not found the function…
silvioprog wroteI 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
2011/12/12 Bart :
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.