Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Vojtěch Čihák

Thanks again, you're right. Now it all works, even with recursive searching in 
parents.
..__

Od: Ondrej Pokorny 
Komu: Lazarus mailing list 
Datum: 22.05.2016 17:47
Předmět: Re: [Lazarus] Detect that component selected in OI.


On 22.05.2016 17:37, Vojtěch Čihák wrote:Separating Component Editors is quiet easy but 
how can I separate the Hook (SelectionHook method) when I need "self"?
 
Thanks, V.

For what do you need self? You have the list, so do

for I := 0 to ASelection.Count-1 do
  if ASelection[I] is TMyTabSheet then
    // do your job here

Ondrej


--

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

On 22.05.2016 17:37, Vojtěch Čihák wrote:


Separating Component Editors is quiet easy but how can I separate the 
Hook (SelectionHook method) when I need "self"?


Thanks, V.



For what do you need self? You have the list, so do

for I := 0 to ASelection.Count-1 do
  if ASelection[I] is TMyTabSheet then
// do your job here

Ondrej
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Vojtěch Čihák

Separating Component Editors is quiet easy but how can I separate the Hook (SelectionHook 
method) when I need "self"?
 
Thanks, V.
 
__

Od: Ondrej Pokorny 
Komu: Lazarus mailing list 
Datum: 22.05.2016 16:10
Předmět: Re: [Lazarus] Detect that component selected in OI.


On 22.05.2016 15:45, Vojtěch Čihák wrote:With a small correction: it must be 
hooked only in design time.
 
constructor TMyTabSheet.Create(TheOwner: TComponent);
begin
  ...
  if csDesigning in ComponentState then
    GlobalDesignHook.AddHandlerSetSelection(@HookSelection);
end;

You should separate the hook completely from your run-time code. Use the hook 
(and include IDEIntf) only in your design-time package and unit.

Ondrej


--

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Vojtěch Čihák

OK, thanks.
__

Od: Ondrej Pokorny 
Komu: Lazarus mailing list 
Datum: 22.05.2016 16:21
Předmět: Re: [Lazarus] Detect that component selected in OI.


On 22.05.2016 14:13, Vojtěch Čihák wrote:procedure 
TMyTabSheet.HookSelection(const ASelection: TPersistentSelectionList);
begin
  if assigned(FMyPageControl) and (ASelection.IndexOf(self)>=0) then
    FMyPageControl.TabIndex:= FMyPageControl.Pages.IndexOf(self);
end;   
+ You also should check for selecting child controls (e.g. the user selects a 
button in the page). See TObjectInspectorDlg.DefSelectionVisibleInDesigner from 
r52344.
Ondrej


--

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

On 22.05.2016 14:13, Vojtěch Čihák wrote:


procedure TMyTabSheet.HookSelection(const ASelection: 
TPersistentSelectionList);


begin

  if assigned(FMyPageControl) and (ASelection.IndexOf(self)>=0) then

  FMyPageControl.TabIndex:= FMyPageControl.Pages.IndexOf(self);

end;

+ You also should check for selecting child controls (e.g. the user 
selects a button in the page). See 
TObjectInspectorDlg.DefSelectionVisibleInDesigner from r52344.


Ondrej

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

On 22.05.2016 15:45, Vojtěch Čihák wrote:


With a small correction: it must be hooked only in design time.

constructor TMyTabSheet.Create(TheOwner: TComponent);

begin

  ...

  if csDesigning in ComponentState then

GlobalDesignHook.AddHandlerSetSelection(@HookSelection);

end;



You should separate the hook completely from your run-time code. Use the 
hook (and include IDEIntf) only in your design-time package and unit.


Ondrej
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Vojtěch Čihák

With a small correction: it must be hooked only in design time.
 
constructor TMyTabSheet.Create(TheOwner: TComponent);
begin
  ...
  if csDesigning in ComponentState then
    GlobalDesignHook.AddHandlerSetSelection(@HookSelection);
end;  
 
V.
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Vojtěch Čihák

Thank you, Ondrej, it works and it is pretty easy.
 
Summary:
 
Let's say you have class TMyPageControl which consists of TMyTabSheet classes 
(TWinControls).
 
uses ... PropEdits, ...;
 
TMyTabSheet = class(TWinControl)
  ...
  protected
    procedure HookSelection(const ASelection: TPersistentSelectionList);
  ...
  end;     
 
constructor TMyTabSheet.Create(TheOwner: TComponent);
begin
  ...
  GlobalDesignHook.AddHandlerSetSelection(@HookSelection);
end;  
 
procedure TMyTabSheet.HookSelection(const ASelection: TPersistentSelectionList);
begin
  if assigned(FMyPageControl) and (ASelection.IndexOf(self)>=0) then
    FMyPageControl.TabIndex:= FMyPageControl.Pages.IndexOf(self);
end;   
 
__

Od: Ondrej Pokorny 
Komu: Lazarus mailing list 
Datum: 22.05.2016 12:56
Předmět: Re: [Lazarus] Detect that component selected in OI.



Instead, do what Howard suggested (although not directly): In your 
component's design-time package, register a SetSelection hook 
("GlobalDesignHook.AddHandlerSetSelection(@OnComponentSelection);"). 
Then in OnComponentSelection you check if your own component is in the 
new selection and do whatever you want.


Ondrej

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus 


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

On 22.05.2016 11:02, Ondrej Pokorny wrote:

