Strong Report + Masks

0

Does anyone know how I can format a CPF / CNPJ in a report in strongs Report?

procedure TFRelMenLac.RLBand4BeforePrint(Sender: TObject; var PrintIt: Boolean);
var
  ltemp : string;
begin
  ltemp := dmretaguarda.qlac.fieldbyname('dccli').asstring;
  if length(ltemp) = 11 then
    begin
      rlldccli.Caption := 'CPF: ';
      //RLDBText29.DisplayMask := '000.000.000-00';

      RLDBText29.Text := copy(ltemp, 1,3)+'.'+copy(ltemp, 4,3)+'.'+copy(ltemp, 7,3)+'-'+copy(ltemp, 10,2);
    end
  else
    begin
      rlldccli.Caption := 'CNPJ: ';
      RLDBText29.Text := copy(ltemp, 1,3)+'.'+copy(ltemp, 4,3)+'.'+copy(ltemp,7,3)+'/'+copy(ltemp, 10,4)+'-'+copy(ltemp, 14,2);
    end;
      //RLDBText29.DisplayMask := '000.000.000/0000-00';

By removing the commented areas, I tried with Copy , but without success, any ideas?

----- Edit -----

 DMRetaguarda.QLac.close;
  DMRetaguarda.QLac.sql.clear;
  DMRetaguarda.QLac.SQL.Add('SELECT relinm.mattec, relinm.nmtec, relinm.nmequip, relinm.num_os, relinm.num_sel, relinm.dtpront, relinm.marca, relinm.modelo, relinm.matric, relinm.peso, relinm.num_lac, relinm.numinm,');
  DMRetaguarda.QLac.SQL.Add('cliente.razaosocial, cliente.cidade as clcid, cliente.uf as cluf, cliente.rua as clru, cliente.bairro as clbr, cliente.cep as clcp, cliente.chave, CASE WHEN cliente.cgc <> '''' THEN cliente.cgc ELSE cliente.cpf END AS dccli ');
  DMRetaguarda.QLac.SQL.Add('FROM relinm, cliente WHERE relinm.codcli = cliente.chave AND relinm.dtpront BETWEEN :pini AND :pfim ORDER BY relinm.mattec, relinm.nmequip, relinm.dtpront');
  DMRetaguarda.QLac.ParamByName('pini').AsDate := StrToDateTime(
    MaskEdit1.Text);
  DMRetaguarda.QLac.ParamByName('pfim').AsDate := StrToDateTime(
    MaskEdit2.Text);
  DMRetaguarda.QLac.open;

---- Edit2 ----

  if length(DMRetaguarda.QLac.FieldByName('dccli').AsString) = 11 then
  begin
    rlldccli.Caption := 'CPF: ';
    DMRetaguarda.QLac.FieldByName('dccli').EditMask := '999.999.999-99;0;_'
    //RLDBText29.DisplayMask := '000.000.000\-99;1;_';
    //RLDBText29.Text := copy(ltemp, 1,3)+'.'+copy(ltemp, 4,3)+'.'+copy(ltemp, 7,3)+'-'+copy(ltemp, 10,2);
  end
  else
  begin
    rlldccli.Caption := 'CNPJ: ';
    DMRetaguarda.QLac.FieldByName('dccli').EditMask := '99.999.999/9999-99;0;_';
    //RLDBText29.Text := copy(ltemp, 1,3)+'.'+copy(ltemp, 4,3)+'.'+copy(ltemp,7,3)+'/'+copy(ltemp, 10,4)+'-'+copy(ltemp, 14,2);
    //RLDBText29.DisplayMask := '000.000.000
procedure TFRelMenLac.RLBand4BeforePrint(Sender: TObject; var PrintIt: Boolean);
var
  ltemp : string;
begin
  ltemp := dmretaguarda.qlac.fieldbyname('dccli').asstring;
  if length(ltemp) = 11 then
    begin
      rlldccli.Caption := 'CPF: ';
      //RLDBText29.DisplayMask := '000.000.000-00';

      RLDBText29.Text := copy(ltemp, 1,3)+'.'+copy(ltemp, 4,3)+'.'+copy(ltemp, 7,3)+'-'+copy(ltemp, 10,2);
    end
  else
    begin
      rlldccli.Caption := 'CNPJ: ';
      RLDBText29.Text := copy(ltemp, 1,3)+'.'+copy(ltemp, 4,3)+'.'+copy(ltemp,7,3)+'/'+copy(ltemp, 10,4)+'-'+copy(ltemp, 14,2);
    end;
      //RLDBText29.DisplayMask := '000.000.000/0000-00';
00-99;1;_'; end;

Follow my QLac. Any ideas?

This is my code, but it gets messed up in some fields, that is, it follows the image:

I believe that by the format of the one to understand that it was wrong, but it is not in all, many are right, some idea of how to proceed?     

asked by anonymous 02.07.2014 / 22:32

2 answers

0

Gentlemen, I was able to solve this problem with Wesley's help.

The only problem was when I was picking up the values, the strongs has 2 steps, Prepare and Show ... so, in my code above, it was showing after picking up the values cpf / cnpj, and before showing the report, consequently the problem was in EVENTO .

So, all I did was put in evento do relatório called, OnDataRecord , below:

procedure TFRelMenLac.RLReport1DataRecord(Sender: TObject; RecNo,
  CopyNo: Integer; var Eof: Boolean; var RecordAction: TRLRecordAction);
begin
  if length(DMRetaguarda.QLac.FieldByName('dccli').AsString) = 11 then
  begin
    rlldccli.Caption := 'CPF: ';
    DMRetaguarda.QLac.FieldByName('dccli').EditMask := '999.999.999-99;0;_';
  end;
  if length(DMRetaguarda.QLac.FieldByName('dccli').AsString) = 14 then
  begin
    rlldccli.Caption := 'CNPJ: ';
    DMRetaguarda.QLac.FieldByName('dccli').EditMask := '99.999.999/9999-99;0;_';
  end;
end;

And that's it, it worked like magic, thanks for the personal help.

    
10.07.2014 / 13:31
1

Here I do the following in the AfterOpen of the Query component I determine the TField

DataSet.FieldByName('CNPJ').EditMask := '99.999.999/9999-99;0;_';
DataSet.FieldByName('CPF').EditMask := '999.999.999-99;0;_';
    
09.07.2014 / 18:34