Recent

Author Topic: Hide Cursor Property on Custom Component  (Read 2951 times)

jerejigga

  • Newbie
  • Posts: 3
Hide Cursor Property on Custom Component
« on: June 01, 2014, 04:37:01 pm »
Since my custom component changes the mouse cursor based on where the mouse pointer is within the component, I need to hide the Cursor property from the IDE object inspector as well as any code that might try to set it.

I followed the instructions at http://wiki.freepascal.org/How_To_Write_Lazarus_Component to create a custom component.

Per this guide, I have two classes:

TCustomMyComponent = class(TGraphicControl)
...
end;

TMyComponent = class(TCustomMyComponent)
...
end;

TGraphicControl extends TControl which contains the Cursor property. My custom component changes the cursor based on where you are in the component so I don't want the Cursor to be writeable at the component level. (It's ok if it's read-only.)

I have tried making the Cursor private and a few other things, but no matter what it keeps appearing in the IDE inspector anyway. How do I hide the Cursor property?

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Hide Cursor Property on Custom Component
« Reply #1 on: June 01, 2014, 04:55:23 pm »
Quote
How do I hide the Cursor property?
It's probably impossible.
You can only change its default value.
Code: [Select]
published
  property Cursor default crDrag;
But Cursor has virtual setter (method SetCursor). You can override it and restrict any changes. You can do it so that you declare protected field FCursorLock: Boolean; it will be true. You can only temporarily change it to false, when you need to change cursor yourself.
Code: [Select]
  procedure SetCursor(AValue: TCursor); override;
...
  procedure TCustomMyComponent.SetCursor(AValue: TCursor);
  begin
    if not FCursorLock then inherited SetCursor(AValue);
  end;
and in your code:
Code: [Select]
FCursorLock:=False;
Cursor:= ....;
FCursorLock:=True;
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

zeljko

  • Hero Member
  • *****
  • Posts: 1764
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Hide Cursor Property on Custom Component
« Reply #2 on: June 01, 2014, 05:16:39 pm »
You cannot unpublish Cursor property, but you can override SetCursor() as Blazeen says.
procedure TMyComponent.SetCursor(Value: TCursor);
begin
   if not (csDesigning in ComponentState) then
     inherited SetCursor(Value);
end;

 

TinyPortal © 2005-2018