Canvas Property on TRichedit??

Hello everyone,

I want to add Canvas property
in TRichedit. I tried by creating
a new component, inheriting from
TRichedit, then when i added the
canvas property, i get the message:
"not in the Base class..." during
compilation.
Please help me.

Thanks in advance.
eabell
eabellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kotikCommented:
Hi!
I used this code to do the same thing:

TMyRichEdit = class(TRichEdit)
private
  Canvas : TCanvas;
public
  constructor Create(AOwner: TComponent); override;
  destructor Destroy; override;
end;

implementation

constructor TMyRichEdit.Create(AOwner: TComponent);
begin
  Inherited Create(AOwner);
  Canvas := TControlCanvas.Create;
  TControlCanvas(Canvas).Control := self;
end;

destructor TMyRichEdit.Destroy;
begin
  Canvas.Free;
  inherited Destroy;
end;

Regards,
Kot
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eabellAuthor Commented:
Thanks..it works!
0
PoeticAudioCommented:
Here is the whole program,  there are of coarse better ways you could impliment this
but this should give you a good idea on how it works

unit Unit1;

interface

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

{Customized scrollbox}

type
  TMyScrollBox = class(TScrollBox)
  private
    Canvas : TCanvas;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;


{normal stuff}
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
    ScrollBox: TMyScrollBox;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TMyScrollBox }

constructor TMyScrollBox.Create(AOwner: TComponent);
begin
  Inherited Create(AOwner);
  Canvas := TControlCanvas.Create;
  TControlCanvas(Canvas).Control := self;
end;

destructor TMyScrollBox.Destroy;
begin
  Canvas.Free;
  inherited Destroy;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with Scrollbox do
  begin
    left := 0;
    top := 0;
    Width := 100;
    Height := 100;
    Parent := Form1;
    Show;
  end;

  Scrollbox.Canvas.Pen.Color := clRed;
  Scrollbox.Canvas.MoveTo(0, Scrollbox.Height div 2);
  Scrollbox.Canvas.LineTo(Scrollbox.Width, Scrollbox.Height div 2);

end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  Scrollbox := TMyScrollBox.Create(form1);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Scrollbox.Destroy;
end;


end.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.