• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

How to sublass...

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
gspears060598
Asked:
gspears060598
  • 2
1 Solution
 
viktornetCommented:
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
 
gspears060598Author Commented:
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
 
viktornetCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now