So now getting back to my own components.I assume that you do this for practicing. Then it's ok. But if not, you should not re-invent the wheel. There are several ready-made gauge components somewhere in the internet, also for Lazarus, e.g. the one in the Industrial package which you can install via Online-Package-Manager.
This simple thing, is a ownerdrawn TPanel, to use as a gauge - that can also function as a setter.
(attached mygauge.zip)
I would also like to remove the Caption (set it empty).I think this is not done easily because - to my knowledge - the default Caption text is inserted by the property editor. So you must write your own property editor for this component which prevents its ancestor from doing so (http://wiki.lazarus.freepascal.org/How_To_Write_Lazarus_Component#Property_editors). Maybe it is easy here, but in general writing property editors is really advanced work with lots of trouble in debugging because the property editor is installed into the IDE, so, you must debug the IDE! Another reason for not inheriting from TPanel.
I have tried settng them in Create, but that doesn't work.
So how is the right way to do that?
I am also a bit puzzeled - propeties have read, write and default sections.The default section is only important for the streaming process. It tells the reader/writer to not read/write a property value if the current value is equal to the default value - this way the size of the lfm file and the activity running when the component is read from the lfm is reduced. Another reason for adding a default value is when a new property is added to the component then you can keep the component usable in older versions of your package, at least unless the new property keeps its default value - because the property does not appear in the lfm.
But the default seem to never be used?
In the attached there is a default value of 20 for position - but position is alwas 0 as default, when the component is placed in IDE.Declaring a property with a default value says only that the property is not to be streamed when the property has the value specified after the "default", in the followin fragment 20:
So how does one change default values - and what does the default for a property actually do?
There is an OnChanged event in the component.Although your component seems to work fine for me (I did not do thorough testing though), I could imagine that this can happen. Because when the lfm is read the properties are set to the values found in the lfm, and it may happen that the events associated with the setters are fired. Of course, it is possible that the other controls are not yet created when this occurs. A remedy is that you insert an "if (csLoading in ComponentState) then exit" into the Change procedure such that the event is not fired. For example:
And I'm getting odd errors with that...
Labels (on the form!) do not exist (=nil) and variables and properties in gauge are not set (access violations).
It seems the event is actually raised and attempted handled during creation of the gauge - and even before the other components on the form are created.
How does one avoid that?
(Inconsistensy between doc - http://wiki.freepascal.org/Canvas_line (http://wiki.freepascal.org/Canvas_line) and real life.You have to remember that pixels are numbered starting at zero. So a control of Width 20 is 20 pixels wide, and the pixels are numbered from 0 to 19.
A line from (Width, 0) to (Width, Height) is drawn outside visible area as is on from (0, Height) to (Width,Height)
they need to be (Width-1, 0) to (Width-1, Height-1) and (0, Height-1) to (Width-1,Height-1) respectively.)