Solved

Using Writeln to create text file in delphi

Posted on 2008-06-25
6
3,149 Views
Last Modified: 2013-11-23
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
Comment
Question by:Kevinfeening
  • 3
  • 3
6 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21871957
only use the write instead of writeln
the file ends with #26
0
 

Author Comment

by:Kevinfeening
ID: 21871998
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
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21872106
#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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Kevinfeening
ID: 21872305
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
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 21872361
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
 

Author Closing Comment

by:Kevinfeening
ID: 31470863
Thanks for you help I will try this on site should be ok i hope
thanks again
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question