[SOLVED] Chartlistbox return error lazarus / 55-TAChart ---------------------------------------------------------------------- madepabloh · 2014-09-08 22:24 I have a chart in which i add series un runtime. Untul here i do not have problems. However, if i add a chartlistbox and i link it to the chart, everythings to work correctly: it compiles, and works as expected in runtime, but when i close the application it returns an "exception on external: SIGSEGV" in Tagraph.pas line 111 "function TChart.GetSeriesCount: Integer; begin   Result := FSeries.FList.Count; end;  " I have other charts and hcartlistboxes inthe same application using the same procedures, but they do not return error. If i remove the chartlistbox, then, the error disapear... Does anyone had a similar issue? Do you know what could be the error related to? Thanks! ---------------------------------------------------------------------- wp · 2014-09-09 07:50 Running fine here. Could you post a small demo which shows the error? ---------------------------------------------------------------------- madepabloh · 2014-09-09 20:40 This is the code to plot the series from a StringGrid. Code: [Select]procedure TMain.PlotReset; var  f: integer;  cs: TConstantLine; begin    f := 0;    SearchSeries(EngineeryGrid, 3, 'Num', True);    for j:= 4 to EngineeryGrid.RowCount-1 do      begin        if EngineeryGrid.Cells[a,j] = '1' then          begin            f := f + 1;            cs := TConstantLine.Create(ChartEng1);            ChartEng1.addSeries(cs);            cs.Index:= f;            cs.Name := 'Reset' + IntToStr(f);            cs.Title := cs.Name;            cs.Tag := f;            cs.Legend.Format := cs.Title;            cs.LineStyle:= lsVertical;            cs.SeriesColor := clred;            cs.Position:= StrToDateTime(EngineeryGrid.Cells[0, j]);          end;      end; end; procedure TMain.PlotEngineery; var   ls2: Tlineseries;   x: TDateTime;   y: double;   z: integer; begin   DefaultFormatSettings.DecimalSeparator:= '.';   for i := 2 to Engineerygrid.ColCount-1 do      begin        ls2 := Tlineseries.Create(ChartEng1);        ChartEng1.addSeries(ls2);        ls2.Name := EngineeryGrid.Cells[i,3];        ls2.Name := 'S_'+ EngineeryGrid.Cells[i,3];        ls2.Title := EngineeryGrid.Cells[i,3];        ls2.Tag := StrtoInt(EngineeryGrid.Cells[i,1]);        ls2.Legend.Format := EngineeryGrid.Cells[i, 3];        ls2.ShowPoints := false;        ls2.ShowLines := true;        if EngineeryGrid.Cells[i,1] = '3' then ls2.SeriesColor := clLime        else if EngineeryGrid.Cells[i,1] = '4' then ls2.SeriesColor := clFuchsia        else if EngineeryGrid.Cells[i,1] = '5' then ls2.SeriesColor := clAqua        else ls2.SeriesColor := clBlue;        z:= (StrToInt(EngineeryGrid.Cells[i,1]));        if ((z > 2) and (z < 6)) = true then ls2.AxisIndexY := 0        else if (z > 5)= true then ls2.AxisIndexY := 2;        ls2.LinePen.Width := 1;        ls2.Marks.Visible :=  False;        ls2.Marks.Style := smsLabel;        ls2.Marks.OverlapPolicy := opIgnore;        ls2.Pointer.Style := psCircle;        ls2.Pointer.HorizSize := 3;        ls2.Pointer.VertSize := 3;        for j := 4 to EngineeryGrid.RowCount - 1 do           // Row 4 is the first row with data after format the table          begin            if TryStrToFloat(EngineeryGrid.Cells[i, j], y) then              begin                x := StrToDateTime(EngineeryGrid.Cells[0, j]);                ls2.AddXY(x, y);              end;          end;        //Progressbar1.StepIt;        //If Progressbar1.Position = 100 then Progressbar1.position := 0;      end; end;          If i do not plot the series, the problem do not show the error when closing the application. If i plot the series, then the application return the error call when closing it. ---------------------------------------------------------------------- wp · 2014-09-09 21:12 It would be better if you would post a simple demo which I could compile and debug. At first sight your code looks ok. There is one thing, however, which I normally don't do: I do not use the chart as owner of the series, instead I normally use the form for that purpose. It could be that when the program closes the chart and the series are destroyed before the listbox which leaves the listbox with invalid pointers (this certainly is a bug). Try to use the form as argument in the constructor of the series: Code: [Select]cs := TConstantLine.Create(Main);  // "Main" (name of the form?) instead of ChartEng1 ... ls2 := Tlineseries.Create(Main);   // dto. Additionally you could disconnect the ChartListbox from the chart before the form closes, maybe in OnCloseQuery where everything is still alive: Code: [Select]procedure TMain.FormCloseQuery(Sender: TObject; var CanClose: boolean); begin   if CanClose then ChartListbox1.Chart := nil; end; ---------------------------------------------------------------------- madepabloh · 2014-09-09 21:19 You are incredible @WP!!! That was the cause of the error! I made the changes you propose, and now the error when closing the program is not showed!! So, SOLVED! Thanks so much! ---------------------------------------------------------------------- wp · 2014-09-09 21:38 Which one of both ways solved it? Or do you need both? ---------------------------------------------------------------------- madepabloh · 2014-09-09 21:54 sorry, i didn´t explained. I used the first modification you proposed, to call the form, and not the chart when creating the series. Thanks!! ---------------------------------------------------------------------- wp · 2014-09-10 07:33 I looked at the ChartListbox in more detail and found that it does not have a Notification method which cleans up references to other objects being destroyed. Since I cannot reproduce your error I'd ask you to test the attached modified unit: Undo the changes that you made yesterday to fix the issue. Unpack the zip file and temporarily copy the enclosed TAChartListbox.pas into your project file. When you recompile the project this unit will be used in place of the original one.Tell me if the error has disapppeared. ---------------------------------------------------------------------- madepabloh · 2014-09-10 20:48 Sure, no problem... I tried, but not it does not compiles. These are the errors it returns: QuotePPU Loading C:\lazarus\components\tachart\lib\i386- win32\win32\tachartlazaruspkg.ppu PPU Source: tachartlazaruspkg.pas not found Recompiling TAChartLazarusPkg, checksum changed for TAChartListbox Quicklook.lpr(10,52) Fatal: Can not find TAChartLazarusPkg used by Quicklook, ppu=C:\lazarus\components\tachart\lib\i386- win32\win32\tachartlazaruspkg.ppu, package TAChartLazarusPkg i removed the new file from my proyect folder, and it does not compiles anymore... Edited: I reinstalled the lazarus program, compiled again the tachartlazaruspkg package, but it does not work again... How could i solve this? ---------------------------------------------------------------------- madepabloh · 2014-09-10 22:03 Okay, i copied your new file, not into my project folder but into the tachart component folder to substitute the original one. Now the program compiles. I made the changes in the code to have it how it was when i had the error related to the chartlistbox, and now   there is not problem... So your new files solve the problem. Thanks @wp! ---------------------------------------------------------------------- wp · 2014-09-10 22:06 Thanks, and sorry for the difficulties... Then I'll add the modified version to TAChart trunk and ask for backporting to version 1.2.6. ---------------------------------------------------------------------- madepabloh · 2014-09-10 22:26 No, thanks to you. The problem was minor and it only took few minutes to me to locate the solution. It is more important what you did to solve this issue (and many others, i know), and help me to solve my problems with arduino. I really appreciate it. So, feel free to ask for to test other things if you need. I would like to help. Thanks!