Results 1 to 4 of 4

Thread: Delphi components and DelphX

  1. #1

    Delphi components and DelphX

    Hi guys, this might not be the right forum to ask this but here goes:

    Is it possible to use Delphi components, i.e. TShape etc. with DelphiX?

    My attempt:
    Code:
    //  The shape Class
      TShape = class(TGraphicControl)
      private
      public
      end;
    
    procedure TForm1.ShapeCreate;
    begin
      Shape := TShape.Create(TComponent.Create(shape));
      Shape.Parent := dxdraw1;
      shape.Color := clRed;
      shape.Canvas.RoundRect(100,100,150,150,170,200);
    end;
    Problem with the above is that the shape is not displayed/visible...any ideas?
    Wake up from the dream and live your life to the full

  2. #2
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,246
    Blog Entries
    2

    Delphi components and DelphX

    Hi Wizard,

    You can make the controls appear, but its very clunky and suffers from flicker.

    [pascal]
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    try
    fShape.free;
    except
    end;

    fShape:=TShape.create(dxdraw1);

    fShape.parent:=dxdraw1;

    fShape.top:=10;
    fShape.left:=10;
    end;

    procedure TForm1.Button2Click(Sender: TObject);
    begin
    try
    fShape.free;
    except
    end;
    end;

    procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
    var
    loop : integer;
    begin
    inc(fx);
    if (fx>100) then
    fx:=0;

    if dxdraw1.CanDraw then
    begin
    dxdraw1.Surface.Fill(0);

    dxdraw1.surface.canvas.pen.color:=clRed;

    dxdraw1.surface.canvas.MoveTo(fx,0);
    dxdraw1.surface.canvas.LineTo(fx,100);

    dxdraw1.surface.Canvas.release;

    for loop:=0 to dxdraw1.ComponentCount-1 do
    if (dxdraw1.components[loop] is TControl) then
    TControl(dxdraw1.components[loop]).Invalidate;

    dxdraw1.Flip;
    end;
    end;
    [/pascal]

    Without the 'for loop:=0.....invalidate;' part, the component appeared once and then vanished the next frame.

    This is just something I banged together to see if it could be done, and it can, but its not great. The problem is once you start flipping to a back buffer, the controls aren't redrawn because they don't get a message telling them they need to. Hence the requirement to invalidate them manullay, but the performance really does suck.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  3. #3
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,246
    Blog Entries
    2

    Delphi components and DelphX

    Another thought... I've just read the help on TGraphicControl...

    Your definition for your TShape (Mine was the standard VCL one) is based on TGraphicControl so to draw the shape, you should override the TGraphicControls PAINT method.

    [pascal]
    TShape = class(TGraphicControl)
    public
    procedure paint; override;
    end;

    ...

    procedure TShape.paint;
    begin
    // Setup the BRUSH and PEN properties of self.canvas here

    self.canvas.RoundRect(100,100,150,150,170,200);
    end;

    [/pascal]

    If you don't override the paint method, when the control receives the WM_PAINT message it won't draw anything and so it will be invisible. But, this will still suffer from flicker etc.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  4. #4

    Delphi components and DelphX

    Thanks for your replies Athena :-) I appreciate your help.

    Yip, it can be done but not realy worth the effort :-)

    Happy coding :-)
    Wake up from the dream and live your life to the full

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •