Recent

Author Topic: if ImageList  (Read 690 times)

BIT

  • Jr. Member
  • **
  • Posts: 80
if ImageList
« on: February 27, 2021, 08:53:43 am »
How do I determine that an ImageList is connected to a component?
Code: Pascal  [Select][+][-]
  1. if ImageList  then
« Last Edit: February 27, 2021, 10:48:09 am by BIT »

Soner

  • Full Member
  • ***
  • Posts: 221
Re: if ImageList
« Reply #1 on: February 27, 2021, 10:03:15 am »
If Assigned(MyPageControl1.Images) then ....

BIT

  • Jr. Member
  • **
  • Posts: 80
Re: if ImageList
« Reply #2 on: February 27, 2021, 10:27:33 am »
I'm trying to create a component with PageControl tab closure buttons. But I can't make a check on ImageList . If you run as is, an error occurs.
Your option didn't help(
10 years ago I created components (now I've forgotten everything) and even how to add my own properties))
Code: Pascal  [Select][+][-]
  1. unit MyPageControl;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Windows, LCLIntf, Classes, SysUtils, LResources, Forms, Controls,
  9.   Graphics, Dialogs, ComCtrls;
  10.  
  11. type
  12.  
  13.   { TMyPageControl }
  14.  
  15.   TMyPageControl = class(TPageControl)
  16.   private
  17.  
  18.   const
  19.     btnSize = 14;
  20.   protected
  21.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  22.       X, Y: integer); override;
  23.     procedure PaintWindow(DC: HDC); override;
  24.   public
  25.  
  26.  
  27.   published
  28.  
  29.   end;
  30.  
  31. procedure Register;
  32.  
  33. implementation
  34.  
  35. procedure Register;
  36. begin
  37.   {$I mypagecontrol_icon.lrs}
  38.   RegisterComponents('Common Controls', [TMyPageControl]);
  39. end;
  40.  
  41. { TMyPageControl }
  42.  
  43. procedure TMyPageControl.MouseDown(Button: TMouseButton; Shift: TShiftState;
  44.   X, Y: integer);
  45.  
  46. var
  47.   R: TRect;
  48. begin
  49.   inherited MouseDown(Button, Shift, X, Y);
  50. //
  51.   if Assigned(Images) then
  52.   begin
  53. //
  54.     if Button = mbLeft then
  55.     begin
  56.       R := TabRect(ActivePageIndex);
  57.       if PtInRect(Classes.Rect(R.Right - btnSize - 5, R.Top + 4,
  58.         R.Right - 5, R.Top + btnSize + 4), Classes.Point(X, Y)) then
  59.       begin
  60.  
  61.         ActivePage.Free;
  62.       end;
  63.     end;
  64.   end;
  65.  
  66. end;
  67.  
  68. //PageClose img
  69. procedure TMyPageControl.PaintWindow(DC: HDC);
  70. var
  71.   i: integer;
  72.   R: TRect;
  73.   bm: TBitmap;
  74. begin
  75.   inherited PaintWindow(DC);
  76. //
  77.   if Assigned(Images) then
  78.   begin
  79. //
  80.     bm := TBitmap.Create;
  81.  
  82.     try
  83.       bm.SetSize(16, 16);
  84.  
  85.       Images.GetBitmap(1, bm); //Icon index 1 ImageList
  86.  
  87.       for i := 0 to Pred(PageCount) do
  88.       begin
  89.         R := TabRect(i);
  90.         StretchBlt(DC, R.Right - btnSize - 4, R.Top + 2,
  91.           btnSize, btnSize, bm.Canvas.Handle, 0, 0, 16, 16, cmSrcCopy);
  92.       end;
  93.     finally
  94.       bm.Free;
  95.     end;
  96.  
  97.   end;
  98.  
  99. end;
  100.  
  101. end.
« Last Edit: February 27, 2021, 10:59:08 am by BIT »

BIT

  • Jr. Member
  • **
  • Posts: 80
