I've been having some problems with a program I'm writing (using the latest svn of lazarus), the program has several forms and when i start the program in windows i get a division by 0 error.
I've tracked it down to the unit I wrote called AutoGraph.pas (removing references to it stop any problems from occuring), its quite a simple form with just two buttons on it, and a TChart component.
In linux there I can run the program fine, however sometimes when I close the program I get a SIGFPE error which I dont understand. any help is appreciated. Thanks
Heres the code for the autograph unit (sorry its long):
//##############################################################################
//------------------------------------------------------------------------------
// AUTOGRAPH
//
// Automatically runs through values of what you
// you request for the variable you request and
// plots it for you with the legend data you
// request, how nice! ;)
//------------------------------------------------------------------------------
//##############################################################################
unit AutoGraph;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons,
ExtCtrls, LResources, Menus, ComCtrls, ExtDlgs,TAGraph,TASeries, TAEngine;
type
{ TForm5 }
TForm5 = class(TForm)
ClearBtn: TBitBtn;
Bottom_Panel: TPanel;
BackBtn: TButton;
Chart2: TChart;
// AUTOGRAPH FUNCTIONS
procedure AutoGraphGoGoGo(Chart:TChart);
procedure ClearBtnClick(Sender: TObject);
procedure BackBtnClick(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form5:TForm5;
g: TSerie;
implementation
uses mainpage,functions, UserFriendly;
procedure TForm5.AutoGraphGoGoGo(Chart:TChart);
var
a,b,Increase:real;
t:integer;
units:string;
begin
if ClearGraph=true then Chart.series.clear; // Clears if wanted
if AllowZoom=false then Chart.AllowZoom:=false // Clears if wanted
else Chart.AllowZoom:=true;
g:= TSerie.Create(Chart);
Chart.AddSerie(g);
g.SeriesColor := UserFriendly.Form6.ColorBox1.Selected;
g.ShowLines := true;
g.ShowPoints := true;
Chart.AxisVisible:=true;
Chart.BottomAxis.Visible:=true;
Chart.LeftAxis.Visible:=true;
//Chart.SaveToBitmapFile(filename) ;
// Pointer settings
g.Pointer.Visible:=true;
if psType='Diagonal Cross' then g.Pointer.Style:=psDiagCross
else if psType='Cross' then g.Pointer.Style:=psCross
else if psType='Circle' then g.Pointer.Style:=psCircle
else if psType='Star' then g.Pointer.Style:=psStar
else if psType='Rectangle' then g.Pointer.Style:=psRectangle
else g.Pointer.Visible:=false;
// Auto change colour
if UserFriendly.Form6.ColorBox1.ItemIndex=13 then UserFriendly.Form6.ColorBox1.ItemIndex:=0
else UserFriendly.Form6.ColorBox1.ItemIndex:=UserFriendly.Form6.ColorBox1.ItemIndex+1;
// Sets up graphs as booleans see fit
if InvertedX=true then Chart.LeftAxis.Inverted := InvertedX
else Chart.LeftAxis.Inverted := FALSE;
if InvertedY=true then Chart.BottomAxis.Inverted := InvertedY
else Chart.BottomAxis.Inverted := FALSE;
// Use requested item as legend data
if UserFriendly.Form6.LegendCombo.Text='Refractive Indexs' then g.Title:='N1: '+UserFriendly.Form6.N1_Edit.text + ' N2: ' +UserFriendly.Form6.N2_Edit.text
else if UserFriendly.Form6.LegendCombo.Text='Refractive Index N1' then g.Title:=UserFriendly.Form6.N1_Edit.text
else if UserFriendly.Form6.LegendCombo.Text='Refractive Index N2' then g.Title:=UserFriendly.Form6.N2_Edit.text
else if UserFriendly.Form6.LegendCombo.Text='Fibre Type' then g.Title:=UserFriendly.Form6.FT_Combo.text
else if UserFriendly.Form6.LegendCombo.Text='Length' then g.Title:=UserFriendly.Form6.Length_Edit.text
else if UserFriendly.Form6.LegendCombo.Text='Peak Wavelength' then g.Title:=UserFriendly.Form6.PeakWL_Edit.text
else if UserFriendly.Form6.LegendCombo.Text='Pulse Width' then g.Title:=UserFriendly.Form6.PW_Edit.text
else if UserFriendly.Form6.LegendCombo.Text='Power Input' then g.Title:=UserFriendly.Form6.PI_Edit.text
else if UserFriendly.Form6.LegendCombo.Text='Spectral Width' then g.Title:=UserFriendly.Form6.SW_Edit.text
else if UserFriendly.Form6.LegendCombo.Text='Spectral Source' then g.Title:=UserFriendly.Form6.SS_Combo.text
else if UserFriendly.Form6.LegendCombo.Text='Y-Axis Info' then g.Title:='N1: '+UserFriendly.Form6.AGYA.text
else if UserFriendly.Form6.LegendCombo.Text='Peak Wavelength' then g.Title:=UserFriendly.Form6.PeakWL_Edit.text;
Chart.Foot.Text.Text:=UserFriendly.Form6.AGXA.Text;
Chart.Foot.Visible:=true;
Chart.Title.Text.Text:=UserFriendly.Form6.AGYA.Text+' against '+ UserFriendly.Form6.AGXA.Text ;
if UserFriendly.Form6.AGXA.Text='Length' then units:='m'
else if UserFriendly.Form6.AGXA.Text='WaveLength' then units:='m'
else units:='m';
b:=StringToNumber(UserFriendly.Form6.SV_edit.text,units);
Increase:=(StringToNumber(UserFriendly.Form6.EV_edit.text,units)-b)/ UserFriendly.Form6.AGP.Value;
if UserFriendly.Form6.AGXA.Text='Length' then
begin
if UserFriendly.Form6.AGYA.Text='Total Attenuation' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('TA', 'L', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Bandwidth' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('BW', 'L', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Attenuation(km-1)' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('ATT', 'L', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Power Output' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('PO', 'L', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Intramodal Dispersion' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('MD', 'L', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Intermodal Dispersion' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('DTS', 'L', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Total Dispersion' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('FPW', 'L', b);
g.AddXY(b, a, '', clTAColor);
end;
end;
end
else if UserFriendly.Form6.AGXA.Text='WaveLength' then
begin
if UserFriendly.Form6.AGYA.Text='Total Attenuation' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('TA', 'WL', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Bandwidth' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('BW', 'WL', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Attenuation(km-1)' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('ATT', 'WL', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Power Output' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('PO', 'WL', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Intramodal Dispersion' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('MD', 'WL', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Intermodal Dispersion' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('DTS', 'WL', b);
g.AddXY(b, a, '', clTAColor);
end;
end
else if UserFriendly.Form6.AGYA.Text='Total Dispersion' then
begin
for t:=0 to UserFriendly.Form6.AGP.Value do
begin
b:=b+Increase;
a:=mainpage.Form1.Recalculate('FPW', 'L', b);
g.AddXY(b, a, '', clTAColor);
end;
end;
end;
if copyclipboard=true then Chart.CopyToClipboardBitmap; // Doesnt seem to help, puts a black pic in clipboard
//Chart.SaveToBitmapFile('/home/mat/testy.bmp') // maybe in win?
end;
procedure TForm5.ClearBtnClick(Sender: TObject);
begin
Chart2.series.clear;
UserFriendly.Form6.ColorBox1.ItemIndex:=0;
Chart2.update;
end;
procedure TForm5.BackBtnClick(Sender: TObject);
begin
mainpage.Form1.PageControl.ActivePageIndex:=0;
end;
initialization
{$I autograph.lrs}
end.
I use the following code to create and show the form
AutoGraph.Form5:=TForm5.Create(nil);
AutoGraph.Form5.Parent:=Start_Page;
AutoGraph.Form5.Show;
AutoGraph.Form5.Align:=alClient;
I've tried swapping this for:
Application.CreateForm (TForm5 , Form5 );
in the main .lpi file, but this didn't help either
[/code]