Recent

Author Topic: How to append a text file to a TMemo?  (Read 26830 times)

Elmug

  • Hero Member
  • *****
  • Posts: 849
How to append a text file to a TMemo?
« on: September 10, 2011, 07:30:21 am »
Good people,

I would appreciate advice on a quick way to append a complete text-file to the existing contents of a TMemo.

Thanks!

eny

  • Hero Member
  • *****
  • Posts: 1634
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: How to append a text file to a TMemo?
« Reply #2 on: September 10, 2011, 09:55:42 pm »
http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tmemo.html
http://lazarus-ccr.sourceforge.net/docs/rtl/classes/tstringlist.html
LoadFromFile()
Append()

Thanks Eny.

I am wondering if there is a higher level way of doing the operation since we are talking about complete 'sets' of data and sometimes I've been happily surprised that there are "methods" beyond the usual "line-at a time" ways.

If you happen to know of any, would appreciate your mentioning them.

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: How to append a text file to a TMemo?
« Reply #3 on: September 10, 2011, 11:55:40 pm »
I am wondering if there is a higher level way of doing the operation
FPC is a programming language, not a magic wand.

Quote
since we are talking about complete 'sets' of data
I thought we were talking about text files?

Quote
and sometimes I've been happily surprised that there are "methods" beyond the usual "line-at a time" ways.
I never mentioned line at a time  %)
Just load the text in a stringlist and append the Text of the stringlist to the memo's strings with Append.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: How to append a text file to a TMemo?
« Reply #4 on: September 11, 2011, 01:03:34 am »
FPC is a programming language, not a magic wand.
Quote

Hi Eny,

and thanks for correcting what I don't think.

Looks like I'll have to write my own functions, like MemoToFile and FileToMemo.

And, by the way, "sets" has many meanings, verifiable at a dictionary. We can't just speak in Pascal.

Thanks for helping-out, anyway!

dkjMusic

  • Full Member
  • ***
  • Posts: 146
Re: How to append a text file to a TMemo?
« Reply #5 on: September 11, 2011, 03:34:43 am »
Google is your friend. The following is from the first hit of a Google search for "memo load from file example." The site is http://www.delphibasics.co.uk/, an invaluable resource for me.

------------------------------------------------------------------------------------------------
The TStringList class is a very useful utility class that works on a list of strings, each indexable like an array. The list can be sorted, and supports name/value pair strings, allowing selection by name or value.
    
   These lists can be furnished from text files in one fell swoop. Here we show a TStringList object being created, and loaded from a file:
    
 var
   fileData : TStringList;                // Our TStringList variable
 begin
   fileData := TStringList.Create;        // Create the TSTringList object
   fileData.LoadFromFile('Testing.txt');  // Load from Testing.txt file
   ...

   We can display the whole file in a Memo box:
   
   memoBox.Text := fileData.Text;
------------------------------------------------------------------------------------------------

Can you guess the method for saving text to a file?  ;)
Windows 7 Ultimate/32 bit;
Lazarus 0.9.31/Rev 33300;
FPC 2.7.1/Rev 19464;
GDB 7.0.50;
(via CodeTyphon 2.30)

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: How to append a text file to a TMemo?
« Reply #6 on: September 11, 2011, 12:45:06 pm »
and thanks for correcting what I don't think.
I'm an IT specialist in the field of business analysis and design, I do not make assumptions on what other people might think.
Please try to understand the answers in relation to your topic question.

Quote
Looks like I'll have to write my own functions, like MemoToFile and FileToMemo.
FPC is a toolbox, not a collection of applications that do the work for you.
If you want to drive a screw, you'll need a screwdriver but you still have to handle the screwdriver yourself.

Quote
And, by the way, "sets" has many meanings, verifiable at a dictionary. We can't just speak in Pascal.
Of course, that's why you have to provide us with context in which you see your 'set'.

Quote
Thanks for helping-out, anyway!
Based on your question I have given you all the tools you need:
- create a TStringList object like 'O := TStringList.Create';
- load the textfile you wish to add: O.LoadFromFile(<your textfile>);
- append it to the memo: Memox.Append(O.Text).


