PDA

View Full Version : Delphi components and DelphX



Wizard
13-02-2007, 11:41 AM
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:


// 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?

AthenaOfDelphi
13-02-2007, 11:58 AM
Hi Wizard,

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


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;


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
13-02-2007, 12:04 PM
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.


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;



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.

Wizard
13-02-2007, 12:34 PM
Thanks for your replies Athena :-) I appreciate your help.

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

Happy coding :-)