On 22.05.2016 8:50, Ondrej Pokorny wrote:
IMO you can suggest a custom designing message that will handle it 
without hard-coding it into the IDE. Because e.g. the TNotebook page 
change doesn't work.


No need. I added CM_OBJECTINSPECTORSELECT in r52338.


No, I reverted it. I though a little bit more about it and we shouldn't 
pollute the LCL with designer code if not necessary.


Instead, do what Howard suggested (although not directly): In your 
component's design-time package, register a SetSelection hook 
("GlobalDesignHook.AddHandlerSetSelection(@OnComponentSelection);"). 
Then in OnComponentSelection you check if your own component is in the 
new selection and do whatever you want.


Ondrej

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Example of TObjectList sorting

2016-05-22 Thread Ondrej Pokorny

You are using "procedure of object" where you need "procedure".

(One solution is to add static keyword to your procedure declaration, if 
the FPC version you use supports the typecast - iirc, fpc 3.0.0 can't do 
that in objfpc mode.)



Ondrej


On 22.05.2016 12:17, Richard Mace wrote:

Thanks Denis,

I am now getting:

inboundroutedestlist.pas(49,35) Error: Incompatible type for arg no. 
1: Got "of object;Register>", expected "function(Pointer;Pointer):LongInt;Register>"


Any ideas?

Richard

On 22 May 2016 at 07:30, Denis Kozlov > wrote:



On 21 May 2016 at 13:49, Richard Mace > wrote:

​Would I call the List.sort externally, or would the List call
sort when an Add has happened, as I don't seem to have a
".sort" method on my TObjectList?


You need to call List.Sort yourself, it is not sorted
automatically when you add more elements.

TObjectList does have a Sort method, since it descends from TList
class.

Denis



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Example of TObjectList sorting

2016-05-22 Thread Richard Mace
Thanks Denis,

I am now getting:

inboundroutedestlist.pas(49,35) Error: Incompatible type for arg no. 1: Got
"", expected ""

Any ideas?

Richard

On 22 May 2016 at 07:30, Denis Kozlov  wrote:

>
> On 21 May 2016 at 13:49, Richard Mace  wrote:
>
>> ​Would I call the List.sort externally, or would the List call sort when
>> an Add has happened, as I don't seem to have a ".sort" method on my
>> TObjectList?
>>
>
> You need to call List.Sort yourself, it is not sorted automatically when
> you add more elements.
>
> TObjectList does have a Sort method, since it descends from TList class.
>
> Denis
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

On 22.05.2016 8:50, Ondrej Pokorny wrote:
IMO you can suggest a custom designing message that will handle it 
without hard-coding it into the IDE. Because e.g. the TNotebook page 
change doesn't work.


No need. I added CM_OBJECTINSPECTORSELECT in r52338.

Ondrej


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Detect that component selected in OI.

2016-05-22 Thread Ondrej Pokorny

I didn't know it either. But it was quite easy to find out:

1.) Debug Lazarus IDE within another instance.
2.) In the IDE-to-debug create a project with TPageControl and 2 tabs.
3.) Set breakpoint to "TCustomTabControl.ShowCurrentPage" in the 
debugger IDE.

4.) Change pages with the OI in the IDE-to-debug.

Now you get your Call Stack filled with useful information. See #4 for 
relevant line:


#0 SHOWCURRENTPAGE(0x15087170) at include\customnotebook.inc:1049
#1 DOSENDPAGEINDEX(0x15087170) at include\customnotebook.inc:1072
#2 INTERNALSETPAGEINDEX(0x15087170, 0) at include\customnotebook.inc:985
#3 SETPAGEINDEX(0x15087170, 0) at include\customnotebook.inc:587
*#4 DOSELECTIONCHANGED(0x150683a0) at componenttreeview.pas:315*
#5 INTERNALSELECTIONCHANGED(0x150683a0) at include\treeview.inc:5715
#6 UNLOCKSELECTIONCHANGEEVENT(0x150683a0) at include\treeview.inc:5909
#7 SELECTONLYTHIS(0x169b89f0, 0x19c80ed8) at include\treeview.inc:2097
#8 MOUSEDOWN(0x150683a0, MBLEFT, [SSLEFT], 104, 64) at 
include\treeview.inc:5349

//...

So you can see that the changing code is hard-coded into IdeIntf. (The 
callback is in "TComponentTreeView.DoSelectionChanged;".)


IMO you can suggest a custom designing message that will handle it 
without hard-coding it into the IDE. Because e.g. the TNotebook page 
change doesn't work.


Ondrej


On 21.05.2016 22:49, Vojtěch Čihák wrote:


That's something else. I need something that will be part of 
component. Something like overriden SetFocus; or so.


So far I tried CMDesignHitTest and DoEnter but it didn't work.

It's like when you design Form with PageControl and two TabSheets. You 
select the second TabSheet in OI and PageControl "knows" it and it 
changes the tabs on the form. I'd like to know how this works (what 
component's code allows this).


Thanks, V.



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Example of TObjectList sorting

2016-05-22 Thread Denis Kozlov
On 21 May 2016 at 13:49, Richard Mace  wrote:

> ​Would I call the List.sort externally, or would the List call sort when
> an Add has happened, as I don't seem to have a ".sort" method on my
> TObjectList?
>

You need to call List.Sort yourself, it is not sorted automatically when
you add more elements.

TObjectList does have a Sort method, since it descends from TList class.

Denis
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus