Solved

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

Posted on 2004-04-08
12
197 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi: Connect to running MS Outlook 4 208
Firemonkey webbrowser scrollbars ? 1 70
Delphi: sending SMS on android platform 1 100
Delphi Firemonkey send email on Android 1 80
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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