Accessing DataBase Fields

Hello,

can somebody tell me if there is a way to access and modify the contents of a Data Base field prior to building the final report?

I am programming a simple reporting system that needs to analyze and process some of the info from the DB and then output a report. The problem is
that I cannot find the correct set of instructions to get my hands on the data and modify it. We are looking at the following Delphi code:
procedure TForm1.buildReport(Sender: TObject);

var
  frxReport1: TfrxReport;
  frxDBDataset1: TfrxDBDataset;
  DevicePic, SymbolPic: TfrxPictureView;
  TitleEntry, xmlField: TfrxMemoView;
  MasterDataBand: TfrxMasterData;
  xmlText :  WideString;

begin

   ... load report template from file..

   ... attach dataSet to the masterdata band of the report.

   ... Initialize all TfrxView objects ... 

  // Get a handle to the TfrxMemoView object called xmlField

  xmlField := frxReport1.FindObject('xmlField') as TfrxMemoView;
  // stretch the field if text too big.
  xmlField.StretchMode := TfrxStretchMode.smActualHeight;
  //get the XML DATA FROM THE DB.
  xmlField.DataSet := frxDBDataset1;
  xmlField.DataField := 'LibFXML';
  frxDBDataset1.DataSet.FieldByName('LibFXML')
  
 ----And now Here is the part that I am having difficulties with:----
 // I want to access the contents of the DB before geberating the report. For that purpose I tried many alternatives:
 
  xmlText := xmlField.Text; // obviously does not return anything since the Text Property of xmlField has not yet been set
---or maybe something like this---
  xmlField.GetData;
  xmlText := xmlField.Text; //still does not work! I get an "access violation error"
---or maybe sth like this---
  xmlText :=frxDBDataset1.Value[xmlField.DataField]; // again, I get the "Access Violation error".
 
...


 // build and display report
  frxReport1.PrepareReport();
  frxReport1.ShowPreparedReport;

I can get around that problem with direct Data Base access (SQL Select and so on) but I do not think it is the most elegant way, so I would definitely appreciate any piece of advice or illustration on how to make this thing work.

Thank you, in advance, for your time.

Regards,

Petar

