?
Solved

Using Writeln to create text file in delphi

Posted on 2008-06-25
6
Medium Priority
?
3,156 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 38

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 38

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
Technology Partners: 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 38

Accepted Solution

by:
Geert Gruwez earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

764 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