Change .rtm Storage -> Format programatically

Use case: We need to loop through all our .rtm's and change them to ftASCII format.

How could this be done?

Comments

  • Hi Robert,

    Iterate over the .rtm's and for each, use Report.Template methods to load the .rtm. Then set Report.Template.Format to ftASCII and then call Report.Template.SaveToFile

    Report.Template.Format defines ftBinary as the default property value. Delphi does not write default properties, so there is no way to edit the .rtm as text and accomplish your goal.

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited August 2019
    nardmoseley, thank you for your reply.
    Would you be able to provide some code that could accomplish this please?
  • edited August 2019
    I created a form that will loop through each .rtm and save it. I changed the property in the report object to Format as ftASCII.

    So if I open it, then close it, it'll save with the property change. The problem I'm having is that when I try to run the report with our main application, the rtm is "broke" and won't run.

    So other properties are being set.

    Is there a way to open the .rtm and ONLY change the Format?


    procedure TForm1.Button1Click(Sender: TObject);
    var
    searchResult: TSearchRec;
    path : string;
    begin
    path := 'C:\Users\Public\Documents\Ocuco\RTMs\';

    if FindFirst(path + '*.rtm', faAnyFile, searchResult) = 0 then
    begin
    repeat
    ppReport1.Template.FileName := path + searchResult.Name;
    ppReport1.Template.LoadFromFile;
    ppReport1.Template.SaveToFile;
    until FindNext(searchResult) <> 0 ;

    end;

    FindClose(searchResult);

    end;
  • Hi Robert,

    If your main application is built with a prior version of RB, then it will not recognized new properties introduced/saved by RB 20.

    Possible Solutions
    - use the same older RB version as the main app to perform the template conversion.
    - update the main app to RB 20
    - update the main application to ignore errors when loading reports. To do this, set Report.Template.IgnoreErrors True.





    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
Sign In or Register to comment.