rsah
asked on
Create Custom Shape Component
Hi, I need help on create a new component
This is my source code:
My problem is When I use method
What should I do to make shape repaint when I add string to top items
thanks
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,extctrls,
StdCtrls;
type
tmy=class(tshape)
topitem:tstrings;
bottomitem:tstrings;
constructor Create(Owner: TComponent); override;
procedure paint;override;
end;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a:tmy;
implementation
{$R *.DFM}
constructor Tmy.Create(Owner: TComponent);
begin
inherited Create(Owner); // Initialize inherited parts
topitem:=tstringlist.creat e;
end;
procedure tmy.paint;
begin
inherited paint;
if topitem.count>0 then
canvas.textout(1,1,topitem .strings[0 ]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
a:=tmy.create(self);
a.parent:=form1;
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
a.topitem.Add('Hello Hello');
end;
procedure TForm1.Button2Click(Sender : TObject);
begin
a.paint;
end;
end.
This is my source code:
My problem is When I use method
What should I do to make shape repaint when I add string to top items
thanks
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,extctrls,
StdCtrls;
type
tmy=class(tshape)
topitem:tstrings;
bottomitem:tstrings;
constructor Create(Owner: TComponent); override;
procedure paint;override;
end;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a:tmy;
implementation
{$R *.DFM}
constructor Tmy.Create(Owner: TComponent);
begin
inherited Create(Owner); // Initialize inherited parts
topitem:=tstringlist.creat
end;
procedure tmy.paint;
begin
inherited paint;
if topitem.count>0 then
canvas.textout(1,1,topitem
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
a:=tmy.create(self);
a.parent:=form1;
end;
procedure TForm1.Button1Click(Sender
begin
a.topitem.Add('Hello Hello');
end;
procedure TForm1.Button2Click(Sender
begin
a.paint;
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I agree with nnbbb09, seems like the only logical way of doing what you need...
Also, do not forget to create a destructor and override it to free your StringLists
destructor MyClass.Destroy;
begin
MyStringList1.Free;
MyStringList2.Free;
inherited Destroy;
end;
Shane Holmes
Also, do not forget to create a destructor and override it to free your StringLists
destructor MyClass.Destroy;
begin
MyStringList1.Free;
MyStringList2.Free;
inherited Destroy;
end;
Shane Holmes
ASKER
thanks nnbbb09
and also thanks to shaneholmes.
sorry to shaneholmes the credit is for nnbbb09
don't be angry
and also thanks to shaneholmes.
sorry to shaneholmes the credit is for nnbbb09
don't be angry
If you are trying to modify the apperance of a component, you can try to build a region in witch your component will painted:
var
FormRegion : THandle;
...
FormRegion := CreateRectRgn(Left, Top, Right, Bottom);
SetWindowRgn(YourComponent
You can also use different shapes than Rectangle (see Help).
GunDamn