Recent

Author Topic: Adding memo from code  (Read 4997 times)

Fai

  • New Member
  • *
  • Posts: 24
Adding memo from code
« on: July 29, 2015, 06:47:50 am »
I'm trying to add memo fields from code & found examples from here & here.
This is my code :
Code: [Select]
...
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
Code: [Select]
v:= frCreateObject(gtMemo, '');it says : Wrong number of parameters specified for call to "frCreateObject"
Am I missing something..?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8111
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Adding memo from code
« Reply #1 on: July 29, 2015, 09:25:15 am »
Either read the documentation of frCreateObject or dig in its source yourself (if you have access to). Does it really accept 2 parameters?

Fai

  • New Member
  • *
  • Posts: 24
Re: Adding memo from code
« Reply #2 on: July 29, 2015, 11:49:46 am »
Quote
Does it really accept 2 parameters?
Yes, it should be 3.
Code: [Select]
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?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8111
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Adding memo from code
« Reply #3 on: July 29, 2015, 12:48:36 pm »
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. 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.
« Last Edit: July 29, 2015, 07:49:40 pm by Leledumbo »

Fai

  • New Member
  • *
  • Posts: 24
Re: Adding memo from code
« Reply #4 on: July 29, 2015, 01:49:52 pm »
I step into code in assembler debug window and it opens LR_class and goes to
Code: [Select]
procedure TfrPage.Clear;.
It seems the Page that I didn't create initially, how to create it? I try
Code: [Select]
Page:=TfrPage.Create(nil) but still error

Leledumbo

  • Hero Member
  • *****
  • Posts: 8111
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Adding memo from code
« Reply #5 on: July 29, 2015, 07:51:44 pm »
I step into code in assembler debug window and it opens LR_class and goes to
Code: [Select]
procedure TfrPage.Clear;.
It seems the Page that I didn't create initially, how to create it? I try
Code: [Select]
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.

Fai

  • New Member
  • *
  • Posts: 24
Re: Adding memo from code
« Reply #6 on: July 31, 2015, 05:23:16 am »
Quote
...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

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Re: Adding memo from code
« Reply #7 on: August 23, 2015, 11:08:28 pm »
I've the same problem...

Code: [Select]
procedure TfrPage.Clear;

I can't see where is the problem... My sqlite3 projects are sleeping :-[

Are there recent changes?

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Re: Adding memo from code
« Reply #8 on: August 25, 2015, 07:21:02 am »
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...

Code: [Select]
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;   

« Last Edit: August 25, 2015, 07:23:04 am by u2o »