Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-04-08
12
Medium Priority
?
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10782323
you should use a TCustom...-Ancestor
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 10782413
TCustom what?
0
 
LVL 17

Expert Comment

by:geobul
ID: 10782415
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:MoonCalf
ID: 10782432
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
ID: 10782435
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
ID: 10782549
How do I do that?
0
 
LVL 17

Expert Comment

by:geobul
ID: 10782578
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
ID: 10782840
Thanks, again, Geo, but that's done diddly.

More ideas?

MoonCalf.
0
 
LVL 17

Accepted Solution

by:
geobul earned 1000 total points
ID: 10783456
 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 23

Expert Comment

by:Ferruccio Accalai
ID: 10784823
--> 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
ID: 10784937
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
ID: 10811403
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

670 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