[SOLVED] change sub form icon at runtime lazarus / 34-Windows ---------------------------------------------------------------------- petevick · 2024-03-30 09:04 I'm trying to change the icon of a sub form at run time, I'm using the following code.... 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   ImageList1.GetBitmap(0, Image1.Picture.BitMap);  Form2.Icon.Assign(Image1.Picture.Graphic);  ....but I get an access violation error when I compile. There is definitely an image in ImageList1 and Image1 is declared  under TForm2 = class(TForm). I'm beginning to think that it's not possible to change a sub form icon. ---------------------------------------------------------------------- Fibonacci · 2024-03-30 09:10 What is Unit2? Is it a form name? Or a unit? Then what is the Icon inside Unit2? Try 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 ImageList1.GetBitmap(0, Image1.Picture.Bitmap);Form2.Icon.Assign(Image1.Picture.Bitmap); ---------------------------------------------------------------------- petevick · 2024-03-30 09:14 Quote from: Fibonacci on March 30, 2024, 10:10:37 amWhat is Unit2? Is it a form name? Or a unit? Then what is the Icon inside Unit2? Try 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 ImageList1.GetBitmap(0, Image1.Picture.Bitmap);Form2.Icon.Assign(Image1.Picture.Bitmap);my bad, mistyped, Unit2 should be Form2 ---------------------------------------------------------------------- Fibonacci · 2024-03-30 09:14 So it works now or not? ---------------------------------------------------------------------- petevick · 2024-03-30 09:15 Quote from: Fibonacci on March 30, 2024, 10:14:55 amSo it works now or not? sorry, no, it doesn't work ---------------------------------------------------------------------- Fibonacci · 2024-03-30 09:21 Works for me ---------------------------------------------------------------------- petevick · 2024-03-30 09:25 Quote from: Fibonacci on March 30, 2024, 10:21:45 amWorks for me Hmmm, there must be something in the rest of the code that's conflicting with it. ---------------------------------------------------------------------- petevick · 2024-03-30 10:07 Solved, it requires a physical TImage on the form rather that just declaring one  Thanks Fibonacci for the gif that gave me the clue ---------------------------------------------------------------------- Fibonacci · 2024-03-30 10:16 Sure But it works without TImage on the form too 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 with TImage.Create(nil) do begin  ImageList1.GetBitmap(0, Picture.Bitmap);  Form2.Icon.Assign(Picture.Bitmap);  Free;end; or 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 var  b: TBitmap;begin  Form2.Show;   b := TBitmap.Create;  ImageList1.GetBitmap(0, b);  Form2.Icon.Assign(b);  b.Free; ---------------------------------------------------------------------- TRon · 2024-03-30 10:16 Quote from: petevick on March 30, 2024, 11:07:19 amSolved, it requires a physical TImage on the form rather that just declaring one  Uhm, yes ? Classes requires to be instantiated ? see also manual. So, either you use the designer to let the form do it automatically for you or manually as shown by Fibonacci. ---------------------------------------------------------------------- petevick · 2024-03-30 11:19 Quote from: Fibonacci on March 30, 2024, 11:16:22 amSure But it works without TImage on the form too 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 var  b: TBitmap;begin  Form2.Show;   b := TBitmap.Create;  ImageList1.GetBitmap(0, b);  Form2.Icon.Assign(b);  b.Free; I like that method, thanks Fibonacci for the help and guidance