Board index » delphi » create shapes at runtime

create shapes at runtime

Shapes have useful features which I would like to take advantage of by
creating them at run time rather than in the designer.

Seems possible but I cannot get one to display on the Form
- myshape.visible := True;
- myshape.show

These do not work.   Any suggestions would be appreciated.

TIA
George.

 

Re:create shapes at runtime


After you create them, you need to set their Parent property or they
will not show up. Set their Parent to the object that contains them.

Re:create shapes at runtime


Sorry for some reason the reply went as a question.
Here is the correct way to design shapes at runtime.
with TShape.Create(Self) do
    begin
     Name:='name here';
     Align:=alNone;
     Left:=10; */ make your own
     Top:=10; */ make your own
     Width:=100;
     Height:=100;
     Shape:=stRectangle;
     Brush.Style:=bssolid;
     Brush.Color:=clRed;
     Pen.Color:=clRed;
      Visible:=true;
      Enabled:=true;
      Parent:=Form1;

     end;
   end;

  Make notice of */ as comment. double / will make a wierd note

  from the above example you can modify your component.

Quote
George Myers <geo...@thoughtshare.com> wrote in message

news:37CE9B98.D5E0643D@thoughtshare.com...
Quote
> Shapes have useful features which I would like to take advantage of by
> creating them at run time rather than in the designer.

> Seems possible but I cannot get one to display on the Form
> - myshape.visible := True;
> - myshape.show

> These do not work.   Any suggestions would be appreciated.

> TIA
> George.

Re:create shapes at runtime


Use Myshape.parent:= self;

Quote

>Shapes have useful features which I would like to take advantage of by
>creating them at run time rather than in the designer.

>Seems possible but I cannot get one to display on the Form
>- myshape.visible := True;
>- myshape.show

>These do not work.   Any suggestions would be appreciated.

>TIA
>George.

 Sent via Deja.com http://www.deja.com/
 Share what you know. Learn what you don't.

Re:create shapes at runtime


Alberto, if you place a space between the "//" and the comment, OE will not
give you the wierd note...

      Left:=10; // make your own
      Top:=10; // make your own

Quote
Alberto <chap...@bellsouth.net> wrote in message

news:7qmko5$g2c12@forums.borland.com...
Quote
> Sorry for some reason the reply went as a question.
> Here is the correct way to design shapes at runtime.
> with TShape.Create(Self) do
>     begin
>      Name:='name here';
>      Align:=alNone;
>      Left:=10; */ make your own
>      Top:=10; */ make your own
>      Width:=100;
>      Height:=100;
>      Shape:=stRectangle;
>      Brush.Style:=bssolid;
>      Brush.Color:=clRed;
>      Pen.Color:=clRed;
>       Visible:=true;
>       Enabled:=true;
>       Parent:=Form1;

>      end;
>    end;

>   Make notice of */ as comment. double / will make a wierd note

>   from the above example you can modify your component.

> George Myers <geo...@thoughtshare.com> wrote in message
> news:37CE9B98.D5E0643D@thoughtshare.com...
> > Shapes have useful features which I would like to take advantage of by
> > creating them at run time rather than in the designer.

> > Seems possible but I cannot get one to display on the Form
> > - myshape.visible := True;
> > - myshape.show

> > These do not work.   Any suggestions would be appreciated.

> > TIA
> > George.

Re:create shapes at runtime


Thanks!  Hopefully you have another suggestion...
Because I need to position the shapes, I set Top, Left, H & W and use
BringToFront, SendToBack.   Works fine, but now after putting a few
overlapping
shapes on the form when I change their size and position I see very annoying
flickering.

I have tried a number of things.
- changing the creation order,
- speeding up and slowing down (via timer) the changing of properties
- setting component style to opaque
- writing the property values only when any have changed

Ideally what I want to do is suppress painting at the component level during
shape
property adjustments and subsequently have the entire window repainted in
one
pass.  After that I want to turn on normal painting again.

