Simple visual component with no inherited properties/methods/events.

Hi.

I've made components before, and never had any real issues, until I decided to make one for a HTML editor I'm currently working on.

What I want is a visual component that has top,left,width and height properties, and is sizable and movable on the form.

I want to add all the other properties, methods and events myself.  Is there anything I could define as the ancestor of my component that will give me that?  If not, how can I do it?  I did try using TWinControl and TControl, but found them both unsuitable - the TControl has redraw problems and both of them have too many properties that I don't want.

Alternatively, is there a way to simply override or hide the inherited properties when creating a component?

Thanks in advance,

MoonCalf.
LVL 1
MoonCalfAsked:
Who is Participating?
 
geobulConnect With a Mentor Commented:
 TMyControl = class(TCustomControl)
  private
    FUnused : Boolean;
  published
    property Hint: Boolean read FUnused;
    property HelpContext: Boolean read FUnused;
    property Tag: Boolean read FUnused;
  end;
0
 
kretzschmarCommented:
you should use a TCustom...-Ancestor
0
 
MoonCalfAuthor Commented:
TCustom what?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
geobulCommented:
Yes, kretzschmar is right. I'd derive the component from either TCustomControl if it should be able to receive focus or TGraphicControl if it shouldn't.
0
 
MoonCalfAuthor Commented:
I tried TCustomControl and found it better than the TControl, but it still has a bunch of standard properties that I do not want.

As long as the component is sizable and movable (top,left,width & height), and obviously has a name, then I can add the properties I want, rather than have them mixed up with the ones I don't want.

MoonCalf.
0
 
MoonCalfAuthor Commented:
Thanks Geobul - It does require focus as I'll be dragging and resizing.  I just need rid of the properties that are irrelevant to my component.

MoonCalf.
0
 
MoonCalfAuthor Commented:
How do I do that?
0
 
geobulCommented:
TCustomControl has four more published properties in my Delphi 5 - Cursor, Hint, HelpContext and Tag (excluding Name and coordinates). They are all useful. Which property do you want to remove? Try redefining them as public instead:

  TMyControl = class(TCustomControl)
  public
    property Hint;
    property HelpContext;
  end;  

Regards, Geo
0
 
MoonCalfAuthor Commented:
Thanks, again, Geo, but that's done diddly.

More ideas?

MoonCalf.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
--> Alternatively, is there a way to simply override or hide the inherited properties when creating a component?
If you want to 'Unpublish' some ancestor published properties, you need to let them became readonly for project inspector, so them won't anymore showed by it... to do this you have to reassign properties values by functions inheriting the result...

for example, to hide properties Cursor and Hint of a TCustomControl descendent:

unit customcontrol1;

interface

uses
  SysUtils, Classes, Controls;

type
  tcustomcontrol1 = class(TCustomControl)
  private
    { Private declarations }
  protected
    { Protected declarations }
    function GetHint: String;
    function GetCursor: TCursor;
  public
    { Public declarations }
  published
    { Published declarations }
    property Cursor: TCursor read GetCursor;
    property Hint: STring read GetHint;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Standard', [tcustomcontrol1]);
end;

function TCustomControl1.GetHint:String;
begin
  result := inherited Hint;
end;

function TCustomControl1.GetCursor: Tcursor;
begin
  result := inherited Cursor;
end;
end.
0
 
AlievCommented:
If you want to create any components on a base of standart components you don`t need build component from "null".
This example is Stantart label with any additional functions:

CodeEDITURLLabel_source.pas:

/////////////////////////////////////////////////////////////
//         CodeEDIT Components                             //
//                                                         //
//                                                         //
//         E-mail: components@aliev.info                   //
//         Web-site: http://codeedit.aliev.info            //
//         Copyright© 2003,Adil Aliev                      //
/////////////////////////////////////////////////////////////


unit CodeEDITURLLabel_source;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,  ShellAPI, StdCtrls;

type
  CodeEDITURLLabel = class(TLabel)
  private
    { Private declarations }
    fURL:string;
    fHoverFont:TFont;
    fFont:TFont;
    procedure SetHoverFont(Value:TFont);
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;


  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    procedure Click;override;

//    procedure Click(Sender: TObject); override;
  published
    { Published declarations }
     property URL:string read fURL write fURL;
     property HoverFont:TFont read fHoverFont write SetHoverFont;
     
  end;



implementation




constructor CodeEDITURLLabel.Create(AOwner: TComponent);
begin
inherited;

Caption:='http://codeedit.aliev.info';
Font.Color:=clBlue;
Font.Style:=[fsunderline];
Cursor:=crHandPoint ;

fFont:=TFont.Create;

fHoverFont:=TFont.Create;
fHoverFont.Color:=clBlue;  



end;



procedure CodeEDITURLLabel.Click;
begin

ShellExecute(Application.Handle ,'Open',pchar(fURL),'','',SW_NORMAL);

end;

procedure CodeEDITURLLabel.CMMouseEnter(var Message: TMessage);
begin
fFont.Assign(Font);
Self.Font:=fHoverFont;

end;

procedure CodeEDITURLLabel.CMMouseLeave(var Message: TMessage);
begin
Self.Font:=fFont;
end;

procedure CodeEDITURLLabel.SetHoverFont(Value:TFont);
begin
fHoverFont.Assign(Value);
fFont:=Self.Font;
end;

end.
0
 
MoonCalfAuthor Commented:
Geobul - thanks for the help.  Just what I wanted.

Aliev - "If you want to create any components on a base of standart components you don`t need build component from 'null'."  The question stated "Alternatively, is there a way to simply override or hide the inherited properties when creating a component?" so thanks, but I think you should have read the question before pasting loads of irrelevant code for future users to ignore.

Thanks everyone.

MoonCalf.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.