User written content in text file writer. lazarus / 11-Options ---------------------------------------------------------------------- magicpants · 2015-06-18 16:11 Hello. I have a school project to do with Lazarus, but I have a problem. I have a Survey, so I want to store the information somehow, so I thought about creating a text file and storing it there, it wasn't that hard, until I wanted to write the information that user entered in the text file... (how do I do that?) Code: [Select]program project1; {$mode objfpc}{$H+} uses   Sysutils,   {$IFDEF UNIX}{$IFDEF UseCThreads}   cthreads,   {$ENDIF}{$ENDIF}   Interfaces, // this includes the LCL widgetset   Forms, Unit1   { you can add units after this }; {$R *.res} var   f:textfile; begin   RequireDerivedFormResource := True;   Application.Initialize;   Application.CreateForm(TfrmSurvey, frmSurvey);   Application.Run;   assignfile(f, 'Submited.txt');   rewrite(f);   close(f);   //   writeln(f, 'Hello') + edtName; end.      I want to enter information that user entered via tEdit. It doesn't seem to work, what's wrong? I tried to use + edtName.Text; but it didn't work either. Thank you! P.S. Is it possible that the text file would be written when certain assigned button is clicked, and not when the application is closed? ---------------------------------------------------------------------- howardpc · 2015-06-18 17:03 Don't add code to your project's .lpr file. Use the survey unit. One very simple way to enter and save the data as text would be to use a memo control. Drop a memo on that form, called MemoSurvey. Add a Save button, and in the OnClick event of the Save button add some variation of this to suit your case: Code: [Select]procedure  TfrmSurvey.ButtonSaveClick(Sender: TObject); begin   MemoSurvey.Lines.SaveToFile('surveydata.txt'); end; ---------------------------------------------------------------------- magicpants · 2015-06-18 17:37 Thank you for your answer. But I get an error when I try to plug this code in. Code: [Select]unit1.pas(248,13) Error: identifier idents no member "Lines" I plug in: Code: [Select] frmSurvey.Lines.SaveToFile('surveydata.txt'); What's up with that 'Lines'? ---------------------------------------------------------------------- Michl · 2015-06-18 19:22 I hope, this page is helpful for you: http://wiki.freepascal.org/TMemo#Save_and_load ---------------------------------------------------------------------- howardpc · 2015-06-18 21:29 Quote from: magicpants on June 18, 2015, 07:37:13 pmThank you for your answer. But I get an error when I try to plug this code in. Code: [Select]unit1.pas(248,13) Error: identifier idents no member "Lines" I plug in: Code: [Select] frmSurvey.Lines.SaveToFile('surveydata.txt'); What's up with that 'Lines'? you needCode: [Select]  frmSurvey.MemoSurvey.Lines.SaveToFile('surveydata.txt'); Replace MemoSurvey with the name you've given to your memo (if you use the default it will be Memo1). ---------------------------------------------------------------------- magicpants · 2015-06-20 07:00 Thank you guys  Although, I have a question again. Is it possible to make the TMemo only edit the text file, not to save it? That I could save answers from multiple people in one .txt file? Or maybe that if there's already a file for example 'survey.txt' it would create 'survey1.txt' and so on. Thank you ---------------------------------------------------------------------- howardpc · 2015-06-20 09:51 As you extend the functionality of your project, you need more and more the features provided by a relational database. So you have a design decision: do I start using a database (programmed by someone else - so I will need to learn how to program and use it), or do I roll my own database-type functionality to store and retrieve increasingly complex data? Either route will be a useful learning experience.