Solved

Using Writeln to create text file in delphi

Posted on 2008-06-25
6
3,139 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now