All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Rails

  • Guest
Re: How to append a text file to a TMemo?
« Reply #7 on: September 11, 2011, 12:54:24 pm »
Google is your friend. The following is from the first hit of a Google search for "memo load from file example." The site is http://www.delphibasics.co.uk/, an invaluable resource for me.

Thanks for mentioning delphibasics. It looks like a very handy resource.


Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: How to append a text file to a TMemo?
« Reply #8 on: September 11, 2011, 09:05:53 pm »
I'm an IT specialist in the field of business analysis and design

I don't recall asking about this. Bu thanks for the information, anyway. :)

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: How to append a text file to a TMemo?
« Reply #9 on: September 11, 2011, 09:38:56 pm »
I don't recall asking about this
I don't recall this being a homework assignment forum.
So please start reading the manuals or at least show signs that you really do something with the information that is given to you, when you ask questions.
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: How to append a text file to a TMemo?
« Reply #10 on: September 12, 2011, 05:44:37 pm »
I don't recall asking about this
I don't recall this being a homework assignment forum.
So please start reading the manuals or at least show signs that you really do something with the information that is given to you, when you ask questions.

There you go again, Eny: imagining home-works, assignments, and demanding things from others when volunteering.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: How to append a text file to a TMemo?
« Reply #11 on: September 12, 2011, 05:54:41 pm »
For what i can follow this thread (it's still not solved?), it now seems like misunderstanding of something...

Thanks Eny.

I am wondering if there is a higher level way of doing the operation since we are talking about complete 'sets' of data and sometimes I've been happily surprised that there are "methods" beyond the usual "line-at a time" ways.

If you happen to know of any, would appreciate your mentioning them.
The first reply from Eny in the thread already gave you a high level way, not "line-at a time" method. Only thing that's still missing is is full source code to spoil the challenge  :P  Did you try the answers given earlier?

You asked:
Quote
a quick way to append a complete text-file to the existing contents of a TMemo.
This code does it:
Code: [Select]
var sl: TStringList;
begin
  sl:=TStringList.Create;
  sl.LoadFromFile('Textfile.txt');
  memo1.Lines.Add(sl.Text); // Or try Append() here, or add sl.Text to memo1.lines.text
  sl.Free;
end;
« Last Edit: September 13, 2011, 10:23:44 am by User137 »

TurboRascal

  • Hero Member
  • *****
  • Posts: 672
  • "Good sysadmin. Bad programmer."™
Re: How to append a text file to a TMemo?
« Reply #12 on: September 12, 2011, 10:11:55 pm »
@Elmug, eny gave you exactly what you asked for, I guess you should be thankful instead of hostile...
Regards, ArNy the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: How to append a text file to a TMemo?
« Reply #13 on: September 13, 2011, 12:49:47 am »
@Elmug, eny gave you exactly what you asked for, I guess you should be thankful instead of hostile...

Thanks for replying, but the information that Eny linked to is not what I wanted and I already thank him for that.

Shebuka

  • Sr. Member
  • ****
  • Posts: 427
Re: How to append a text file to a TMemo?
« Reply #14 on: September 13, 2011, 03:11:15 pm »
@Elmug, eny gave you exactly what you asked for, I guess you should be thankful instead of hostile...

Thanks for replying, but the information that Eny linked to is not what I wanted and I already thank him for that.
eny linked you all the thing you need to: "append a complete text-file to the existing contents of a TMemo". The part of reading that links, understand what functions do by their descriptions and mnemonic names, power up the brain and then write YOUR code, is YOUR part. You can't ask us to code for you all simplest thing you need...
If you just known things eny linked, then YOU can post that code and say something like "i know how to do this in this way, is there a better and/or shorter and/or faster method?".

My post is not really related to this particular thread, but to all that one started by you which quite always are resolved by pointing you to a particular manual page, so in definitive: RTFM (if you don't know what it means, don't ask it here, google it).

 

TinyPortal © 2005-2018