Recent

Author Topic: TControl and TGraphic Control creation issue  (Read 8279 times)

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
TControl and TGraphic Control creation issue
« on: April 25, 2021, 09:25:24 am »
I ported a Delphi component over to Lazarus.  Ran fine on Windows.  But has issues on both the Pi and the Beaglebone.  That was many months ago and it's only this weekend that I've had a chance to try and chase down the issue.
I've added some screen shots to demonstrate what Lazarus is seeing.
The creation of the component and assignment with the value of 40 to the width which part of the TControl object.
Hovering with the cursor over the Width shows how/where it's been declared on the PC.
Notice the property is the same on the Beagle.
But run the program with a break point and suddenly the Width component is gone.   Since I'm limited to 4 JPGs I can add the one showing the PC does not have this problem on a follow up posting.
« Last Edit: April 25, 2021, 09:32:58 am by jcdammeyer »

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: TControl and TGraphic Control creation issue
« Reply #1 on: April 25, 2021, 09:32:32 am »
So the question is why on the Beagle and the Pi is the Width parameter not initialized (random value) and marked as unknown while on the PC it has the value assigned in the create constructor.

The end result is that on the Pi or the Beagle the display the first digit is incorrect and in the wrong position and the other 3 are blank.  The calculation
  W := Width / 20;
  H := Height / 38;

sets W and H effectively to 0.  (a very small float number).

Don't know where to look next since the edit shows the correct linkage while the run time debug does not but only on the Beagle or Pi.  Not a PC.



jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: TControl and TGraphic Control creation issue
« Reply #2 on: April 25, 2021, 02:21:27 pm »
You have different screen resolutions,  you need a scaler divider that is calculated via your screen X,Y resolution and not use fixed values..

The only true wisdom is knowing you know nothing

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: TControl and TGraphic Control creation issue
« Reply #3 on: April 25, 2021, 05:19:19 pm »
You have different screen resolutions,  you need a scaler divider that is calculated via your screen X,Y resolution and not use fixed values..

If the components were oddly shaped I could see that but the PC with 1080 and the Pi with 1080 have the same resolution.  The Beagle is stretched so circles aren't round but in either case the value of Width passed to TdsSevenSegmentDisplay.DrawSegment(s:Byte) should not be 0 since the value 40 was assigned to it inside the create constructor.

When I put a break point inside that constructor TdsSevenSegmentDisplay.Create(AOwner : TComponent) and look at Width it does indeed have 40 in it.

So why later when DrawSegment is called does it no longer have a value?  Lazarus under Windows does not have that issue so there's something different in the ARM family.  But what?

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: TControl and TGraphic Control creation issue
« Reply #4 on: April 25, 2021, 05:35:17 pm »
maybe bad compiler..

 There has been recent corrections made with the compiler for arm but I think you need to get the most recent truck for that and of course you will need to rebuild all of the LCL code etc with that compiler..

The only true wisdom is knowing you know nothing

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: TControl and TGraphic Control creation issue
« Reply #5 on: April 25, 2021, 06:21:06 pm »
maybe bad compiler..

 There has been recent corrections made with the compiler for arm but I think you need to get the most recent truck for that and of course you will need to rebuild all of the LCL code etc with that compiler..

Possibly.  But this seems too obvious a problem not to have shown up a long time ago.  I'll whack away at it for a bit.  I'd like to know why it's broken.  Not just blindly type something in to fix it.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: TControl and TGraphic Control creation issue
« Reply #6 on: April 25, 2021, 07:05:57 pm »
I got looking at  your problem a little closer..

can you try instead of using "/" as the divider and use "DIV" instead ?

Also, I guess another question would be is did you use the IDE to design the class or are you doing this at the raw level ?

The IDE needs to read the values from the resource of the file which is attached at the end of the application file. This is done during the Construction period so that means you either need to use the OnCreate of the form there by allowing this process to complete or if you are overriding the constructor then you need to ensure you call the inherited first..

 But if you are doing this at RAW metal level, then of course these WIDTH, HEIGHT etc values will be 0 at start.

The only true wisdom is knowing you know nothing

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: TControl and TGraphic Control creation issue
« Reply #7 on: April 25, 2021, 07:13:29 pm »
Just headed out on doggy walk so I'll check when I get back. 

The odd thing is the exact same code works with Lazarus for Windows and I've just been through the files doing some tweaking and {$IFDEF} work so now it again compiles with Delphi 10.3 or Lazarus on the PC.  I'll copy that project folder back onto the Beagle and the Pi and give it another try.

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: TControl and TGraphic Control creation issue
« Reply #8 on: April 26, 2021, 01:47:55 am »
I just downloaded the folder with the project onto a LinuxCNC PC.  Had to install the dsLED component in order to get the form to show up.  And it shows up just like it does on the Beagle and that's different from the PC Lazarus or Delphi version.

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.

I'll go through the tutorial along with this part
https://wiki.lazarus.freepascal.org/How_To_Write_Lazarus_Component#Step_3:_Create_icons_for_the_package
because the package icons show up correctly for WIN-10 Delphi but not Lazarus at all.

Baby steps I guess.


jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: TControl and TGraphic Control creation issue
« Reply #9 on: April 28, 2021, 07:55:13 am »
I broke the project down to be a bit simpler since I couldn't figure out why the 7 segment display was offset from the rectangle.  Quite by accident when I was moving things around on the form I stumbled on the underlying root of the problem.  Don't have a solution yet though.

I created a form with just the single 7 segment component created from scratch on the BBB with Lazarus 2.0.10.  I also added another component that has a 6 digit display and works properly; to try and figure out what's different...

Anyway, the basic component works wonderfully if the component is placed at 0,0.  Click the button and the Value is incremented each time the LED is switched to ON. 

But drag the component away from the 0,0 position and the segments remain in place and when recompiled still changed but not locked inside the rectangle.

This only happens on the Linux based BBB and Raspberry Pi.  The same code and component on a PC has the segments dragging with the rectangle.  Same code in Delphi too. 

So something deep inside the TGraphicControl doesn't work in either the IDE or in the running application. 

More when I figure it out.

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: TControl and TGraphic Control creation issue
« Reply #10 on: April 28, 2021, 08:52:00 am »
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?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: TControl and TGraphic Control creation issue
« Reply #11 on: April 28, 2021, 08:55:32 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.

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).

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: TControl and TGraphic Control creation issue
« Reply #12 on: April 28, 2021, 09:14:46 am »
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.

jcdammeyer

  • Full Member
  • ***
  • Posts: 205
  • Embedded System Developer
    • Automation Artisans Inc.
Re: TControl and TGraphic Control creation issue
« Reply #13 on: May 03, 2021, 06:36:08 pm »
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
   SevenSegDisplayImage.Paint;
crashes.

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?

Thanks
John

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TControl and TGraphic Control creation issue
« Reply #14 on: May 03, 2021, 10:50:54 pm »
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.

 

TinyPortal © 2005-2018