Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3162
  • Last Modified:

Using Writeln to create text file in delphi

I am using Writeln for create a text file in delphi 5 and packing it to 628 charactors
The writeln option adds a CRLF at the end of each line (as far as I have read)
error .. On some computers the last line looses the CRLF

txtline := 'Testline1';
l := length(txtline)
for i := l to 628 do begin
    txtline := txtline + ' ';
end;
txtline := 'Testline2';
l := length(txtline)
for i := l to 628 do begin
    txtline := txtline + ' ';
end;

any suggestions how I can fix this
0
Kevinfeening
Asked:
Kevinfeening
  • 3
  • 3
1 Solution
 
Geert GruwezOracle dbaCommented:
only use the write instead of writeln
the file ends with #26
0
 
KevinfeeningAuthor Commented:
Thanks
But the file has to end with - CRLF #13#10 or the government department wont accept it

I am not sure what #26 is
0
 
Geert GruwezOracle dbaCommented:
#26 is the End Of File marker

did you try the TStringList approach ?
and the format routine ?




procedure CreateGovFile(FileName: string);
var List: TStrings;
begin
  List := TStringList.Create;
  try
    List.Add(Format('%-628.s', ['TestLine1']));
    List.Add(Format('%-628.s', ['TestLine2']));
    List.SaveToFile(FileName);
  finally
    FreeAndNil(List); 
  end;
end;

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
KevinfeeningAuthor Commented:
I copied and pasted the code you sent me and the file was created by with noting in it - no records
Testline1 or 2
0
 
Geert GruwezOracle dbaCommented:
silly points ...
procedure CreateGovFile(FileName: string);
var List: TStrings;
begin
  List := TStringList.Create;
  try
    List.Add(Format('%-628s', ['TestLine1']));
    List.Add(Format('%-628s', ['TestLine2']));
    List.SaveToFile(FileName);
  finally
    FreeAndNil(List); 
  end;
end;

Open in new window

0
 
KevinfeeningAuthor Commented:
Thanks for you help I will try this on site should be ok i hope
thanks again
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now