DezsoSajer 0 Posted October 4, 2022 Hi, I am creating an indicator of a machine, in the style of a PFD (Primary Flight Display) using the TImage32 library. I finished the work, and I need 2 of these indicators, so I added the second one to my form (I am using a panel to draw the image). Strangly, the second one is not showing the texts. I would like to ask some pointers where I should check the source of the problem. I swapped the order of creation, and the problem swapped, too. So the first created works, but not 2nd. Thank you Share this post Link to post
angusj 126 Posted October 4, 2022 (edited) I'm not sure why you're having problems. I've attached a very simple test that shows text drawing on 2 TImage32Panel controls. procedure TForm1.FormCreate(Sender: TObject); begin fc := TFontCache.Create(FontManager.Load('Arial'), dpiAware(20)); end; procedure TForm1.FormDestroy(Sender: TObject); begin fc.Free; end; procedure TForm1.FormResize(Sender: TObject); begin with Image32Panel1 do begin Width := self.ClientWidth div 2; //Align = alLeft image.SetSize(InnerClientRect.Width,InnerClientRect.Height); DrawLine(image, Rectangle(0,0,image.Width, image.Height), 10, clRed32, esPolygon); DrawText(Image, Image.Bounds, 'This is Panel1', taCenter, tvaMiddle, fc); end; with Image32Panel2 do begin //Align = alClient image.SetSize(InnerClientRect.Width,InnerClientRect.Height); DrawLine(image, Rectangle(0,0,image.Width, image.Height), 10, clRed32, esPolygon); DrawText(Image, Image.Bounds, 'This is Panel2', taCenter, tvaMiddle, fc); end; end; img32_test.zip Edited October 4, 2022 by angusj Share this post Link to post
DezsoSajer 0 Posted October 5, 2022 (edited) Hi, Thanks very much for the project. I have tested, and it worked on mine PC, too. However, when I modified it to the same way I have in my project (moved it to a unit and created a class), the same thing happened. Main unit: unit main; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls,Unit1; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private public { Public declarations } end; var Form1: TForm1; Image32Panel1: testclass; Image32Panel2: testclass; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Image32Panel1:=testclass.Create(Self,0); Image32Panel2:=testclass.Create(Self,ClientWidth div 2); end; procedure TForm1.FormDestroy(Sender: TObject); begin Image32Panel1.Free; Image32Panel2.Free; end; end. Class unit unit Unit1; interface uses System.Classes,Img32.Panels,Img32, Img32.Vector, Img32.Draw, Img32.Text,VCL.Controls; type testclass=class private FImagePanel:TImage32Panel; fc: TFontCache; public constructor Create(AOwner:TComponent;LeftPos:integer); destructor Destroy; end; implementation { testclass } constructor testclass.Create(AOwner:TComponent;LeftPos:integer); begin fc := TFontCache.Create(FontManager.Load('Arial'), dpiAware(20)); FImagePanel:=TImage32Panel.Create(AOwner); FImagePanel.Parent:=AOwner As TWinControl; with FImagePanel do begin Left:=LeftPos; Width := FImagePanel.Parent.ClientWidth div 2; image.SetSize(InnerClientRect.Width,InnerClientRect.Height); DrawLine(image, Rectangle(0,0,image.Width, image.Height), 10, clRed32, esPolygon); Img32.Text.DrawText(Image, Image.Bounds, 'This is TImagePanel Panel1', taCenter, tvaMiddle, fc); end; end; destructor testclass.Destroy; begin FImagePanel.Free; fc.Free; end; end. img32_test.zip Edited October 5, 2022 by DezsoSajer Share this post Link to post
angusj 126 Posted October 6, 2022 (edited) Yes, the problem is/was that you were trying to load the same font twice ... FontManager.Load('Arial') and this was failing. Strictly speaking this wasn't a bug but logically it makes sense to return the first loaded font when a fontname is supplied multiple times. And I've just updated the GitHub repository to address this. https://github.com/AngusJohnson/Image32 Thanks again for the feedback. ps: It's better to raise issues with Image32 here: https://github.com/AngusJohnson/Image32/issues OR https://github.com/AngusJohnson/Image32/discussions Edited October 6, 2022 by angusj Share this post Link to post
DezsoSajer 0 Posted October 6, 2022 Hi angusj, Thanks very much for the solution Share this post Link to post