Add a new property in TImage lazarus / 31-LCL ---------------------------------------------------------------------- antoniocangiano76 · 2021-08-25 19:17 Hi, I would like to know if it is possible to add a new property to a TImage. I need to add a property of type string called 'refer'  that i would use like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i image1.refer := 'pippo';Thanks ---------------------------------------------------------------------- antoniocangiano76 · 2021-08-25 19:27 A first thing I realized is that since Timage is created at runtime, I have to add ExtCtrls to the uses. ---------------------------------------------------------------------- Soner · 2021-08-25 20:53 You can also take cdesim's code and put it in a library and use it without installing it as component. You can still drop standard TImage from componentpalette on your form and acces new property refer like this: First create unit: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit myimage; {$mode objfpc}{$H+} interface uses Classes, ExtCtrls; type  TMyImage = class(TImage)  private    FRefer: string;  protected  public    property Refer: string read FRefer write FRefer;  end; implementationend. Drop standard image to your form and use it normal and change in your forms: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,  myimage; type  TImage = class(myimage.TMyImage); //<-- ADD THIS   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Image1: TImage;    procedure Button1Click(Sender: TObject);    procedure FormCreate(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  // LOOK at this: Image1 it is TImage with new property  Image1.Refer:='Yes, It is TImage with refer property';end; procedure TForm1.Button1Click(Sender: TObject);begin  ShowMessage('Image1.Refer property is:'+LineEnding+Image1.Refer);end; end. You can use TImage.Refer property only when you add at top of your units this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  myimage;type  TImage = class(myimage.TMyImage); //<-- ADD THIS  I added example project. ---------------------------------------------------------------------- egsuh · 2021-08-26 02:28 Interposing (what Soner is suggesting) is appropriate if you need to use it in many units of your project. If you are going to use it only one unit, I'd rather recommend using helpers. But here, if you need to add new fields, you cannot do it with helpers. To add single field, you may use "tag" property to store it. If you need to add more than one field, interpose will be the option. Currently I'm using interposing for many components, but all are collected in one unit file, for a project group. ---------------------------------------------------------------------- antoniocangiano76 · 2021-08-26 06:02 Quote from: cdesim on August 25, 2021, 10:05:19 pmYou could create a new class that descends from TImage Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TMyImage = class(TImage)  private    FRefer: string;  protected  public    property Refer: string read FRefer write FRefer;end; but then you could no longer simply drop it on a form from the component pallet - you would have to create it in your code. I have attached an example if you're interested. Perfect!!! It was what I wanted. I don't need to drop it on a form from the component pallet, I have to use in code. Very thanks ---------------------------------------------------------------------- antoniocangiano76 · 2021-08-26 06:21 Quote from: jamie on August 25, 2021, 10:44:02 pmor simply use the TAG property to point to a index of an array of string or constant. Thank, I thought about it but I was looking for a solution that would allow me to add n properties. What if I wanted to add a method as well? ---------------------------------------------------------------------- egsuh · 2021-08-27 07:01 QuoteWhat if I wanted to add a method as well? TMyImage is a inherited class, so you can do anything --- add new methods, new fields, or override methods.