Solved

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

Posted on 2004-04-08
12
183 Views
Last Modified: 2010-04-05
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.
0
Comment
Question by:MoonCalf
12 Comments
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
you should use a TCustom...-Ancestor
0
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
TCustom what?
0
 
LVL 17

Expert Comment

by:geobul
Comment Utility
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
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
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
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
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
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
How do I do that?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 17

Expert Comment

by:geobul
Comment Utility
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
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
Thanks, again, Geo, but that's done diddly.

More ideas?

MoonCalf.
0
 
LVL 17

Accepted Solution

by:
geobul earned 250 total points
Comment Utility
 TMyControl = class(TCustomControl)
  private
    FUnused : Boolean;
  published
    property Hint: Boolean read FUnused;
    property HelpContext: Boolean read FUnused;
    property Tag: Boolean read FUnused;
  end;
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
Comment Utility
--> 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
 
LVL 3

Expert Comment

by:Aliev
Comment Utility
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
 
LVL 1

Author Comment

by:MoonCalf
Comment Utility
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now