Recent

Author Topic: OnActivate when the form is docked  (Read 5990 times)

yellowbit

  • New Member
  • *
  • Posts: 22
OnActivate when the form is docked
« on: October 02, 2012, 02:30:33 pm »
After setting Parent of the new form to TPanel (something like MDI), OnActivate event doesn't work on this new form. Does anybody know how to resolve this problem?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: OnActivate when the form is docked
« Reply #1 on: October 02, 2012, 03:42:38 pm »
Unless you do it manually there is no way that this even will fire. As far as I know and I might be wrong mind you, the onactivate event is fired on non parented controls when they  become active. In aprented control the parent form get the activate event.

You to manually call that event from the main form.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

yellowbit

  • New Member
  • *
  • Posts: 22
Re: OnActivate when the form is docked
« Reply #2 on: October 02, 2012, 04:41:22 pm »
I'm trying to implement something similar to MDI interface (because Lazarus doesn't support it). I need to manage these docked windows by an external "control panel" (minimize, maximize, restore, close etc.). It has to know which windows is active/focused. This may be done by using OnClick event, but this method doesn't react when the user clicks the title bar of the window...

Carver413

  • Full Member
  • ***
  • Posts: 119
Re: OnActivate when the form is docked
« Reply #3 on: October 02, 2012, 08:55:30 pm »
I tried some time ago to do something like that. what a nightmare. and it doesn't get and better with just the xlib. I finally gave up and begin working on my own framework. now I can create any kind of layout I want without a problem.
http://www.pascalgamedevelopment.com/showthread.php?13312-Carver-Explorer
 

vrull

  • Full Member
  • ***
  • Posts: 118
Re: OnActivate when the form is docked
« Reply #4 on: October 09, 2012, 09:20:51 am »
I experienced similar behaviour in Delphi. When the form is docked it is no longer a form in some respects. In order to find the active form I usually started from Screen.ActiveControl (or Application.ActiveControl?) and moved up until the parent is TForm, like
Code: [Select]
var aControl : TWinControl;
begin
...
aControl := Screen.ActiveControl; // or Application.ActiveControl (sorry, don't remember)
while Assigned(aControl) and not (aControl is TForm) do aControl := aControl.Parent;
The event to check is likely onDeactivate

yellowbit

  • New Member
  • *
  • Posts: 22
Re: OnActivate when the form is docked
« Reply #5 on: October 10, 2012, 11:34:48 am »
Good idea, but I think there is a problem: if you want to do this action by clicking on the toolbar on the main form, ActiveControl changes to the toolbar button  :-\

vrull

  • Full Member
  • ***
  • Posts: 118
Re: OnActivate when the form is docked
« Reply #6 on: October 11, 2012, 10:44:35 am »
Try this approach:
in every form you want to close "remotely" set onDeactivate event like this
Code: [Select]
Tdesiredform.OnDeactivate(Sender : TObject);
begin
  gHandle := self.Handle; // gHandle is a global variable of type THandle
end;
When you click on your dedicated "Close" button do
Code: [Select]
if gHandle <> 0 then PostMessage(gHandle, WM_CLOSE, 0,0);
gHandle := 0;
The last  piece is a Delphi code, but something very similar must exist in Lazarus as well. Edited: in fact, it does not work, because I could not figure out what message is closing the form. So another approach would be:
Code: [Select]
var formRef : TForm; // global variable available everywhere
...
TsomeForm.Deactivate(Sender : TObject);
begin
  formRef := self; // second reference to someForm;
 // formRef always refers to last active form or nil
end;
....
TMainForm.CloseFormButtonClick(Sender : TObject);
begin
  if Assigned(formRef) then formRef.Close;
  formRef := nil; // to avoid re-use
end;

.....
TsomeForm.FormClose(Sender : TObject);
begin
  if formRef = self then formRef := nil;
  // to avoid reference to already closed form
end;
I think the above code must work in Lazarus.
« Last Edit: October 12, 2012, 10:14:29 am by vrull »

 

TinyPortal © 2005-2018