Unit U_ExpXlsX;
interface
uses windows, SysUtils, Variants, Classes, FR_Class,  frx2xto30;

function ExportReportToXLSX(aFileName: String; aReport: tfrReport): Boolean;
//procedure UserFunction(const Name: String; var Val: Variant);
type Tmy_Obj = class(TObject)
     Private
       procedure DoGetValue(const Expr: String; var Value: Variant);
     end;
implementation

Uses FrxClass, FrxExportXlsX, U_ProgressExp, U_Main, U_ResourceReport, U_BaseConstants, U_SCSComponent,
     U_BaseCommon, U_Cad, U_Common, frxdbSet, frxExportDOCX;

function ExportReportToXLSX(aFileName: String; aReport: tfrReport): Boolean;
var i, j: integer;
    Filter: TfrxXLSXExport;
    FilterDoc: TfrxDOCXExport;
    NewRep: TfrxReport;
    Stream: TMemoryStream;
    Compressor: TfrxCustomCompressor;
    ffrCompressor: TfrCompressor;
    my_Obj: TMy_Obj;
    frDBDataset_Master, frDBDataset_Detail, frDBDataset_SubDetail, frDBDataset1, frDBDataset2: TfrxDBDataset;
    c: TfrxComponent;
    d: TfrxDataband;
    dFNAme, s: string;
    f: TextFile;

    Procedure SetNewReportPagesVisibility;
    var i: integer;
    begin
      if TF_Main(F_ProjMan).F_ResourceReport.ReportPagesVisibilityList = nil then
        exit;
      if TF_Main(F_ProjMan).F_ResourceReport.ReportPagesVisibilityList.Count = 0 then
        exit;

      if (NewRep.PagesCount - 1) = TF_Main(F_ProjMan).F_ResourceReport.ReportPagesVisibilityList.Count then
      begin
        for i := 0 to TF_Main(F_ProjMan).F_ResourceReport.ReportPagesVisibilityList.Count - 1 do
        begin
          if TF_Main(F_ProjMan).F_ResourceReport.ReportPagesVisibilityList[i] = 1 then
            NewRep.Pages[i + 1].Visible := True
          else
            NewRep.Pages[i + 1].Visible := false;
        end;
      end;
    end;
