Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

reading whole file into Memo field

ucbonesucbones Posts: 4Member
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

Comments

  • zibadianzibadian Posts: 6,349Member
    : 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.
Sign In or Register to comment.