Forum > Packages and Libraries

New component - properties are integer instead of single

<< < (3/3)

bobby100:
The loop you resolved came latter. I've moved code around between the procedures because I was thinking that the LCDDisplay is accessing variables from BComponentTheme before variables got initialized, and that's how I probably caused the loop.
Before moving the variables into TPersistent, in most of the cases, the program got bugging at SetFrameStyle in TBComponentTheme. The value to be set was one with the "could not be found in memory" problem. My biggest problem at that moment was, that I didn't even call any Set procedures at all. Call stack didn't help at all here - I couldn't find what was calling my SetFrameStyle.
The code was simply running wild (tested with Lazarus 2.2.6 and 3.4 on Windows 10, installers from sourceforge).

alpine:

--- Quote ---Before moving the variables into TPersistent,
--- End quote ---
I'm a bit confused - in order to put something in a form it must be a TComponent (i.e. TPersistent), which should do the persistency stuff. How did you do it before?

bobby100:
So, before:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TBComponentsTheme = class(TComponent)private  FParameter1: integer;  FParameter2: single;..  procedure SetParameter1(AValue: integer);  procedure SetParameter2(AValue: single); published  property Parameter1: integer read FParameter1 write SetParameter1;  property Parameter2: single read FParameter2 write SetParameter2; etc.and that didn't work well (situation at the beginning of this topic).

Now:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TBComponentsThemeSet = class(TPersistent)public  FParameter1: integer;  FParameter2: single;end; TBComponentTheme = class(TComponent)private  FThemeSet: TBComponentsThemeSet;  function GetParameter1: integer;  function GetParameter2: single;  procedure SetParameter1(AValue: integer);  procedure SetParameter2(AValue: single);published  property Parameter1: integer read GetParameter1 write SetParameter1;  property Parameter2: single read GetParameter2 write SetParameter2;... implementation constructor TBComponentTheme (AOwner: TComponent);begin  inherited Create (AOwner: TComponent);  FThemeSet := TBComponentsThemeSet.Create;end; destructor TBComponentTheme.Destroy;begin  FreeAndNil(FThemeSet);  inherited Destroy;end; procedure TBComponentTheme.SetParameter1(AValue: integer);begin  FThemeSet.FParameter1 := AValue;end; function TBComponentTheme.GetParameter1: integer;begin  Result := FThemeSet.FParameter1;end; This is how it is now, and it works.

Code is cropped to just the necessary to show the basic idea.

alpine:
Still not clear for me. The actual difference is that you have added property accessors GetParameterX into the TBComponentTheme. IMO the TBComponentsThemeSet not relevant at all, even less it's predecessor TPersistent.

Have you tried just to replace read FParameterX (private field) with read GetParameterX (accessor) wich simply returns FParameterX? Without using the TBComponentsThemeSet.

bobby100:
Didn't try with getter-functions before I moved the variables into a separate class, e.g. until it really went necessary.
What I did try, but without anything being better, was to move the variables between the sections (private, protected, public).
I've also tried direct set access in Properties
--- Code: ---  property ParameterX read FParameterX write FParameterX;
--- End code ---
, but that didn't bring any good.

Navigation

[0] Message Index

[*] Previous page

Go to full version