How to append a text file to a TMemo? lazarus / 31-LCL ---------------------------------------------------------------------- Elmug · 2011-09-10 05:30 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 · 2011-09-10 06:56 http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tmemo.html http://lazarus-ccr.sourceforge.net/docs/rtl/classes/tstringlist.html LoadFromFile() Append() ---------------------------------------------------------------------- Elmug · 2011-09-10 19:55 Quote from: eny on September 10, 2011, 08:56:51 amhttp://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 · 2011-09-10 21:55 Quote from: Elmug on September 10, 2011, 09:55:42 pmI am wondering if there is a higher level way of doing the operation FPC is a programming language, not a magic wand. Quotesince we are talking about complete 'sets' of data I thought we were talking about text files? Quoteand 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. ---------------------------------------------------------------------- Elmug · 2011-09-10 23:03 Quote from: eny on September 10, 2011, 11:55:40 pmFPC 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 · 2011-09-11 01:34 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? ---------------------------------------------------------------------- eny · 2011-09-11 10:45 Quote from: Elmug on September 11, 2011, 01:03:34 amand 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. QuoteLooks 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. QuoteAnd, 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'. QuoteThanks 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(); - append it to the memo: Memox.Append(O.Text). ---------------------------------------------------------------------- Rails · 2011-09-11 10:54 Quote from: dkjMusic on September 11, 2011, 03:34:43 amGoogle 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 · 2011-09-11 19:05 Quote from: eny on September 11, 2011, 12:45:06 pmI'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 · 2011-09-11 19:38 Quote from: Elmug on September 11, 2011, 09:05:53 pmI don't recall asking about thisI 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. ---------------------------------------------------------------------- Elmug · 2011-09-12 15:44 Quote from: eny on September 11, 2011, 09:38:56 pmQuote from: Elmug on September 11, 2011, 09:05:53 pmI don't recall asking about thisI 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 · 2011-09-12 15:54 For what i can follow this thread (it's still not solved?), it now seems like misunderstanding of something... Quote from: Elmug on September 10, 2011, 09:55:42 pmThanks 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    Did you try the answers given earlier? You asked: Quotea 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; ---------------------------------------------------------------------- TurboRascal · 2011-09-12 20:11 @Elmug, eny gave you exactly what you asked for, I guess you should be thankful instead of hostile... ---------------------------------------------------------------------- Elmug · 2011-09-12 22:49 Quote from: TurboRascal 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... Thanks for replying, but the information that Eny linked to is not what I wanted and I already thank him for that. ---------------------------------------------------------------------- Shebuka · 2011-09-13 13:11 Quote from: Elmug on September 13, 2011, 12:49:47 amQuote from: TurboRascal 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... 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). ---------------------------------------------------------------------- Elmug · 2011-09-13 13:30 Quote from: Shebuka on September 13, 2011, 03:11:15 pmQuote from: Elmug on September 13, 2011, 12:49:47 amQuote from: TurboRascal 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... 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). Of course, everything can resolve to manual pages FOR EVERYONE. I am no exception. However, the pages than Eny linked I was already aware of and that's not what I wanted. I have the right to ask any thing I happen to be ignorant about, confused about, or have forgotten about,  just like others have the right not to wish to volunteer to answer. Now if people think they know everything, and that gives them rights to judge others, that's something else. Besides, it would be presumptuous for anyone to believe that manuals of any kind are perfectly clear, complete,  unambiguous, or so simple to interpret for anyone, on any thing. If it were so, then the job would be done long since, and there would be no need for this forum, don't you think? ---------------------------------------------------------------------- felipemdc · 2011-09-13 13:38 Quote from: Elmug on September 13, 2011, 03:30:49 pmHowever, the pages than Eny linked I was already aware of and that's not what I wanted. It seams that you want a one-liner to append text from a file to a TMemo. The answer is: It does not exist. If you want to have one, just create a routine for that: procedure AppendTextFileToTMemo(AFilename: string; ADestMemo: TMemo); And implement it. And about the rest of the discussion, lets stop it right here. ---------------------------------------------------------------------- Elmug · 2011-09-13 14:23 Quote from: felipemdc on September 13, 2011, 03:38:25 pmQuote from: Elmug on September 13, 2011, 03:30:49 pmHowever, the pages than Eny linked I was already aware of and that's not what I wanted. It seams that you want a one-liner to append text from a file to a TMemo. The answer is: It does not exist. If you want to have one, just create a routine for that: procedure AppendTextFileToTMemo(AFilename: string; ADestMemo: TMemo); And implement it. And about the rest of the discussion, lets stop it right here. Thanks for understanding, Felipe. I already did the suggested, actually 3 procedures, a while back. I just did not want to re-invent the wheel and be dumb by not asking.