Forum > LCL

TControl and TGraphic Control creation issue

<< < (3/7) > >>

So I loaded the components into the windows version of Lazarus and absolutely no problem dragging the seven segment display around the form.

I also tried it on LinuxCNC and same as the Beagle.

I've attached the zip of the project and the two component lpk folders. 
Maybe someone else wants to try this?


--- Quote from: jcdammeyer on April 26, 2021, 01:47:55 am ---Since it doesn't show up correctly as a form I think that's the first place to look.  Why is it that on a PC with Lazarus this form is correct while on Linux based systems it's not.  It implies the write once compile anywhere module is not working correctly.
--- End quote ---

Assuming that with "PC" you mean Windows-based then it could simply be that the widgetsets behave differently. Remember: on Windows the Windows API is used for the UI while on Linux it's either GTK or Qt. It could be that you stumbled either upon a bug in the way the LCL interfaces with that widgetset or - worse - a bug in the widgetset itself. Best try to minimize your problem as much as possible (like you already started in your last post) and then to report a bug. Also you could try if your widgetset is set to e.g. GTK to switch to Qt instead to see whether that solves the problem (or the other way round).

I understood that at a certain level Lazarus as the IDE isolates us from those details.   The whole point of the Delphi style interface is that you plop components down onto the form and link to the various events.  Makes for easy graphical applications development.  Whether under the covers it's Windows, GTK or Qt should, to the applications programmer be irrelevant.

What I do not know yet, but appears I'm going to have to learn is how a component is shown on the form during development.  Seems as if the code that makes up the 'paint' function or 'change' or 'refresh' is also called by the IDE to display the components on the form during development.

Unlike Delphi the IDE needs to be rebuilt every time a component is added.  So what I really need to do is take a step back and create a canvas rectangle, set the brush and pen colours and create canvas polygons.  All without the IDE forms design side since then it's part of the IDE.

And because the BBB and Pi are painfully slow I'll have to do it on a Linux desktop (the LinuxCNC one) since unfortunately the Windows PC Lazarus works the in the expected way.

It may be a few days before I get to this.  Work-work unfortunately has to come first.

Alright.  Spent some time this weekend reducing this project down to as simple as possible.
1. I'm trying to create a component that I can debug where the TGraphicControl object is created at run time rather than design time. 

2. I don't want to continually add it to the IDE and recompile the IDE so I'm trying to follow the component creation instructions that say test, test, test before you install it into the IDE so that you don't crash the IDE.

3. The sample project allows me to debug and see that everything in the unit jdsevensegdisplay.pas works with one problem.

I cannot figure out how to get the MainForm  FormPaint() method to call the paint function of the unit and therefore nothing is displayed.  Moving the
    procedure Paint; override;
down into published and calling it as

The same unit is installed as a component and displayed on the RHS of the form.  (see attached photo here) and increments on the press of the button.  At the moment I'd like the dynamically created TGraphicalControl on the LHS of the form but I'd also like to know how to position it anywhere on the form.

I have explored painting it into an TImage component.  That creates a black rectangle wherever the TImage is placed if the
  SevenSegDisplayImage.Value := CounterValue;
is done inside
with Image1.Canvas do   .. begin

I've attached a zip with the sample project and the component lpk or just remove the component from the form to avoid having to install it.

What am I missing when trying to dynamically create TGraphicControls at some XY location on the form?


The attached project makes a few adjustments to your main test program to create the component dynamically and exercise it.
To display a dynamically created control you need to set both its visual coordinates and its Parent (as well as any other relevant properties).
You don't need to explicitly call its Paint method. The LCL ensures that Paint is called whenever the OS needs to refresh the display.


[0] Message Index

[#] Next page

[*] Previous page

Go to full version