Lazarus
Programming => Packages and Libraries => LazReport => Topic started by: Fai on July 29, 2015, 06:47:50 am
-
I'm trying to add memo fields from code & found examples from here (http://www.filewatcher.com/p/lazarus-0.9.28.2-src.tar.bz2.12933724/lazarus/components/lazreport/source/lr_pgrid.pas.html) & here (https://www.fast-report.com/documentation/ProgMan/index.html?creating_a_report_form_from_code.htm).
This is my code :
...
var
v: TfrView;
Page: TfrPage;
begin
...
if not ZQuery1.EOF then begin
frDBDataSet1.DataSet:=ZQuery1;
frReport1.Dataset:=frDBDataSet1;
frReport1.LoadFromFile('report1.lrf');
if frReport1.Pages.Count = 0 then frReport1.Pages.Add;
Page := frReport1.Pages[0];
v:= frCreateObject(gtMemo, '');
v.SetBounds(100,140,100,18);
v.Memo.Add('[ZQuery1.value1]');
Page.Objects.Add(v);
frReport1.ShowReport;
end
...
But I got error on
v:= frCreateObject(gtMemo, '');
it says : Wrong number of parameters specified for call to "frCreateObject"
Am I missing something..?
-
Either read the documentation of frCreateObject or dig in its source yourself (if you have access to). Does it really accept 2 parameters?
-
Does it really accept 2 parameters?
Yes, it should be 3.
v:= frCreateObject(gtMemo, '', Page);
Now the project compiled, can load the report, and added new memo successully. But when I close the report it throws exception : raised exception class 'External:SIGSEGV' at address BAADF00D.
What does it mean?
-
But when I close the report it throws exception : raised exception class 'External:SIGSEGV' at address BAADF00D.
The address looks familiar and indeed it is something known (https://en.wikipedia.org/wiki/Magic_number_(programming)). It's not really an address, though. Just a code for a bad thing, which is an uninitialized memory area access (well, SIGSEGV in general is always caused by this). So find out which property, variable or whatever the report closing code is trying to access that you haven't initialized.
-
I step into code in assembler debug window and it opens LR_class and goes to
procedure TfrPage.Clear;
.
It seems the Page that I didn't create initially, how to create it? I try Page:=TfrPage.Create(nil)
but still error
-
I step into code in assembler debug window and it opens LR_class and goes to procedure TfrPage.Clear;
.
It seems the Page that I didn't create initially, how to create it? I try Page:=TfrPage.Create(nil)
but still error
Get as deep as possible stacktrace (use the call stack window), then look one by one which page object whose clear method it tries to call.
-
...which page object whose clear method it tries to call
I attach the call stack window. I know there's something not right on TrfPage initialization. Still have no idea why & how to resolve it
-
I've the same problem...
procedure TfrPage.Clear;
I can't see where is the problem... My sqlite3 projects are sleeping :-[
Are there recent changes?
-
I attach the call stack window. I know there's something not right on TrfPage initialization. Still have no idea why & how to resolve it
I've found some errors in my code, referred to 'range check', it was corrected and work ok.
loop: Can you try this? (Sqlite3 database, modify it as you need...) The code works. If it fails, you have a problem with FreeReports template file or in the database, or some parameter...
procedure TfrmLibrosListadosPorMateria.ButtonRangoSingleClick(Sender: TObject);
var
sQuery: string;
sTableName, sDatabaseFilePath : string;
Sqlite3DatasetA: TSqlite3Dataset;
frDBDataSetA: TfrDBDataSet;
frReportA: TfrReport;
frViewA: TfrView;
frPageA: TfrPage;
begin
sDatabaseFilePath := ; { here Your Database FilePath }
sTableName := 'libros';
Sqlite3DatasetA := TSqlite3Dataset.Create(Self);
frDBDataSetA := TfrDBDataSet.Create(Self);
frReportA := TfrReport.Create(Self);
frReportA.ReportType := rtSimple;
frReportA.ModifyPrepared := False;
Sqlite3DatasetA.FileName := sDatabaseFilePath;
Sqlite3DatasetA.TableName := sTableName;
Sqlite3DatasetA.PrimaryKey := 'id';
sQuery := 'SELECT * FROM ' + sTableName ' WHERE activo=1 AND id_materia=' + QuotedStr(IntToStr(SpinEdit1.Value));
Sqlite3DatasetA.SQL := sQuery;
Sqlite3DatasetA.ExecSQL;
Sqlite3DatasetA.Open;
if Sqlite3DatasetA.RecordCount < 1 then begin
ShowMessage('No records found for "materia" specified...');
end else begin
frReportA.ShowProgress := False;
frDBDataSetA.DataSet := Sqlite3DatasetA;
frReportA.Dataset := frDBDataSetA;
frReportA.loadFromFile(Application.Location + '\reports\libros_por_materia.lrf'); // here myReport.lrf
frPageA := frReportA.Pages[0];
frViewA := frCreateObject(gtMemo, '', frPageA); // create data field
frViewA.SetBounds(900, 25, 100, 80); // Position Right-Up
frViewA.Memo.Add('( ' + IntToStr(SpinEdit1.Value) + ' )');
TfrMemoView(frViewA).Font.Size := 14;
TfrMemoView(frViewA).Font.Bold := True;
TfrMemoView(frViewA).Alignment := taRightJustify;
frPageA.Objects.Add(frViewA);
if not frReportA.PrepareReport then ShowMessage('Not prepared');
Application.ProcessMessages;
frReportA.ShowReport;
Application.ProcessMessages;
FreeAndNil(frViewA);
end;
//----------------------------------- clear memory
frDBDataSetA.Close;
Sqlite3DatasetA.Close;
FreeAndNil(frReportA);
FreeAndNil(frDBDataSetA);
FreeAndNil(Sqlite3DatasetA);
//----------------------------------- clear memory
end;