Solved

How to sublass...

Posted on 1998-08-29
3
200 Views
Last Modified: 2010-04-04
I am reasonly new at the object side of Delphi.  Using D3.  I have purchased a 3rd party toolset with source, InfoPower.  They have a class, TwwDBEdit that I wish to make a similar class, but with an underline for a field instead of a complete border.  When I asked InfoPower about this, they said "I suppose you could subclass the component, and set the borderstyle to none, and have the wmpaint method paint the line the way you want..".

This is all fine and well, if I knew what I was doing... <g>. Can someone give me a shove in the right direction.  
-- Code fragments greatly appreciated --

Also, how do I get my new control to show up on the VCL controls panel.

Thanks
0
Comment
Question by:gspears060598
[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
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1338096
Start creating a new component and make it descendant from the one you want..in this case TwwDBEdit....
The unit should look something like this,,,,,
------------
unit Component1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TYourWwDBEdit = class(TwwDBEdit)
  private
    procedure Paint;override;//Only if there is a procedure like this...
  protected
    { Protected declarations }
  public
    constructor Create(AOwner : TComponent);override;
  published
    { Published declarations }
  end;

procedure Register;

implementation
constructor TYourWwDBEdit.Create(AOwner : TComponent);
begin
  Inherited Create(AOwner);
  //If you have any values you want to set by default here is you big chance...
end;
procedure TYourWwDBEdit.Paint;
begin
  //Paint the control......
end;
procedure Register;
begin
  RegisterComponents('Samples', [TwwDBEdit]);//This will show your component on the pallette
end;

end.
--------------

I think that's pretty much it...

Regards,
Viktor Ivanov
0
 

Author Comment

by:gspears060598
ID: 1338097
hi,

Your answer is just about complete.  Can you give me a little help with the wm_paint.  I was told this is what I need to use to draw the line.  I'd like it to be 3D, but I'll take what I can get.  I've tried to look up information, but haven't had a whole lot of luck yet...

0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338098
Here is a code I've tried with the TLabel component.....It is not finished yet, but it will show you how to draw a 3D underlining under the caption of the label....
----------------
unit Label1;

interface

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

type
  TLabel1 = class(TLabel)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    procedure Paint;override;
    Constructor Create(AOwner : TComponent);override;
  published
    { Published declarations }
  end;

procedure Register;

implementation
Constructor TLabel1.Create(AOwner : TComponent);
begin
  Inherited Create(AOwner);
end;

procedure TLabel1.Paint;
var
  High : Integer;
begin
  Inherited Paint;
  High := Canvas.TextHeight(Caption) + 1;
  Canvas.Pen.Color := clBtnShadow;
  Canvas.MoveTo(0, High - 1);
  Canvas.LineTo(Canvas.TextWidth(Caption),High - 1);

  Canvas.Pen.Color := clBtnHighLight;
  Canvas.MoveTo(0, High + 1);
  Canvas.LineTo(Canvas.TextWidth(Caption),High + 1);

  Canvas.Pen.Color := Font.Color;
  Canvas.MoveTo(0, High);
  Canvas.LineTo(Canvas.TextWidth(Caption),High);
end;

procedure Register;
begin
  RegisterComponents('Samples', [TLabel1]);
end;

end.
-------------
Hope this helps =)

Regards,
Viktor Ivanov
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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