Solved

How to sublass...

Posted on 1998-08-29
3
182 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
  • 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

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 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…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

16 Experts available now in Live!

Get 1:1 Help Now