Solved

Using Writeln to create text file in delphi

Posted on 2008-06-25
6
3,153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

717 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