begin
  Result := False;

  NewRep := TfrxReport.Create(aReport.Owner);
  Filter := TfrxXLSXExport.Create(NewRep);

  Filter.FileName := aFileName;
  Filter.ShowDialog := False;

  {dFNAme := aFileName;
  delete(dFName, Pos('.xlsx',dFName),5);
  dFName := dFName + '.docx';
  FilterDoc := TfrxDOCXExport.Create(NewRep);
  FilterDoc.FileName := aFileName;
  FilterDoc.ShowDialog := False;}

  Stream := TMemoryStream.Create;
  //aReport.SaveToFR3File('c:\123');
  //aReport.FR3Stream := True;
  aReport.SaveToStream(stream);

  //aReport.Pages[0].Objects.Count

  //aReport.FR3Stream := false;
  Stream.Position := 0;
  //Compressor := TfrxCustomCompressor.Create(NewRep);
  //Compressor.IsFR3File := True;
 // NewRep.OnLoadTemplate := frxFR2EventsNew.DoLoad;
 // NewRep.LoadFromFile('c:\123.fr3');
  //ffrCompressor := TfrCompressor.Create;
  //NewRep.Preview.

 // NewRep.OnUserFunction := TfrxUserFunctionEvent(aReport.OnUserFunction);
 // NewRep.OnGetValue := aREport.OnGetValue;

  NewRep.LoadFromStream(Stream);

  //Report.Clear;

 // frDBDataset_Master := TfrxDbDataset.Create(NewRep);
  frDBDataset_Master := TfrxDbDataset.Create(Nil);
  frDBDataset_Master.Name := 'frDBDataSet_Master';
  frDBDataset_Detail := TfrxDbDataset.Create(Nil);
  frDBDataset_Detail.Name := 'frDBDataSet_Detail';

  frDBDataset_SubDetail := TfrxDbDataset.Create(Nil);
  frDBDataset_SubDetail.Name := 'frDBDataset_SubDetail';

  frDBDataset1 := TfrxDbDataset.Create(Nil);
  frDBDataset1.Name := 'frDBDataset1';

  frDBDataset2 := TfrxDbDataset.Create(Nil);
  frDBDataset2.Name := 'frDBDataset2';

  frDBDataset_Master.OpenDataSource := True;
  frDBDataset_Master.RangeBegin := rbFirst;
  frDBDataset_Master.RangeEnd := reLast;

  frDBDataset_Detail.OpenDataSource := True;
  frDBDataset_Detail.RangeBegin := rbFirst;
  frDBDataset_Detail.RangeEnd := reLast;

  frDBDataset_SubDetail.OpenDataSource := True;
  frDBDataset_SubDetail.RangeBegin := rbFirst;
  frDBDataset_SubDetail.RangeEnd := reLast;

  frDBDataset1.OpenDataSource := True;
  frDBDataset1.RangeBegin := rbFirst;
  frDBDataset1.RangeEnd := reLast;

  frDBDataset2.OpenDataSource := True;
  frDBDataset2.RangeBegin := rbFirst;
  frDBDataset2.RangeEnd := reLast;

  //frDBDataset_Master.Name := 'TF_Main(F_ProjMan).F_ResourceReport.' + TF_Main(F_ProjMan).F_ResourceReport.frDBDataSet_Master.Name;
  frDBDataset_Master.DataSource :=  TF_Main(F_ProjMan).F_ResourceReport.frDBDataSet_Master.DataSource;
  frDBDataset_Master.DataSet :=  TF_Main(F_ProjMan).F_ResourceReport.frDBDataSet_Master.DataSet;

  frDBDataset_Detail.DataSource :=  TF_Main(F_ProjMan).F_ResourceReport.frDBDataSet_Detail.DataSource;
  frDBDataset_Detail.DataSet :=  TF_Main(F_ProjMan).F_ResourceReport.frDBDataSet_Detail.DataSet;

  frDBDataset_SubDetail.DataSource := TF_Main(F_ProjMan).F_ResourceReport.frDBDataSet_SubDetail.DataSource;
  frDBDataset_SubDetail.DataSet := TF_Main(F_ProjMan).F_ResourceReport.frDBDataSet_SubDetail.DataSet;

  frDBDataset1.DataSource := TF_Main(F_ProjMan).F_ResourceReport.frDBDataSet1.DataSource;
  frDBDataset1.DataSet := TF_Main(F_ProjMan).F_ResourceReport.frDBDataSet1.DataSet;

  frDBDataset2.DataSource := TF_Main(F_ProjMan).F_ResourceReport.frDBDataSet2.DataSource;
  frDBDataset2.DataSet := TF_Main(F_ProjMan).F_ResourceReport.frDBDataSet2.DataSet;

  if frDBDataset_Master.DataSource <> nil then
    if frDBDataset_Master.DataSource.DataSet <> nil then
    begin
      frDBDataset_Master.DataSource.DataSet.First;
      frDBDataset_Master.UserName := frDBDataset_Master.DataSource.DataSet.Name;
      NewRep.DataSets.Add(frDBDataset_Master);
    end;

  if frDBDataset_Detail.DataSource <> nil then
    if frDBDataset_Detail.DataSource.DataSet <> nil then
    begin
      frDBDataset_Detail.DataSource.DataSet.First;
      frDBDataset_Detail.UserName := frDBDataset_Detail.DataSource.DataSet.Name;
      NewRep.DataSets.Add(frDBDataset_Detail);
    end;

  if frDBDataset_SubDetail.DataSource <> nil then
    if frDBDataset_SubDetail.DataSource.DataSet <> nil then
    begin
      frDBDataset_SubDetail.DataSource.DataSet.First;
      frDBDataset_SubDetail.UserName := frDBDataset_SubDetail.DataSource.DataSet.Name;
      NewRep.DataSets.Add(frDBDataset_Detail);
    end;

  if frDBDataset1.DataSource <> nil then
    if frDBDataset1.DataSource.DataSet <> nil then
    begin
      frDBDataset1.DataSource.DataSet.First;
      frDBDataset1.UserName := frDBDataset1.DataSource.DataSet.Name;
      NewRep.DataSets.Add(frDBDataset1);
    end;

  if frDBDataset2.DataSource <> nil then
    if frDBDataset2.DataSource.DataSet <> nil then
    begin
      frDBDataset2.DataSource.DataSet.First;
      frDBDataset2.UserName := frDBDataset2.DataSource.DataSet.Name;
      NewRep.DataSets.Add(frDBDataset2);
    end;



   AssignFile(f, 'c:\ImpClasses.txt');
   rewrite(f);
   for i := 0 to NewRep.AllObjects.Count - 1  do
   begin
      c := NewRep.AllObjects[i];
      s := c.ClassName;
      writeln(f, s);
      if c is TfrxDataband then
      begin
        d := NewRep.AllObjects[i];
        if d.DataSet = nil then
        begin
          s := d.DatasetName;
          if CompareStr(s, frDBDataset_Master.Name) = 0 then
             d.DataSet := frDBDataset_Master
          else
          if s = frDBDataset_Detail.Name then
             d.DataSet := frDBDataset_Detail
          else
          if s =  frDBDataset_SubDetail.Name then
             d.DataSet :=  frDBDataset_SubDetail
          else
          if s = frDBDataset1.Name then
             d.DataSet := frDBDataset1
          else
          if s = frDBDataset2.Name then
             d.DataSet := frDBDataset2
          {for j := 0 to NewRep.DataSets.Count - 1 do
          begin
            if TfrxDbDataset(NewRep.DataSets[j]).Name = s then
            begin
              d.DataSet := TfrxDbDataset(NewRep.DataSets[j]);
            end;
          end;
          }
        end;
      end;
   end;
   CloseFile(f);

  SetNewReportPagesVisibility; // установить видимость страниц ... как было
  //NewRep.Pages[0].Objects

  //aReport.Dictionary.BandDatasources.Count

  NewRep.OnUserFunction := TfrxUserFunctionEvent(aReport.OnUserFunction);

  my_Obj := TMy_Obj.Create;

  frxFR2Events.OnGetValue := My_Obj.DoGetValue;//aREport.OnGetValue;

  //FreeAndNil(frxFR2Events);



  //NewRep.OnGetValue := My_Obj.DoGetValue;

  //NewRep.PrepareScript(NewRep);

  //NewRep.Engine.Run(false);

  //NewRep.PrepareReport(True);
  {
  NewRep.PreparePage(NewRep.Pages[1]);
  NewRep.ShowReport;
  }
  NewRep.OnGetValue := aREport.OnGetValue;
  //NewRep.EngineOptions.DoublePass := True;
  TF_Main(F_ProjMan).F_ResourceReport.ShowXLSXReport(NewRep);

  //LoadFromFR2Stream(NewRep, Stream);
  //NewR.Pagesep.LoadFromStream(stream);
  //NewRep.InheritFromTemplate()
  //NewRep.Assign(aReport);
  //NewRep.Export(Filter);

  //NewRep.PrepareReport(false);

  //NewRep.PrepareReport;

  NewRep.Export(Filter);


  stream.free;
  //NewRep.Preview.Assign(aReport.Preview);
  //NewRep.Free;
  i := 0;
  Filter.Free;
  //FilterDoc.Free;
 // NewRep.Free;
  my_Obj.Free;
  Result := True;