My most desperate act was to try and intercept the WM_PAINT in the
WndProc and conditionally repaint by using another timer.  I suspect this
may contain the answer  but I ran into a strange side-effect, likely caused
by my ignorance of default windows msg processing (exhibited in the
following code
fragment)- immediately after setting DoPaint := False elswhere, the msg is
intercepted OK but all timers stop working - no ONTIMER events fire!

procedure TWebDeskForm.WndProc(var Message: TMessage);
var
 i : Integer;
begin

 if Message.Msg =  WM_PAINT then
 begin
   if bDoPaint = False then
      exit; // divert it
 end;
 inherited WndProc(Message);
end;

Quote
Alberto wrote:
> Sorry for some reason the reply went as a question.
> Here is the correct way to design shapes at runtime.
> with TShape.Create(Self) do
>     begin
>      Name:='name here';
>      Align:=alNone;
>      Left:=10; */ make your own
>      Top:=10; */ make your own
>      Width:=100;
>      Height:=100;
>      Shape:=stRectangle;
>      Brush.Style:=bssolid;
>      Brush.Color:=clRed;
>      Pen.Color:=clRed;
>       Visible:=true;
>       Enabled:=true;
>       Parent:=Form1;

>      end;
>    end;

>   Make notice of */ as comment. double / will make a wierd note

>   from the above example you can modify your component.

> George Myers <geo...@thoughtshare.com> wrote in message
> news:37CE9B98.D5E0643D@thoughtshare.com...
> > Shapes have useful features which I would like to take advantage of by
> > creating them at run time rather than in the designer.

> > Seems possible but I cannot get one to display on the Form
> > - myshape.visible := True;
> > - myshape.show

> > These do not work.   Any suggestions would be appreciated.

> > TIA
> > George.

Re:create shapes at runtime


On September 18 1999, you wrote:

Quote
> but now after putting a few
> overlapping
> shapes on the form when I change their size and position I see very
> annoying flickering.

You might be able to achieve all you want by just setting the
doublebuffered property of your form to true.

Renate

Re:create shapes at runtime


sounds encouraging... but would appreciate if you could elaborate -
cannot find
such property (in D3).
Quote
Renate Schaaf wrote:
> On September 18 1999, you wrote:
> > but now after putting a few
> > overlapping
> > shapes on the form when I change their size and position I see very
> > annoying flickering.

> You might be able to achieve all you want by just setting the
> doublebuffered property of your form to true.

> Renate

Re:create shapes at runtime


On September 18 1999, you wrote:

Quote
> sounds encouraging... but would appreciate if you could elaborate -
> cannot find
> such property (in D3).

Sorry, it's new in 4. I haven't been able to fake the doublebuffering in
D3. Maybe someone else can give you a hint.  You can try and add
[csOpaque] to the *form's* controlstyle, too.  Also, setting autoscroll
to false, if that's an option. And using "setbounds" for the shapes
rather than setting individual width and height.

Referring to your original message, rather than overriding the WndProc
as a whole, I'd only override the form's paint, something like this:

procedure TForm1.Paint;
begin
  if dbDoPaint then
  inherited;
end;

Maybe some of this helps.

Renate

Re:create shapes at runtime


Hi! Please HELP!!!!!!
A have to do a program which is very much like the M$ Paintbrush.
I have done all the functions but one.
On the Select Button, the program has to give the user the opportunity to select
a rect and drag it somewhere else. The former place of the rect has to remain
blanc.
I didn't yet manage to implement this functionality.
All the drawing is done on the Canvas of a TImage. The shapes(rect, filledrect,
roundrect, etc ) are done on the MouseMove event by calling a procedure
DrawShape.
Something like this:

procedure TFormPaintBrush.DrawShape(TopLeft, BottomRight: TPoint; AMode:
TPenMode);
var
   rcRect : TPaintStruct;
