Recent

Author Topic: Adding a TShape in code issue  (Read 888 times)

JasonLugg

  • Jr. Member
  • **
  • Posts: 67
Adding a TShape in code issue
« on: April 24, 2019, 02:15:27 pm »
Hi All

I wish to add a TShape using a class called from the MainUnit (Containing the main form and the TPanel I wish to add the Tshape to). I can do this but for some reason the TShape is not shown on the main form? I wish the TShape to be

Here is my Class constructor
Code: Pascal  [Select][+][-]
  1. constructor tNPCObjectType.Create(sObjNameIn: string; xPos, yPos, iWidth, iHeight: integer; tType: tObj_Type; iDistance: integer; iMoveSpeed: integer; tCompToAdd: TPanel);
  2. begin
  3.      tNPC_Shape:=TShape.Create(tCompToAdd);
  4.      tNPC_Shape.Shape:=TShapeType.stRectangle;
  5.      tNPC_Shape.Left:=xPos;
  6.      tNPC_Shape.Top:=yPos;
  7.      case tType of
  8.           tObj_Type.tStill:
  9.             begin
  10.               tNPC_Shape.SetBounds(xPos, yPos+24, 24, 24);
  11.             end;
  12.           tObj_Type.tHorizontal:
  13.             begin
  14.               //tNPC_Shape.SetBounds(xPos, yPos+24, 24, iDistance);
  15.               //DEBUG
  16.               tNPC_Shape.SetBounds(24,24,100,100);
  17.             end;
  18.           tObj_Type.tVertical:
  19.             begin
  20.               tNPC_Shape.SetBounds(xPOs, yPos+24, iDistance, 24);
  21.             end;
  22.      end;
  23.      tNPC_Shape.Pen.Color:=clBlue;
  24.      tNPC_Shape.Brush.Color:=clWhite;
  25.      tNPC_Shape.Brush.Style:=bsSolid;
  26.      tNPC_Shape.Visible:=true;
  27.  
  28.  
  29.      bInit:=true;
  30.  
  31. end;

Here is the Calling Code:
Code: Pascal  [Select][+][-]
  1. aNPC:=tNPCObjectType.Create(anObjName,npcShape.Left, npcShape.Top, 24, 24, npc_Type, iDist, 4, ScenePanel);

Any ideas why the newly created TShape in the class is not being displayed?


Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: Adding a TShape in code issue
« Reply #1 on: April 24, 2019, 02:33:38 pm »
« Last Edit: April 24, 2019, 02:42:41 pm by Thausand »

furious programming

  • Hero Member
  • *****
  • Posts: 858
Re: Adding a TShape in code issue
« Reply #2 on: April 24, 2019, 04:10:53 pm »
Exactly — no parent means invisible.

Code: Pascal  [Select][+][-]
  1. tNPC_Shape := TShape.Create(tCompToAdd);
  2. tNPC_Shape.Parent := tCompToAdd;
  3. {..}
Lazarus 3.2 with FPC 3.2.2, Windows 10 — all 64-bit

Working solo on an acrade, action/adventure game in retro style (pixelart), programming the engine and shell from scratch, using Free Pascal and SDL. Release planned in 2026.

 

TinyPortal © 2005-2018