Recent

Author Topic: [SOLVED] Tshape onclick do not works  (Read 414 times)

torbente

  • Sr. Member
  • ****
  • Posts: 298
    • Noso Main Page
[SOLVED] Tshape onclick do not works
« on: January 14, 2021, 08:19:52 pm »
Hi everyone.
I created a Tshape:

Code: Pascal  [Select][+][-]
  1. ConnectCircle := Tshape.Create(form1);ConnectCircle.Parent:=form1;
  2. ConnectCircle.Top:=2;ConnectCircle.Left:=2;ConnectCircle.Height:=26;ConnectCircle.Width:=26;
  3. ConnectCircle.Shape:=stcircle;ConnectCircle.Brush.Color:=clred;ConnectCircle.Brush.Style:=bssolid;
  4. ConnectCircle.Visible:=true;ConnectCircle.Enabled:=true;
  5. ConnectCircle.ShowHint:=true;ConnectCircle.Hint:='Disconnected';
  6. ConnectCircle.OnClick:=@Form1.ConnectCircleOnClick;
  7.  
  8. Procedure TForm1.ConnectCircleOnClick(Sender: TObject);
  9. Begin
  10. ConnectCircle.Brush.Color:=clgreen;
  11. End;
  12.  

The onclick procedure is not working. I can change the color at runtime, but for some reason the onclick do not works.
Any idea?

EDIT: the tshape is not showing the hint neither...  :o
« Last Edit: January 15, 2021, 01:25:16 am by torbente »
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

jamie

  • Hero Member
  • *****
  • Posts: 4211
Re: Tshape onclick do not works
« Reply #1 on: January 14, 2021, 10:37:17 pm »
laz version ?


EDIT

 I just checked old Laz 2.0.4 and Trunk, all working here.
« Last Edit: January 14, 2021, 11:06:18 pm by jamie »
The only true wisdom is knowing you know nothing

torbente

  • Sr. Member
  • ****
  • Posts: 298
    • Noso Main Page
Re: Tshape onclick do not works
« Reply #2 on: January 14, 2021, 11:02:54 pm »
Lazarus 2.0.10 r63526 on windows 8.1
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

speter

  • Full Member
  • ***
  • Posts: 162
Re: Tshape onclick do not works
« Reply #3 on: January 14, 2021, 11:21:05 pm »
G'Day Torbente,

I recreated your example and it worked without a problem.
I have added a tlabel (see screenshot) and cleaned up your code a little.


Code: Pascal  [Select][+][-]
  1.   TForm1 = class(TForm)
  2.     Label1: TLabel;
  3.     procedure FormCreate(Sender: TObject);
  4.   private
  5.   public
  6.     ConnectCircle : TShape;
  7.     Procedure ConnectCircleOnClick(Sender: TObject);
  8.   end;
  9.  
  10. ...
  11.  
  12. procedure TForm1.FormCreate(Sender: TObject);
  13. begin
  14.   ConnectCircle := TShape.Create(form1);
  15.   with ConnectCircle do
  16.     begin
  17.       Parent:=form1;
  18.       Top:=2;
  19.       Left:=2;
  20.       Height:=26;
  21.       Width:=26;
  22.       Shape:=stcircle;
  23.       Brush.Color:=clred;
  24.       Brush.Style:=bssolid;
  25.       Visible:=true;
  26.       Enabled:=true;
  27.       ShowHint:=true;
  28.       Hint:='Disconnected';
  29.       OnClick:=@Form1.ConnectCircleOnClick;
  30.     end;
  31.  
  32. end;
  33.  
  34. Procedure TForm1.ConnectCircleOnClick(Sender: TObject);
  35. Begin
  36.   ConnectCircle.Brush.Color:=clgreen;
  37.   label1.caption := 'after';
  38. End;

What event did you use when you created your TShape?

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.10 / FPC 3.2.0 / Windows 10 (64bit)

torbente

  • Sr. Member
  • ****
  • Posts: 298
    • Noso Main Page
Re: Tshape onclick do not works
« Reply #4 on: January 14, 2021, 11:33:25 pm »
It is created at formshow; i create all my controls there.
I have somebuttons created at formshow and they work perfect.
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

speter

  • Full Member
  • ***
  • Posts: 162
Re: Tshape onclick do not works
« Reply #5 on: January 14, 2021, 11:40:38 pm »
When I move my "create" code from FormCreate to FormShow the program still works fine.

I am not sure what the issue is.

cheers
S.

Edit: Is it possible that you have a component over (on top) the TShape? I've had a paintbox over other components, and was therefore unable to interact with the "lower" components...
« Last Edit: January 14, 2021, 11:43:27 pm by speter »
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.10 / FPC 3.2.0 / Windows 10 (64bit)

torbente

  • Sr. Member
  • ****
  • Posts: 298
    • Noso Main Page
Re: Tshape onclick do not works
« Reply #6 on: January 15, 2021, 01:24:48 am »
Done! I had an old, transparent and completely forgot label in front!
Thanks for your tip.
Noso Cryptocurrency Main Developer
https://github.com/DevTeamNoso/NosoWallet

 

TinyPortal © 2005-2018