Solved

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

Posted on 2004-04-08
12
194 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 250 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 22

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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