CHMlib Logo Leading Translation Management System for Translation Agencies, Top Translation Management Software for Freelance Translators, Time Tracking Software, Word Count, Character Count and Line Count Software, Computer Assisted Translation Tool for Easy Word Count, Clipboard Character Count Software, User-Friendly Translation Memory Software, Terminology Management Software, Terminology Management Server, Microsoft Glossary Software, Dictionary of Acronyms, Social Network for Translators and Translation Agencies, Acronyms and Abbreviations Search Engine, Russian Translation Lab, Ukrainian Translation Lab.
You are reading help file online using chmlib.com
CrisisHelper - First Aid in Tough Times of World Economic Crisis


Rave Reports Visual Designer

Lesson - Calculated Fields

Top  Previous  Next

You can create calculated fields in Delphi and use those in your reports. However, those fields are also available to Delphi visual form components such as DBGrids so that is not always a desirable option. Another problem is that you cannot define calculated fields for memo or graphic field types. Here is a method to define calculated fields in Delphi that will only be available to your reports, will not impact the rest of your application and works for memo or graphic fields. The following example could be done using DataMirrors, but we want to show a custom data connection solution. This example demonstrates a method for printing addresses where some of the lines may be blank and you do not want them printed.

 

1) Define an OnGetCols event

 

procedure TForm1.CustomerCXNGetCols(Connection: TRPCustomConnection);

begin

       With Connection do begin

               DoGetCols;

               WriteField('FullAddress', dtMemo, 30, '', '');

       end; { with }

end;

 

The DoGetCols call will create the default columns (fields) that would have been created if you did not define this event. The only step left for this event is to call WriteField to define the meta-information for each field that you want to define. See Lesson - "Custom Data Connection" for more information on WriteField.

 

2) Define an OnGetRow event

 

procedure TForm1.CustomerCXNGetRow(Connection: TRPCustomConnection);

var

Stream: TMemoryStream;

Memo: TMemo;

s1, s2: string;

i1: integer;

begin

With Connection do begin

   DoGetRow; // get data for table fields

 

   For i1 := 0 to 3 do begin

     case i1 of

       0: s2 := Table1.FieldByName('Company').AsString;

       1: s2 := Table1.FieldByName('Addr1').AsString;

       2: s2 := Table1.FieldByName('Addr2').AsString;

       3: begin

         s2 := Table1.FieldByName('City').AsString;

         s2 := s2 + ', ' + Table1.FieldByName('State').AsString +

              ' ' + Table1.FieldByName('Zip').AsString;

       end;

     end; // case

     if s2 <> '' then begin

       if s1 = '' then begin

         s1 := s2;

       end else begin

         s1 := s1 + #13#10 + s2;

       end;// else

     end;// if

   end;// for

 

   Stream := TMemoryStream.Create;

   Memo := TMemo.create(self);

   try

     Memo.Text := s1;

     Memo.Lines.SaveToStream(Stream);

     Stream.Position := 0;

     WriteBlobData(Stream.Memory^, Stream.Size);

   finally

     Stream.Free;

     Memo.Free;

   end;// tryf

end; { with }

end;

 

We need to force the default behavior for this event by calling DoGetRow. Then we get the address information and store it in a string variable. We can then write the data for our calculated field by calling WriteBlobData (since it is a memo field). See Lesson - "Custom Data Connections" for more information on WriteBlobData and the other WriteXxxxData methods. You can add more calculated fields to your data connection by adding more calls to WriteField and WriteXxxxData in each of these events.

 

As with custom data connections, you must have your application running and the data connection must be set to visible for these fields to show up.

 



You are reading help file online using chmlib.com

If you want your help file to be removed or added please send e-mail to chmlibcom@gmail.com