begin
   BeginPaint(Image.Canvas.Handle,rcRect);
 with Image.Canvas do
 begin
  Pen.Mode := AMode;
  case DrawingTool of
   dtLine: begin
    MoveTo(TopLeft.x, TopLeft.y);
    LineTo(BottomRight.x, BottomRight.y);
   end;
   dtDelete: begin
...........//some code
   end;
   dtRectangle: Rectangle(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
   dtSelect:begin
.................
         end;//dtSelect
         dtEllipse : ...........//some code
   dtRoundRect: ...........//some code
  dtEmptyEllypse:........//some code
  dtArrow:.........//some code
//etc, etc, etc
end;

I would sincerely appreciate if somebody could help me with the SELECT/Drag&Drop
part!
I also can be found at a...@crinsoft.ro

Re:create shapes at runtime


What i do to make things simple is to dynamicly create a Timage and copy the rect
information to it then
move the Timage as the mouse moves to a new location..
 this way the information under it will stay valid.
Var
Drag:Timage;
Begin
  Drag := Timage.Create(Application);
  Drag.Width := ?
  Drag.Hieght := ?
  Drag.Parent := MyMasterTimage ect....
  Drag.Canvas.CopyRect(.................
--
 Now just position the Image where you want on the screen using the Left,Top of the
Image..
Quote
Marius Bunescu wrote:
> Hi! Please HELP!!!!!!
> A have to do a program which is very much like the M$ Paintbrush.
> I have done all the functions but one.
> On the Select Button, the program has to give the user the opportunity to select
> a rect and drag it somewhere else. The former place of the rect has to remain
> blanc.
> I didn't yet manage to implement this functionality.
> All the drawing is done on the Canvas of a TImage. The shapes(rect, filledrect,
> roundrect, etc ) are done on the MouseMove event by calling a procedure
> DrawShape.
> Something like this:

> procedure TFormPaintBrush.DrawShape(TopLeft, BottomRight: TPoint; AMode:
> TPenMode);
> var
>    rcRect : TPaintStruct;
> begin
>    BeginPaint(Image.Canvas.Handle,rcRect);
>  with Image.Canvas do
>  begin
>   Pen.Mode := AMode;
>   case DrawingTool of
>    dtLine: begin
>     MoveTo(TopLeft.x, TopLeft.y);
>     LineTo(BottomRight.x, BottomRight.y);
>    end;
>    dtDelete: begin
> ...........//some code
>    end;
>    dtRectangle: Rectangle(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
>    dtSelect:begin
> .................
>          end;//dtSelect
>          dtEllipse : ...........//some code
>    dtRoundRect: ...........//some code
>   dtEmptyEllypse:........//some code
>   dtArrow:.........//some code
> //etc, etc, etc
> end;

> I would sincerely appreciate if somebody could help me with the SELECT/Drag&Drop
> part!
> I also can be found at a...@crinsoft.ro

Re:create shapes at runtime


Quote
Marius Bunescu <mar...@crinsoft.ro> wrote in message

news:380AECBE.2A32BFC1@crinsoft.ro...

Quote
> On the Select Button, the program has to give the user the opportunity to
select
> a rect and drag it somewhere else. The former place of the rect has to remain
> blanc.

Here's roughly how I believe Paint Shop Pro (PSP) does this:

1.  You need to have a rectangle selection tool that just
shows the outline of a rectangle.  The article
"How to Draw Marching Ants" by Robert Vivrette is an
excellent way to draw this rectangle (and appears to be
what PSP is doing):
www.undu.com/DN960901/00000008.htm

You will want to make an in-memory TBitmap
"background" copy of the whole image with the
selected rectangled filled with black (or whatever
color you want).

2.  Once this selection rectangle is in place, a MouseDown
followed by a MouseMove will result in you drawing
the selected area on a copy of the "background"
and redisplaying the result.

___
efg

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Other Threads