Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
reading whole file into Memo field Posted by ucbones on 21 Jul 2003 at 12:10 PM
Hi,

Many thanks for your helpful responses thus far. My next question is, how do I read a whole text file into a memo field?

At present, my code is:

if FileExists('entries/1.jnl') then
begin
// Display the file contents
AssignFile(myFile, 'entries/1.jnl');
//open the file for reading
Reset(myFile);
while not Eof(myFile) do
begin
ReadLn(myFile, text);
MemoRecent.Text := text;
end;
// Close the file for the last time
CloseFile(myFile);
end
else
begin
MemoRecent.Text := '1.jnl does not appear to exist';
end;

But this obviously merely sets the memo to show the last section of the file (i.e. after the final newline). In PHP, which I am more familiar with, you can append things to strings.

i.e. $string="some text";
$string.=" some more text";
//$string now equals "some text some more text"

Is there an equivalent in Delphi?

Many thanks,

ucbones
Report
Re: reading whole file into Memo field Posted by zibadian on 21 Jul 2003 at 1:06 PM
: Hi,
:
: Many thanks for your helpful responses thus far. My next question is, how do I read a whole text file into a memo field?
:
: At present, my code is:
:
: if FileExists('entries/1.jnl') then
: begin
: // Display the file contents
: AssignFile(myFile, 'entries/1.jnl');
: //open the file for reading
: Reset(myFile);
: while not Eof(myFile) do
: begin
: ReadLn(myFile, text);
: MemoRecent.Text := text;
: end;
: // Close the file for the last time
: CloseFile(myFile);
: end
: else
: begin
: MemoRecent.Text := '1.jnl does not appear to exist';
: end;
:
: But this obviously merely sets the memo to show the last section of the file (i.e. after the final newline). In PHP, which I am more familiar with, you can append things to strings.
:
: i.e. $string="some text";
: $string.=" some more text";
: //$string now equals "some text some more text"
:
: Is there an equivalent in Delphi?
:
: Many thanks,
:
: ucbones
:
Check out the Lines.LoadFromFile() method in the help files.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.