Recent

Author Topic: setting properties at runtime  (Read 9905 times)

frederic

  • Full Member
  • ***
  • Posts: 226
setting properties at runtime
« on: December 21, 2014, 04:28:16 pm »
my first post here.
i have problems with changing some of the properties of TAcharts
most are clear numbers(integers or double) ,some are clear strings but there are quite a few where it isn't clear with what method you can change the property. is there a general approach for ?

an example :
i want to make a general procedure to draw a vertical line at a given x-axis value. I use the constantlineseries which i want to create during runtime.The standard linestyle is "Ishorizontal" so I will have to change that property to 'ISvertical"

Code: [Select]
procedure  Tanalysefrm.AddverticallineSeries(axaxesnr:integer);
var
series: TconstantLine;
begin

 series := TconstantLine.Create(self);

 with series do
       begin
          linestyle:=IsVertical;//<------------error
      end;
 //series.linestyle:= [IsVertical];    //<----------------error?
 series.position:=axaxesnr;
 series.SeriesColor := clblack;
  chart1.addseries(series);

 end;     

error: no identifier "Isvertical" found

looking in unit TAseries  under constantline then and saw that Isvertical is of type Tlinestyle :
Code: [Select]
procedure TConstantLine.SetLineStyle(AValue: TLineStyle);
begin
  if FLineStyle = AValue then exit;
  FLineStyle := AValue;
  UpdateParentChart;
end;
and i changed the code as follows:

Code: [Select]
procedure  Tanalysefrm.AddverticallineSeries(axaxesnr:integer);
var
series: TconstantLine;
Isvertical:Tlinestyle;
begin

 series := TconstantLine.Create(self);  //
 series.linestyle:= IsVertical;
 series.position:=axaxesnr;
 series.SeriesColor := clblack;
 chart1.addseries(series);
 end;           

result : no error anymore but also no vertical lines when i give the xaxasnr a value

so what is wrong here?

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: setting properties at runtime
« Reply #1 on: December 21, 2014, 06:36:06 pm »
Your code looks reasonable. I quickly tried your code and it is working fine here (Win, Laz trunk).

Please post the exact error message. Is the error occuring during compilation or at runtime? What is your environment (operating system, Lazarus version)?

Please prepare a little demo which shows the error? The problem is often not in the code snipped which is posted. (For the demo, post only *.pas, *.lfm, *.lpi and *.lpr files packed into a single zip which you can upload to the forum).


User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: setting properties at runtime
« Reply #2 on: December 21, 2014, 07:46:21 pm »
You're missing something from uses-list. Try placing 1 TAChart component on form and it might add something automatically.

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: setting properties at runtime
« Reply #3 on: December 21, 2014, 08:05:47 pm »
Code: [Select]
You're missing something from uses-lisThat's what I was thinking at first. But then the error would be in the line where the series is created because TConstantLine and lsVertical are in the same unit (TASeries).

frederic

  • Full Member
  • ***
  • Posts: 226
Re: setting properties at runtime
« Reply #4 on: December 21, 2014, 10:45:45 pm »
wp

i have prepared a small demo (see attachment)
 the sameresult is as i said
- succesfully compiled
- but no vertical lines in chart


wp

  • Hero Member
  • *****
  • Posts: 11830
Re: setting properties at runtime
« Reply #5 on: December 21, 2014, 11:21:48 pm »
No compilable project, unit1 missing.

BTW, the variable IsVertical in your last example is not initialized.
« Last Edit: December 21, 2014, 11:33:59 pm by wp »

frederic

  • Full Member
  • ***
  • Posts: 226
Re: setting properties at runtime
« Reply #6 on: December 22, 2014, 11:23:18 am »
oh,I am sorry

here again the demo project( i have problems zipping the total project therefore unit1 and the project lps and res)

to be complete:
after succesfull compilation following message was produced:
– unit1.pas(72,38) warning Constructing a class”Tconstantline”with abstract method “IsEmpty”
– Tagrafph.pas (82,14) hint : found abstract method:Tbasicchartseries.IsEmpty(<TbasicChartseries>):boolean;
– unit1.pas(73,31) warning : local variable “Isvertical”does not seem to be initialized

   project succesfully built

when we run the project and change the value in the editbox nothing happens


i am using lazarus v 1.2.6

arneolav

  • Full Member
  • ***
  • Posts: 195
    • ElTranslador
Re: setting properties at runtime
« Reply #7 on: December 22, 2014, 03:15:43 pm »
I had a simular problem :
     Chart1LineSeries1.Pointer.Style := psCircle;   ---> Solved by  Uses ... TAtypes
Win XP, Win7, Win 10, Win 11, win64 , Lazarus 3.0RC1
Delphi/DevExpress

frederic

  • Full Member
  • ***
  • Posts: 226
Re: setting properties at runtime
« Reply #8 on: December 22, 2014, 03:47:34 pm »
thanks for your reaction,

I added tatypes to my demo but result is the same
I checked if i had used "tatypes "in my  bigger application where this problem arised and there was TAtypes declared in the use direct after the "implemention" statement.

so the cause must be  different

frederic

arneolav

  • Full Member
  • ***
  • Posts: 195
    • ElTranslador