end;

Procedure TMy_Obj.DoGetValue(const Expr: String; var Value: Variant);
var s, param: String;
    TempStr: string;
    i, j: integer;
    p1, p2, p3: Variant;
begin
  p1 := null;
  p2 := null;
  p3 := null;

  s := Expr;
  param := '';
  TempStr := '';
  j := pos('(', s);
  if j > 0 then
  begin
    i := 1;

    while s[i] <> '(' do
    begin
      TempStr := TempStr + s[i];
      inc(i);
    end;

    inc(j);

    while s[j] <> ')' do
    begin
      param := param + s[j];
      inc(j);
    end;

    s := Tempstr;
    p1 := param;
  end;
  TF_Main(F_ProjMan).F_ResourceReport.ReportUserFunction(s, p1, p2, p3, Value);
end;

(*
procedure UserFunction(const Name: String; var Val: Variant);
var
  SCSProjCatalog: TSCSCatalog;
  FooterBand: TfrBandView;
  p1, p2, p3: Variant;
begin
  SCSProjCatalog := nil;

  if TF_Main(F_ProjMan).F_ResourceReport.Catalog <> nil then
    if TF_Main(F_ProjMan).F_ResourceReport.Catalog.ItemType = itProject then
      SCSProjCatalog := TF_Main(F_ProjMan).F_ResourceReport.Catalog
    else
      SCSProjCatalog := TF_Main(F_ProjMan).F_ResourceReport.Catalog.GetTopParentCatalog;

  if Name = 'GETREPLABEL' then
    Val := DateToStr(Date)+' '+cResourceReport_Msg24 +ApplicationName+' '+ VersionEXE
  else
  if Name = 'GETPROJECTNAME' then
  begin
    Val := '';
    SCSProjCatalog := nil;
    if Assigned(TF_Main(F_ProjMan).F_ResourceReport.Catalog) then
      if TF_Main(F_ProjMan).F_ResourceReport.Catalog.ItemType = itProject then
        SCSProjCatalog := TF_Main(F_ProjMan).F_ResourceReport.Catalog
      else
        SCSProjCatalog := TF_Main(F_ProjMan).F_ResourceReport.Catalog.GetTopParentCatalog;
    if Assigned(SCSProjCatalog) then
      Val := SCSProjCatalog.GetNameForVisible;
  end
  else
  if Name = 'GETLISTNAME' then
  begin
    Val := '';
    if Assigned(TF_Main(F_ProjMan).F_ResourceReport.Catalog) then
      if TF_Main(F_ProjMan).F_ResourceReport.Catalog.ItemType = itList then
        Val := TF_Main(F_ProjMan).F_ResourceReport.Catalog.GetNameForVisible
      else
      if TF_Main(F_ProjMan).F_ResourceReport.Catalog.ItemType = itDir then
        Val := TF_Main(F_ProjMan).F_ResourceReport.Catalog.GetNameForVisible+' ('+GetCatalogItemsNames(TF_Main(F_ProjMan).F_ResourceReport.Catalog, [itList])+')';
  end
  else
  if Name = 'GETCOMPONNAME' then
  begin
    Val := '';
    if Assigned(TF_Main(F_ProjMan).F_ResourceReport.Component) then
      val := TF_Main(F_ProjMan).F_ResourceReport.Component.GetNameForVisible;
  end
  //Tolik
  else
  if Name = 'GETISCOMPCABLE' then  // 08/02/2018 --для отчета "Полный путь кабеля " -- показатель, принадлежит ли кабель,
                                   // на котором вызван отчет компьютерной сети
  begin
    if TF_Main(F_ProjMan).F_ResourceReport.isCompCable then
      Val := 1
    else
      val := 0;
  end
  else
  if Name = 'GETCABLENAME' then
  begin
    Val := '';
    if Assigned(TF_Main(F_ProjMan).F_ResourceReport.Component) then
      Val := TF_Main(F_ProjMan).F_ResourceReport.Component.Name;
  end
  else
  if Name = 'GETCABLEZAPAS' then
  begin
    Val := null;
    if TF_Main(F_ProjMan).F_ResourceReport.Catalog.ItemType = itList then
      Val := TSCSList(TF_Main(F_ProjMan).F_ResourceReport.Catalog).Setting.LengthKoef;
  end
  else
  if Name = 'GETZAKAZCHIKNAME' then
  begin
    if rkCalc in FReportUseKind then
      Val := FCostOfProjectReportParams.ZakazchikName
    else
    begin
     Val := F_ProjMan.GSCSBase.CurrProject.Setting.CustomerName;
    end;
  end
  else
  if Name = 'GETPODRADCHIKNAME' then
  begin
    if rkCalc in FReportUseKind then
      Val := FCostOfProjectReportParams.PodradchikName
    else
      if SCSProjCatalog <> nil then
        Val := TSCSProject(SCSProjCatalog).Setting.ContractorName
      else
        Val := '';
  end
  else
  if Name = 'GETORGANIZATIONNAME' then
  begin
    if SCSProjCatalog <> nil then
      Val := TSCSProject(SCSProjCatalog).Setting.OrganizationName;
  end
  else
  if Name = 'GETCURRNPP' then
  begin
    Val := DefineCurrRecNo; //frDBDataSet_Master.DataSource.DataSet.RecNo;
  end
  else
  if Name = 'GETISNEWRECORD' then
  begin
    if (FCurrRecNo = FOldRecNo) and (FOldRecNo <> 0) then
      Val := false
    else
      Val := true;
  end
  else
  if Name = 'GETPASSNUM' then
  begin
    Val := FPassNum;
  end
  else
  if Name = 'INCPASSNUM' then
  begin
    Inc(FPassNum);
    Val := FPassNum;
  end
  else
  if Name = 'DEFINEPAGEFOOTER' then
  begin
    FooterBand := TfrBandView(Report.FindObject('PageFooter'));
  end
  else
  if Name = 'GETLENGTHTHROUGHFLOOR' then
  begin
    Val := 0;
    if F_ResourceReport.Catalog is TSCSProject then
      Val := Round2(FloatInUOM(TSCSProject(F_ResourceReport.Catalog).Setting.HeightThroughFloor * (TSCSProject(F_ResourceReport.Catalog).IDsNearFloorFigures.Count) / 2,
                umMetr, TF_Main(GForm).FUOM));
  end
  else
  if Name = 'GETIZM' then
    Val := GetNameUOM(TF_Main(GForm).FUOM, true)
  else
  if Name = 'GETIZMSYMB' then
    Val := GetNameUOM(TF_Main(GForm).FUOM, true, false)
  else
  if Name = 'GETIZMLENMIN' then
    Val := GetUOMLengthMin
  else
  if Name = 'GETIZMWEIGHT' then
    Val := GetUOMWeight
  else
  if Name = 'GETNDS' then
  begin
    if rkProject in FReportUseKind then
    begin
      if SCSProjCatalog <> nil then
        Val := TSCSProject(SCSProjCatalog).Setting.NDS;
    end
  end
  else
  if Name = 'GETPRICEWITHNDS' then //21.11.2013 - Вернуть цену с НДС
  begin
    Report.GetVariableValue(p1, Val);
    if Val <> null then
      if TSCSProject(SCSProjCatalog).Setting.NDS > 0 then
        Val := Val * (TSCSProject(SCSProjCatalog).Setting.NDS/100+1)
  end
  else
  if Name = 'GETTOTALLABORTIME' then
    Val := GetDisplayTextToNORMLaborTime(IntToStr(FTotalLaborTime))
  else
  if Name = 'GETCAPT' then
  begin
    Val := '';
    if p1 = 'CUSTOMER' then
      Val := cRepMsg01
    // added by Tolik for CommerceInvoice Report
    else
    if p1 = 'RESOURCES' then
      Val := cRepMsg207_1
    else
    if p1 = 'CONTRACTOR' then
      Val := cRepMsg02
    else
    if p1 = 'PROJNAME' then
      Val := cRepMsg03
    else
    if p1 = 'PAGENAME' then
      Val := cRepMsg10
    else
    if p1 = 'GRAPHSYMBLEGEND' then
      Val := cRepMsg04
    else
    if p1 = 'NUM' then
    // Tolik 21/01/2020
    {$IF DEFINED (SCS_PE)}
      Val := 'N'
    {$ELSE}
      Val := cRepMsg05
    {$IFEND}
    //
    else
    if p1 = 'NAME' then
      Val := cRepMsg06
    else
    if p1 = 'INDICATION' then
      Val := cRepMsg07
    else
    if p1 = 'WORKEDOUT' then
      Val := cRepMsg08
    else
    if p1 = 'LENGTHALLCABLES' then
      Val := cRepMsg227
    else
    if p1 = 'CHECKEDBY' then
      Val := cRepMsg09
    else
    if p1 = 'UNDERLINE' then
      Val := DupStr('_', 30) //'______________________________'
    else
    if p1 = 'ADJUSTT' then
      Val := cRepMsg11
    else
    if p1 = 'VZAMINVENTNUMT' then
      Val := cRepMsg12
    else
    if p1 = 'SIGNANDDATET' then
      Val := cRepMsg13
    else
    if p1 = 'INVNUMPODLT' then
      Val := cRepMsg14
    else
    if p1 = 'IZMT' then
      Val := cRepMsg15
    else
    if p1 = 'KOLICHT' then
      Val := cRepMsg16
    else
    if p1 = 'PAGET' then
      Val := cRepMsg17
    else
    if p1 = 'NUMDOCT' then
      Val := cRepMsg18
    else
    if p1 = 'SIGNT' then
      Val := cRepMsg19
    else
    if p1 = 'DATET' then
      Val := cRepMsg20
    else
    if p1 = 'STAGET' then
      Val := cRepMsg21
    else
    if p1 = 'PAGEST' then
      Val := cRepMsg22
    else
    if p1 = 'SIGNATURE' then
      Val := cRepMsg23
    else
    if p1 = 'LASTNAME' then
      Val := cRepMsg24
    else
    if p1 = 'CABLEDUCTSLIST' then
      Val := cRepMsg25
    else
    if p1 = 'UOM' then
      Val := cRepMsg26
    else
    if p1 = 'FULLNESSPERC' then
      Val := cRepMsg27
    else
    if p1 = 'LENGTH_M' then
      Val := cRepMsg154 + GetUOMWithOrthographMarks //cRepMsg28
    else
    if p1 = 'RESERVE_M' then
      Val := cRepMsg155 + GetUOMWithOrthographMarks //cRepMsg29
    else
    if p1 = 'PRICE' then
      Val := cRepMsg30
    else
    if p1 = 'COST' then
      Val := cRepMsg31
    else
    if p1 = 'TOTAL' then
      Val := cRepMsg32
    else
    if p1 = 'GENERALCABDUCTSLEN' then
      Val := cRepMsg33
    else
    if p1 = 'M' then
      Val := cRepMsg34
    else
    if p1 = 'GENERALRESERVLEN' then
      Val := cRepMsg35
    else
    if p1 = 'CABLEDUCTSLIST_NOTE1' then
      Val := cRepMsg36
    else
    if p1 = 'CABLELIST' then
      Val := cRepMsg37
    else
    if p1 = 'CONNECTBEGINSH' then
      Val := cRepMsg38
    else
    if p1 = 'CONNECTENDSH' then
      Val := cRepMsg39
    else
    if p1 = 'GENERALCABLESLEN' then
      Val := cRepMsg40
    else
    if p1 = 'GENERALRESERVLEN' then
      Val := cRepMsg41
    else
    if p1 = 'CABLELIST_NOTE1' then
      Val := cRepMsg42
    else
    if p1 = 'CABLELIST_NOTE2' then
      Val := cRepMsg43
    else
    if p1 = 'LISTOFWORKS' then
      Val := cRepMsg44
    else
    if p1 = 'CODE' then
      Val := cRepMsg45
    else
    if p1 = 'VOLUME' then
      Val := cRepMsg46
    else
    if p1 = 'RESOURCELIST' then
      Val := cRepMsg47
    else
    if p1 = 'VENDORSERIALNUM' then
      Val := cRepMsg48
    else
    if p1 = 'DISTRIBSERIALNUM' then
      Val := cRepMsg49
    else
    if p1 = 'VENDOR' then
      Val := cRepMsg50
    else
    if p1 = 'QUANTITY' then
      Val := cRepMsg51
    else
    if p1 = 'PRICEVAT' then
      Val := cRepMsg52
    else
    if p1 = 'COSTVAT' then
      Val := cRepMsg53
    else
    if p1 = 'TOTALCOST' then
      Val := cRepMsg54
    else
    if p1 = 'RESOURCELIST_NOTE1' then
      Val := cRepMsg55
    else
    if p1 = 'EXTLOGBOOK' then
      Val := cRepMsg56
    else
    if p1 = 'NUMPP' then
      Val := cRepMsg57
    else
    if p1 = 'NUMCABLE' then
      Val := cRepMsg58
    else
    if p1 = 'CABLEDATA' then
      Val := cRepMsg59
    else
    if p1 = 'CORENUMBER' then
      Val := cRepMsg60
    else
    if p1 = 'GOFROM' then
      Val := cRepMsg61
    else
    if p1 = 'GOWHERE' then
      Val := cRepMsg62
    else
    if p1 = 'BUILDING' then
      Val := cRepMsg63
    else
    if p1 = 'DEVICE_RACK' then
      Val := cRepMsg64
    else
    if p1 = 'ELEMENT_PANEL' then
      Val := cRepMsg65
    else
    if p1 = 'SEATORCIRCUITBOARDTYPE' then
      Val := cRepMsg66
    else
    if p1 = 'NUMPORT' then
      Val := cRepMsg67
    else
    if p1 = 'PORTMARKING' then
      Val := cRepMsg68
    else
    if p1 = 'JUNCTWITHCABLE' then
      Val := cRepMsg69
    else
    if p1 = 'CABLINGTRACE' then
      Val := cRepMsg70
    else
    if p1 = 'MARKINGLABEL' then
      Val := cRepMsg71
    else
    if p1 = 'CABLEDIAMETERMM' then
      Val := cRepMsg156 +', '+ GetUOMLengthMin //cRepMsg72
    else
    if p1 = 'CABLELEN_M_BUILDING' then
      Val := cRepMsg157+', '+ GetNameUOM(TF_Main(GForm).FUOM, true)+' '+cRepMsg158 //cRepMsg73
    else
    if p1 = 'NOTE' then
      Val := cRepMsg74
    else
    if p1 = 'CABLELOGBOOK' then
      Val := cRepMsg75
    else
    if p1 = 'GOST21_101_97' then
      Val := cRepMsg76
    else
    if p1 = 'CABLETYPE' then
      Val := cRepMsg77
    else
    if p1 = 'NUMSWITCHBOARD' then
      Val := cRepMsg78
    else
    if p1 = 'NUMSWITCHBOARDPORT' then
      Val := cRepMsg79
    else
    if p1 = 'COMESFROM' then
      Val := cRepMsg80
    else
    if p1 = 'NUMOUTLETORSWITCHBOARD' then
      Val := cRepMsg81
    else
    if p1 = 'NUMOUTLETORSWITCHBOARDPORT' then
      Val := cRepMsg82
    else
    if p1 = 'ROOM' then
      Val := cRepMsg83
    else
    if p1 = 'CABLE' then
      Val := cRepMsg84
    else
    if p1 = 'CATEGORY' then
      Val := cRepMsg85
    else
    if p1 = 'FROM' then
      Val := cRepMsg86
    else
    if p1 = 'TO' then
      Val := cRepMsg87
    else
    if p1 = 'WORKPLACE' then
      Val := cRepMsg88
    else
    if p1 = 'WORKAREA' then
      Val := cRepMsg88_
    else
    if p1 = 'PORT' then
      Val := cRepMsg89
    else
    if p1 = 'TYPE' then
      Val := cRepMsg90
    else
    if p1 = 'SPECIFICATION' then
      Val := cRepMsg91
    else
    if p1 = 'PRODMARKNUMSH' then
      Val := cRepMsg92
    else
    if p1 = 'DISTRIBMARKNUMSH' then
      Val := cRepMsg93
    else
    if p1 = 'VENDOR' then
      Val := cRepMsg94
    else
    if p1 = 'PRICEWITHVAT' then
      Val := cRepMsg95
    else
    if p1 = 'COSTWITHVAT' then
      Val := cRepMsg96
    else
    if p1 = 'SUM' then
      Val := cRepMsg97
    else
    if p1 = 'SPECIFICATION_NOTE1' then
      Val := cRepMsg98
    else
    if p1 = 'SPECIFICATION_NOTE2' then
      Val := cRepMsg99
    else
    if p1 = 'GOST21_110_95' then
      Val := cRepMsg100
    else
    if p1 = 'POSITION' then
      Val := cRepMsg101
    else
    if p1 = 'NAMEANDTECHCHARACK' then
      Val := cRepMsg102
    else
    if p1 = 'DOCTYPEMARKINDICAT' then
      Val := cRepMsg103
    else
    if p1 = 'CODEOFEQUIPMMATERIAL' then
      Val := cRepMsg104
    else
    if p1 = 'FACTORYPRODUCER' then
      Val := cRepMsg105
    else
    if p1 = 'UNITOFMEASURE' then
      Val := cRepMsg106
    else
    if p1 = 'MASSOFUNITKG' then
      Val := cRepMsg153 + GetUOMWeightOrthographMarks
    else
    if p1 = 'EXPLANATORYNOTE' then
      Val := cRepMsg109
    else
    if p1 = 'BYTHEPROJECT' then
      Val := cRepMsg110
    else
    if p1 = 'BASEPROJCURRENCY' then
      Val := cRepMsg111
    else
    if p1 = 'PROJVAT' then
      Val := cRepMsg112
    else
    if p1 = 'INTERFLOORLIFTINGSHEIGHT_M' then
      Val := cRepMsg145 + GetUOMWithOrthographMarks //cRepMsg113
    else
    if p1 = 'BYPAGES' then
      Val := cRepMsg114
    else
    if p1 = 'FLOORHEIGHT_M' then
      Val := cRepMsg146 + GetUOMWithOrthographMarks //cRepMsg115
    else
    if p1 = 'DROPCEILINGHEIGHT_M' then
      Val := cRepMsg147 + GetUOMWithOrthographMarks //cRepMsg116
    else
    if p1 = 'POINTOBJECTSPLACEMENTHEIGHT_M' then
      Val := cRepMsg148 + GetUOMWithOrthographMarks //cRepMsg117
    else
    if p1 = 'ROUTEPLACEMENTHEIGHT_M' then
      Val := cRepMsg149 + GetUOMWithOrthographMarks //cRepMsg118
    else
    if p1 = 'CONDUITSFULLNESSCOEFFICIENT' then
      Val := cRepMsg119
    else
    if p1 = 'CABLELENGTHRESERVE' then
      Val := cRepMsg120
    else
    if p1 = 'PORTRESERVE_M' then
      Val := cRepMsg150 + GetUOMWithOrthographMarks //cRepMsg121
    else
    if p1 = 'MULTIPORTRESERVE_M' then
      Val := cRepMsg151 + GetUOMWithOrthographMarks //Val := cRepMsg122
    else
    if p1 = 'MAXLENRESTRICTION_M' then
      Val := cRepMsg152 + GetUOMWithOrthographMarks //cRepMsg123
    else
    if p1 = 'EXPLICATIONROOM' then
      Val := cRepMsg124
    else
    if p1 = 'LETTERTOPLAN' then
      Val := cRepMsg125
    else
    if p1 = 'FLOOR' then
      Val := cRepMsg126
    else
    if p1 = 'LODGEMENTTNUM' then
      Val := cRepMsg127
    else
    if p1 = 'ROOMNUM' then
      Val := cRepMsg128
    else
    if p1 = 'APPOINTMENTROOM' then
      Val := cRepMsg129
    else
    if p1 = 'SQUAREINSIDE' then
      Val := cRepMsg130
    else
    if p1 = 'SQM' then
      Val := cRepMsg159+'.'+GetNameUOM(TF_Main(GForm).FUOM, true, false)+'.' //кв.м. кв.фт. cRepMsg131
    else
    if p1 = 'INCLUDING' then
      Val := cRepMsg132
    else
    if p1 = 'TOTALSQUARE' then
      Val := cRepMsg133
    else
    if p1 = 'HABITABLESQUARE' then
      Val := cRepMsg134
    else
    if p1 = 'BACKROOMSQUARE' then
      Val := cRepMsg135
    else
    if p1 = 'SQUARENOINCLUDETOTATAL' then
      Val := cRepMsg136
    else
    if p1 = 'SQUARESELFWILLEDBUILDING' then
      Val := cRepMsg137
    else
    if p1 = 'HEIGHT' then
      Val := cRepMsg138
    else
    if p1 = 'TOTALINFLOOR' then
      Val := cRepMsg139
    else
    if p1 = 'EXPLICATIONCOMPON' then
      Val := cRepMsg140
    else
    if p1 = 'COMPONNUM' then
      Val := cRepMsg141
    else
    if p1 = 'NAMEMARK' then
      Val := cRepMsg142
    else
    if p1 = 'CROSSJOURNAL' then
      Val := cRepMsg143
    else
    if p1 = 'GOST21_110_95' then
      Val := cRepMsg144
    else
    if p1 = 'INTERFLOORLIFTINGSHEIGHT' then
      Val := cRepMsg145
    else
    if p1 = 'FLOORHEIGHT' then
      Val := cRepMsg146
    else
    if p1 = 'DROPCEILINGHEIGHT' then
      Val := cRepMsg147
    else
    if p1 = 'POINTOBJECTSPLACEMENTHEIGHT' then
      Val := cRepMsg148
    else
    if p1 = 'ROUTEPLACEMENTHEIGHT' then
      Val := cRepMsg149
    else
    if p1 = 'PORTRESERVE' then
      Val := cRepMsg150
    else
    if p1 = 'MULTIPORTRESERVE' then
      Val := cRepMsg151
    else
    if p1 = 'MAXLENRESTRICTION' then
      Val := cRepMsg152
    else
    if p1 = 'MASSOFUNIT' then
      Val := cRepMsg153
    else
    if p1 = 'LENGTH' then
      Val := cRepMsg154
    else
    if p1 = 'RESERVE' then
      Val := cRepMsg155
    else
    if p1 = 'CABLEDIAMETER' then
      Val := cRepMsg156
    else
    if p1 = 'CABLELEN' then
      Val := cRepMsg157
    else
    if p1 = 'BUILDING_S' then
      Val := cRepMsg158
    else
    if p1 = 'SQ' then
      Val := cRepMsg159
    else
    if p1 = 'MATERIALS' then
      Val := cRepMsg160
    else
    if p1 = 'ARTICUL' then
      Val := cRepMsg161
    else
    if p1 = 'WORKS' then
      Val := cRepMsg162
    else

    if p1 = 'DEFECTACT' then
      Val := cRepMsg164
    else
    if p1 = 'FINDDEFECT' then
      Val := cRepMsg165
    else
    if p1 = 'WITHDEFINEWORKS' then
      Val := cRepMsg166
    else
    if p1 = 'REPAIRDEFECT' then
      Val := cRepMsg167
    else
    if p1 = 'ADDRESS' then
      Val := cRepMsg168
    else
    if p1 = 'DEFECTDESCRIPTION' then
      Val := cRepMsg169
    else
    if p1 = 'LINKTRANSPORT' then
      Val := cRepMsg170
    else
    if p1 = 'POINTA' then
      Val := cRepMsg171
    else
    if p1 = 'POINTB' then
      Val := cRepMsg172
    else
    if p1 = 'CABLE' then
      Val := cRepMsg173
    else
    if p1 = 'DEFACTMATERIALS' then
      Val := cRepMsg174
    else
    if p1 = 'SETEQUIPMENT' then
      Val := cRepMsg175
    else
    if p1 = 'EQUIPMENT' then
      Val := cRepMsg176
    else
    if p1 = 'MOVEEQUIPMENT' then
      Val := cRepMsg177
    else
    if p1 = 'DEFACTCONTRACTOR' then
      Val := cRepMsg178
    else
    if p1 = 'DATEGETTING' then
      Val := cRepMsg179
    else
    if p1 = 'DATEEXECUTION' then
      Val := cRepMsg180
    else
    if p1 = 'FORCOMPONENT' then
      Val := cRepMsg181

    else
    if p1 = 'R25HOMEANDAPPROACH' then
      Val := cRepMsg191
    else
    if p1 = 'R25NAME' then
      Val := cRepMsg182
    else
    if p1 = 'R25COOPERATIVE' then
      Val := cRepMsg183
    else
    if p1 = 'R25HEO' then
      Val := cRepMsg184
    else
    if p1 = 'R25AGREED' then
      Val := cRepMsg185
    else
    if p1 = 'R25BOXINSTALLED' then
      Val := cRepMsg186
    else
    if p1 = 'R25PRESENCEPOWER200WFROMNETWORK' then
      Val := cRepMsg187
    else
    if p1 = 'R25CABLESETTOBOX' then
      Val := cRepMsg188
    else
    if p1 = 'R25FIBEROPTICWELDED' then
      Val := cRepMsg189
    else
    if p1 = 'R25EQUIPMENTINSTALLED' then
      Val := cRepMsg190
    else
    //Tolik
    if p1 = 'CROSSCONNECTION' then
      Val := cRepMsg205
    else
    if p1 = 'BUILDINGDISTRIBUTOR' then
      Val := cRepMsg228
    else
    if p1 = 'REELSCABLEFLOW' then
      Val := ReelsCableFlow.Text
    else
    if p1 = 'CABLEREZERV' then
      Val := cRepMsg229
    else
    if p1 = 'WACOORDINATES' then
      Val := cRepMsg238
    else
    if p1 = 'PATH' then
      Val := cRepMsg230
    else
    if p1 = 'CABLE' then
      Val := cRepMsg240
    else
    if p1 = 'CABLEWIREMARKING' then
      Val := cRepMsg247
    else
    if p1 = 'TRACE' then
      Val := cRepMsg248
    else
    if p1 = 'CABLETRACEPART' then
      Val := cRepMsg249
    else
    if p1 = 'TRACEBEGIN' then
      Val := cRepMsg250
    else
    if p1 = 'TRACEEND' then
      Val := cRepMsg251
    else
    if p1 = 'CABLEWIRE' then
      Val := cRepMsg252
    else
    if p1 = 'ONPROJECT' then
      Val := cRepMsg253
    else
    if p1 = 'CABLELAID' then
      Val := cRepMsg254
    else
    if p1 = 'COUNTANDCROSSSQUARE' then
      Val := cRepMsg255
    else
    if p1 = 'CABLEMARK' then
      Val := cRepMsg256
    else
    if p1 = 'CABLETUBEJOURNAL' then
      Val := cRepMsg257
    else
    if p1 = 'THEN' then
      Val := cRepMsg206
    else
    if p1 = 'PARTCABLELENGTH' then
      Val := cRepMsg237
    else
    if p1 = 'PRIORCOSTOFPROJECT' then
      Val := cRepMsg192
    else
    // к основной рамке на чертеж (подписи)(Tolik)
    if p1 = 'RAZRABOTAL' then
      Val := cRepMsg260
    else
    if p1 = 'PROVERIL' then
      Val := cRepMsg261
    else
    if p1 = 'NCONTROL' then
      Val := cRepMsg262
    else
    if p1 = 'TCONTROL' then
      Val := cRepMsg263
    else
    if p1 = 'UTVERDIL' then
      Val := cRepMsg264
   { Значения из свойств проекта и листа}
    else
    if p1 = 'STAMPDEVELOPER' then
	  try
        Val := F_ProjMan.GSCSBase.CurrProject.ProjectLists.Items[0].Setting.CADStampDeveloper // разработал
	  except
	  end
    else
    if p1 = 'MAINENGINEER' then
	  try
        Val := F_ProjMan.GSCSBase.CurrProject.ProjectLists.Items[0].Setting.CADStampMainEngineer  //главный инженер проекта
	  except
	  end
    else
    if p1 = 'STAMPCHECKER' then
	  try
        Val := F_ProjMan.GSCSBase.CurrProject.ProjectLists.Items[0].Setting.CADStampChecker  // проверил
	  except
	  end
    else
    if p1 = 'STAMPAPPROVED' then
	  try
        Val := F_ProjMan.GSCSBase.CurrProject.ProjectLists.Items[0].Setting.CADStampApproved  // утвердил
	  except
	  end

    else
    if p1 = 'DESIGNSTAGE' then
	  try
      // Tolik -- 24/02/2020 --
      if Assigned(GCadForm) then
        Val := GCadForm.FListSettings.CADStampDesignStage
      else
        Val := F_ProjMan.GSCSBase.CurrProject.ProjectLists.Items[0].Setting.CADStampDesignStage  // стадия проектирования
	  except
	  end

    else
    if p1 = 'PROECTORGANIZATION' then
	  try
        Val := F_ProjMan.GSCSBase.CurrProject.Setting.OrganizationName // наименование организации проектировщика
	  except
	  end

    else
    if p1 = 'LISTSIGN' then
	  try
        Val := F_ProjMan.GSCSBase.CurrProject.ProjectLists.Items[0].Setting.CADStampListSign  // обозначение документа
	  except
	  end

    //
    else
    begin
      val := GetStrFromStringsByKey(FRepMsgList, p1);
    end;
  end
  else if Name = 'GETLOAT' then
  begin
    val := FloatToStrFix(p1, FloatPrecision);
  end;
end;
 *)
end.