Re: if ImageList
« Reply #3 on: February 27, 2021, 12:32:07 pm »
Excuse me! After reinstalling the component, everything worked!

jamie

  • Hero Member
  • *****
  • Posts: 4337
Re: if ImageList
« Reply #4 on: February 28, 2021, 01:42:12 am »
maybe this should be implemented in the Win32 widget so that it works as it does on other platforms.

could even add a little fluff to it.
The only true wisdom is knowing you know nothing

BIT

  • Jr. Member
  • **
  • Posts: 80
Re: if ImageList
« Reply #5 on: February 28, 2021, 06:58:17 am »
I do it on win32 . Now I remember how to add my properties to the currently working code of the component.
Component with an example https://disk.yandex.ru/d/bwo_ZX6umA3jNQ
Tab with the Common Controls component.

Code: Pascal  [Select][+][-]
  1. unit MyPageControl;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Windows, Classes, SysUtils, LResources, Forms, Controls,
  9.   Graphics, Dialogs, ComCtrls;
  10.  
  11. type
  12.  
  13.   { TMyPageControl }
  14.  
  15.   TMyPageControl = class(TPageControl)
  16.   private
  17.     ImagesIndex: integer;
  18.     procedure SetImagesIndex(AValue: integer);
  19.   const
  20.     btnSize = 14;
  21.   protected
  22.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  23.       X, Y: integer); override;
  24.     procedure PaintWindow(DC: HDC); override;
  25.   published
  26.     property ImagesCloseIndex: integer read ImagesIndex write SetImagesIndex default 0;
  27.   end;
  28.  
  29. procedure Register;
  30.  
  31. implementation
  32.  
  33. procedure Register;
  34. begin
  35.   {$I mypagecontrol_icon.lrs}
  36.   RegisterComponents('Common Controls', [TMyPageControl]);
  37. end;
  38.  
  39. { TMyPageControl }
  40.  
  41. //properties ImageIndex
  42. procedure TMyPageControl.SetImagesIndex(AValue: integer);
  43. begin
  44.   ImagesIndex := AValue;
  45.   Refresh;
  46.  
  47. end;
  48.  
  49. //Close MouseDown
  50. procedure TMyPageControl.MouseDown(Button: TMouseButton; Shift: TShiftState;
  51.   X, Y: integer);
  52. var
  53.   R: TRect;
  54. begin
  55.   inherited MouseDown(Button, Shift, X, Y);
  56.   if Assigned(Images) then
  57.   begin
  58.     if Button = mbLeft then
  59.     begin
  60.       R := TabRect(ActivePageIndex);
  61.       if PtInRect(Classes.Rect(R.Right - btnSize - 5, R.Top + 4,
  62.         R.Right - 5, R.Top + btnSize + 4), Classes.Point(X, Y)) then
  63.       begin
  64.  
  65.         ActivePage.Free;
  66.       end;
  67.     end;
  68.   end;
  69.  
  70. end;
  71.  
  72. //Page Close img
  73. procedure TMyPageControl.PaintWindow(DC: HDC);
  74. var
  75.   i: integer;
  76.   R: TRect;
  77.   bm: TBitmap;
  78. begin
  79.   inherited PaintWindow(DC);
  80.   if Assigned(Images) then
  81.   begin
  82.     bm := TBitmap.Create;
  83.  
  84.     try
  85.       bm.SetSize(16, 16);
  86.       Images.GetBitmap(ImagesCloseIndex, bm);
  87.  
  88.       for i := 0 to Pred(PageCount) do
  89.       begin
  90.         R := TabRect(i);
  91.         StretchBlt(DC, R.Right - btnSize - 4, R.Top + 2,
  92.           btnSize, btnSize, bm.Canvas.Handle, 0, 0, 16, 16, cmSrcCopy);
  93.       end;
  94.     finally
  95.       bm.Free;
  96.     end;
  97.   end;
  98. end;
  99.  
  100. end.
« Last Edit: February 28, 2021, 07:27:18 am by BIT »

 

TinyPortal © 2005-2018