Re: setting properties at runtime
« Reply #9 on: December 22, 2014, 05:12:24 pm »
Well, I cant get your downloads, and the .zip file has no *.pas.
...
I solved other problems with: TAChartUtils.
...
As a roule I allways keep "system Uses" in the upper part, just after the interface.
And my "private Uses" after implementation (If I don't need them before).

Win XP, Win7, Win 10, Win 11, win64 , Lazarus 3.0RC1
Delphi/DevExpress

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: setting properties at runtime
« Reply #10 on: December 22, 2014, 06:17:27 pm »
The posted program works fine here (Win7, Laz-trunk/FPC2.6.4, or Laz1.2.6/FPC2.6.4) after initializing the variable "IsVertical" (as noted above)

Code: [Select]
procedure  TForm1.AddverticallineSeries(axaxesnr:integer);
var
series: TconstantLine;
Isvertical:Tlinestyle;
begin

  IsVertical := lsVertical;         // <---- is missing
 series := TconstantLine.Create(self);  //
 series.linestyle:= IsVertical;
 series.position:=axaxesnr;
 series.SeriesColor := clred;
 chart1.addseries(series);
 end;

But the direct assignment (series.linestyle := lsVertical) is working also.

You did not post the lpi file (I did tell you to post pas, lfm, lpi and lpr files...), therefore I can't tell if the TAChart package is properly added, but I think so because this happens automatically when you click a TChart into the form.

I attach an adapted version of your program which is complete - no changes, just making sure that the package is included and some cosmetic changes in indentation (I can't read unindented source code...). Unzip the contents to some folder, compile and run. It definitely works!

If the program will not work properly my explanation would be you could have a corrupted Lazarus and/or TAChart installation or user profile.

Maybe the first thing to do would be to recompile the TAChart package: Select "Package" / "Open package (.lpk)", navigate to "(lazarus-folder)\components\tachart" and select the file "tachartlazarus.pkg". Compile.

If this does not help recompile Lazarus: Select "Tools" / "Build Lazarus with profile...". This takes some time, at the end Lazarus will be restarted in the newly compiled version.

If this does not help either reset your user profile: In the Windows explorer (I assume you use Windows - you did not answer my question regarding the operating system...) navigate to c:\users\<your name>\AppData\Local\. Seek the folder "Lazarus". Rename it and run Lazarus again. This resets all user settings to their default values. If this solves your issue you have to reinstall all your components.

If not the final option is to reinstall Lazarus. Delete the old installation folder. Download the current version and install.

If this does not help I have no more idea...

frederic

  • Full Member
  • ***
  • Posts: 226
Re: setting properties at runtime
« Reply #11 on: December 22, 2014, 11:33:07 pm »
arneolav, thank you  TaUtils was also in the uses list

wp ; thank you  .it looks you solved the problem; it works !!  .......by initializing ISvertical   

but is this the way to tackle the type problem?

 
ps. the download appeared to be a problem ; in the backup file i can see the files you mentioned.  Would that have been of help?

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: setting properties at runtime
« Reply #12 on: December 23, 2014, 12:45:49 am »
Is fine that it works. But I still don't understand what was wrong in your first posting.

Quote
the download appeared to be a problem
The download of the file that I posted? What was the problem?

frederic

  • Full Member
  • ***
  • Posts: 226
Re: setting properties at runtime
« Reply #13 on: December 23, 2014, 10:43:54 am »
wp
i meant problems with my own download to the forum; this has more to do with my inexperience with zipping these projects . The application part of the project appeared to be to big (appr 28000kb).Is there a description how to prepare for zipping projects in order to reduce the size?

But there is a strange thing.I ran the code i received from you and it worked. Then i compared the code text which i uploaded to the forum and this is the same but did not work ???
.

i use lazarus v 1.2.6  on windows vista

frederic

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: setting properties at runtime
« Reply #14 on: December 23, 2014, 11:35:45 am »
Quote
Then i compared the code text which i uploaded to the forum and this is the same but did not work ???
Maybe there is a difference in the lpi file which you did not upload. Whatever the reason here are step-by-step instructions how to create a valid charting project:
  • "New" / "Project" / "Application"
  • Component palette "Chart", click a TChart component onto the new form.
  • In your example, you create the constant line series by code. The corresponding series type TConstantLine is found in unit TASeries. Also, the identifier "lsVertical" is declared in this unit. You have to add TASeries to the uses clause of the form. Otherwise the compiler would complain about "unknown identifier".
  • If you would not know where TConstantLine is you can try this trick: double-click on the chart in the form to open the series editor. Select "Constant line" to add a TConstantLineSeries. Then delete it again. This removes the series, but leaves all the units required by the TConstantLine in the form's "uses". Please be aware that some identifiers can be accessed at run-time which are not needed explicitly at design-time. In this case the unit TAChartUtils is a good candidate to find them in - I'd say - 90% of all cases.
  • Then proceed with your own code of the example.
  • It should work.
Quote
my inexperience with zipping these project
In the explorer select the *.pas, *.lfm, *.lpi and *.lpr files (left-click with the CTRL key held down), then you right-click on one of them and select "Send to" / "zip compressed folder" (or similar) from the explorer context menu. Or use a third-party zipper, like 7-zip, which gives you better control of the zipping process.

The files *.pas, *.lfm, *.lpi, *.lpr are the least files required to build (simple) projects, all the other files are recreated and do not have to be uploaded.

 

TinyPortal © 2005-2018