Comments

  • edited 1:50AM
    peleus wrote: »
    Hi Kenny, it's been few days already since you last posted this. Any updates so far?

    Hi, Peleus. And a happy new year to you!

    No, I havent got any updates on the subject. I've actually encountered a series of other problems with the FastReports tool. The most persistent one of which is the "Class TfrxReport not found" error I get every time I try to generate a meaningful report. I will tackle those issues for the time being and when (actually IF) I overcome those I will sit down and think on the data access problem. If I get any updates on the topic, I will gladly post them.
  • gpigpi
    edited 1:50AM
    wrote:
    The most persistent one of which is the "Class TfrxReport not found" error I get every time I try to generate a meaningful report
    Attach small test project with problem based on standart Delphi's components
    wrote:
    I can get around that problem with direct Data Base access (SQL Select and so on) but I do not think it is the most elegant way, so I would definitely appreciate any piece of advice or illustration on how to make this thing work.
    I think Data Base access is a best way, but you also can use TfrxReport.Calc('<frxDBDataset1."LibFXML">')
  • edited 1:50AM
    Have you tried such a solution:
    var 
        MyString:      String;                                                                                        
        MyWide:        TWideStrings;
        frxDBDataset1: TfrxDBDataset;         
    
    begin
       MyString := frxDBDataset1.DataSet.FieldByName('libFXML').AsString;
       MyWide   := frxDBDataset1.DataSet.FieldByName('libFXML').AsVariant;
    end.
    
    Regards
    Mick
  • edited 1:50AM
    I DO agree with gpi that Dataset is the best way to manipulate around data, and that's why I use TfrxADOQuery everywhere where SQL Database engine can do some work for me [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Regards Mick[/img]
  • BinBin
    edited 1:50AM
    I must've came late but no worries.

    In regard to your problem, the one with (class not found) I encountered this issue today and already knew what is the problem.

    Go to Options - Library - Library path and browse the little button over there.

    you'll see a box full of paths that the compiler uses to locate components files.

    at the end, there is an Edit box filled with a path. Delete the path you see and add the following:

    C:\Program Files (x86)\FastReports\LibD16 << this is the library path for fast report. The path might differ from the one I have so please keep an eye on that.

    LibD16 means that the library is compatible with Delphi XE2 because the numeric version of it is 16. Depending on your compiler. Choose the correct LibDXX.

    Here is the list of Delphi numeric versions:

    http://delphi.wikia.com/wiki/Delphi_Release_Dates

    Take care and hope you master fastreport.
  • edited February 2013
    Bin wrote: »
    I must've came late but no worries.

    In regard to your problem, the one with (class not found) I encountered this issue today and already knew what is the problem.

    Go to Options - Library - Library path and browse the little button over there.

    you'll see a box full of paths that the compiler uses to locate components files.

    at the end, there is an Edit box filled with a path. Delete the path you see and add the following:

    C:\Program Files (x86)\FastReports\LibD16 << this is the library path for fast report. The path might differ from the one I have so please keep an eye on that.

    LibD16 means that the library is compatible with Delphi XE2 because the numeric version of it is 16. Depending on your compiler. Choose the correct LibDXX.

    Here is the list of Delphi numeric versions:

    http://delphi.wikia.com/wiki/Delphi_Release_Dates

    Take care and hope you master fastreport.

    Hello there, Bin. Thank you for the support. Unfortunately your suggestion did not work. I think that the problem HAS to be in the way the linker links the different units.
    Here is the current situation:

    "Class TfrxReport not found" is being thrown when I include to my Report-generating project additional Units whose source code does not reside in the same directory as my the source code of my Report-Generating project.

    To be more clear, assume that my report-generating project, together with its main form "Unit_ReportingToolMForm", is stored in:

    c:\delphi_projects\Reporting_Tool\

    folder.

    Assume I have a Unit, which I have written long time ago, that parses xmll, and that I want to reuse this functionality without duplicating code. Now assume that this piece of old source code, let us call it "Unit_XMLParser.pas" , lies in a shared_libraries folder on my c drive:

    C:\shared_libraries\Unit_XMLParser.pas

    where I store all my helper files. Besides that, assume "Unit_XMLParser.pas" uses other units from the same shared_libraries directory and is being used by other projects, so moving or copying it into c:\delphi_projects\Reporting_Tool\ would not solve the problem.

    So, I add the Unit_XMLParser in the project source code like this:

    uses
    ...
    Unit_XMLParser in 'Unit_XMLParser.pas',
    ...

    and I add the "C:\Shared_Libraries\" folder to the search path via: Project->Options->Compiler-> Search Path.

    lastly I add the "Unit_XMLParser" in the uses clause of my Unit_ReportingToolMForm.

    Then I compile, Build and run the program, when I wish to generate a report by clicking on a Build Report button on my main form I get "TfrxReport class not found" over and over again.

    As you suggested, I checked the options-> library -> Library Path settings and I confirmed that the path to Fast Reports is correctly set.

    C:\Program Files\FastReports\FastReport 4\LibD16
    .

    The funny thing is that I generate the Report without any problems when I remove the additional Unit_XMLParser unit from my project and use only my main unit and other units that reside in the same directory 'c:\delphi_projects\Reporting_Tool\ ' and do not reference or reuse any of my "shared_library" units.

    My interpretation of the situation is that when the linker goes to shared_libraries to fetch the necessary piece of code in order to assemble the executable, it "forgets" to link up the FastReport dcu's properly to the project. Or something like this. Unfortunately, my internal understanding on the workings of the Delphi16 compiler and the FastReports source code is not high enough for now to decipher why exactly this error occurs. I would really appreciate if any of you could give me a tip or two on the topic. Thank you very much, in advance, for taking your time reading this loooong post and trying to help.

    All the best.
  • edited 1:50AM
    Mick.pl wrote: »
    Have you tried such a solution:
    var 
        MyString:      String;                                                                                        
        MyWide:        TWideStrings;
        frxDBDataset1: TfrxDBDataset;         
    
    begin
       MyString := frxDBDataset1.DataSet.FieldByName('libFXML').AsString;
       MyWide   := frxDBDataset1.DataSet.FieldByName('libFXML').AsVariant;
    end.
    
    Regards
    Mick

    Yep, seems to be worth a try. Thanks for the tip

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.