Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 10 total
Thread 'Transparent' component
Tue, Apr 25 2017 7:49 AMPermanent Link

Matthew Jones

I have two components on a panel. One is a label, the other has the Drag events handled. I'd like the label to be "click transparent", or somehow pass on its clicks to the underlying component. Is this possible?

--

Matthew Jones
Tue, Apr 25 2017 9:01 AMPermanent Link

Michael Dreher

"Matthew Jones" wrote:

 // I have two components on a panel. One is a label, the other has the Drag events handled.
 // I'd like the label to be   // "click transparent", or somehow pass on its clicks to the
 //  underlying component. Is this possible?

TLabel has a FocusControl property for delegating clicks.

M. Dreher
Tue, Apr 25 2017 9:56 AMPermanent Link

Uli Becker

Michael,

> TLabel has a FocusControl property for delegating clicks.

I don't think FocusControl is able to delegate a click-event. It just
passes the focus.
And: Panels are not in the list of the FocusControl property.

Uli
Tue, Apr 25 2017 10:08 AMPermanent Link

Matthew Jones

Michael Dreher wrote:

> TLabel has a FocusControl property for delegating clicks.

Thanks - this needs to be at a lower level I think.

--

Matthew Jones
Tue, Apr 25 2017 10:33 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< I have two components on a panel. One is a label, the other has the Drag events handled. I'd like the label to be "click transparent", or somehow pass on its clicks to the underlying component. Is this possible? >>

Sure, but you need to write a descendant control to do so.  The method that you need to use is:

        function ForwardEvent(AParentElement: TElement;
                                             ID: Integer; AElement: TElement): Boolean; virtual;

in the TInterfaceController class in the WebUI unit.

You would use it like this:

1) Check the ID to see if it's a cdClick event

2) If it is, then call the ForwardEvent method to forward the event to the parent control's client element (use Parent.ClientElement, not Parent.Element).

3) If it isn't, then just call the inherited DispatchEvent method.

Of course, in general, with such a control you probably just want to forward *everything* on to the parent control that deals with mouse/touch events.  This is much easier, of course:

type

  TMyLabel = class(TLabel)
     protected
        function DispatchEvent(ID: Integer; AElement: TElement): Boolean; override;
     end;

implementation

function TMyLabel.DispatchEvent(ID: Integer; AElement: TElement): Boolean;
begin
  if Assigned(Parent) and (ID >= cdMouseDown) and (ID <= cdTouchScroll) then
     Result:=ForwardEvent(Parent.ClientElement,ID,AElement)
  else
     Result:=inherited DispatchEvent(ID,AElement);
end;

If you put that on a form, you'll now notice that the form will now get all of the mouse/touch events originally intended for the label.

Also, further explanation about Element vs. ClientElement.  ClientElement is a "universal" reference.  For control's that don't have a client element (basic panels, labels), the ClientElement property automatically maps to the root Element for the control.  For more complex controls (panels, forms) that *do* have a client element, the ClientElement property will actually map to the client element for the control.  The client element *always* handles interaction with the control, so this makes sure that you're dispatching to the correct element for the control.  It's similar to Windows where there are non-client areas (window title/border) that don't receive normal interaction events, and client areas that do.

Tim Young
Elevate Software
www.elevatesoft.com
Tue, Apr 25 2017 11:00 AMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> ForwardEvent

Thanks - I may look into that, but in this particular case it looks like it would be easier to modify the one underneath anyway to show the text I'm using the label with. Perhaps though this makes sense for a general modification for TLabel, as a property, since that is probably the most common thing people will want to put on top of other things. Not important though.

--

Matthew Jones
Thu, Apr 27 2017 9:08 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Thanks - I may look into that, but in this particular case it looks like it would be easier to modify the one underneath anyway to show the text I'm using the label with. >>

Easier ?  It's 10 lines of code, and I *provided* the code.  All you need to do is put it in the unit of your choosing and pop it on the component palette via Library/Add Component.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Apr 27 2017 9:14 AMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> Easier ?  It's 10 lines of code, and I provided the code.  All you need to do is put it in the unit of your choosing and pop it on the component palette via Library/Add Component.

Hmm, I didn't realise it was complete, but it still needs me to add a new component etc. Silly question: Can I create such a component at run time? I used to do that a lot in Delphi to save installing components - just put a placeholder, create the replacement by copying properties, and then delete the placeholder. That would be a nice way forward.

--

Matthew Jones
Thu, Apr 27 2017 9:41 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Hmm, I didn't realise it was complete, but it still needs me to add a new component etc. Silly question: Can I create such a component at run time? I used to do that a lot in Delphi to save installing components - just put a placeholder, create the replacement by copying properties, and then delete the placeholder. That would be a nice way forward. >>

You're over-thinking this, and applying Delphi's issues with managing packages to EWB.

Did you actually try to add the control ?  It will literally take about 30 seconds, front to back:

1) Add Component
2) Give it a name (TMyLabel)
3) Type in what unit it is in
4) Click on OK

You don't even need an icon.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Apr 27 2017 10:04 AMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> Matthew,
>
> << Hmm, I didn't realise it was complete, but it still needs me to add a new component etc. Silly question: Can I create such a component at run time? I used to do that a lot in Delphi to save installing components - just put a placeholder, create the replacement by copying properties, and then delete the placeholder. That would be a nice way forward. >>
>
> You're over-thinking this, and applying Delphi's issues with managing packages to EWB.

Yes, but can I do it the way I suggest? That is, just reference the unit and create it manually? I guess so - no reason not to.


--

Matthew Jones
Image