Best way to include lots of text? lazarus / 21-General ---------------------------------------------------------------------- domasz · 2023-06-04 10:03 How can I include lots of text? I can define strings like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Str := 'line' + #13#10 + 'second line';but that's terrible when I have thousands of line. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i I can do {$INCLUDE text.txt}but it needs to be a valid Pascal code. I can do: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i StringList.LoadFromFile('test.txt');but then I need to distribute this file with my exe. Is there a way to easily insert huge files of text into source code, like in PHP where I can just write: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $Str := 'linesecond linethird line';? ---------------------------------------------------------------------- jamie · 2023-06-04 10:31 create a unit that houses just your string and use a "ResourceString" It will be loaded in the resource but not in the binary and you can access when needed. ---------------------------------------------------------------------- domasz · 2023-06-04 10:38 But with ResourceString I still need to define value in this retarded way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 'line' + #13#10 + 'second line'; ---------------------------------------------------------------------- wp · 2023-06-04 11:00 Add the text as a resource: Project Options > Resources > Add > pick your text file and make sure that the resource type is RCDATA. Note that the filename will become the name of the resource - we need that in the code.In the OnCreate handler of the form (or when the text is needed), read the file from the resource into a TResourceStream and display it in a memo, or do whatever what you want to do with the text.Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  LCLType;  // for RT_RCDATA procedure TForm1.FormCreate(Sender: TObject);var  s: TResourceStream;  resName: String;begin  resName := '';  s := TResourceStream.Create(HINSTANCE, resName, RT_RCDATA);   try    Memo1.Lines.LoadFromStream(s);  finally    s.Free;  end;end; This way you can edit the text file whenever you need to, and it is always included automatically (well - you will have to do "run" > "build" to link the new version, though...). ---------------------------------------------------------------------- Swami With The Salami · 2023-06-04 15:22 Lots of text can mean a number of things - do you need to present hundreds of different pages in different areas or all of it at once? ---------------------------------------------------------------------- VTwin · 2023-06-04 19:42 Quote from: wp on June 04, 2023, 01:00:39 pmAdd the text as a resource: ... Nice solution. I just rewrote a help dialog to use it. ---------------------------------------------------------------------- KodeZwerg · 2023-06-04 20:54 Include a database with whatever text, easy to update IMHO. ---------------------------------------------------------------------- domasz · 2023-06-05 17:45 Quote from: wp on June 04, 2023, 01:00:39 pmAdd the text as a resource: Not great but thank you! ---------------------------------------------------------------------- domasz · 2023-06-05 17:46 Quote from: KodeZwerg on June 04, 2023, 10:54:51 pmInclude a database with whatever text, easy to update IMHO. Interesting, but a lot slower solution. ---------------------------------------------------------------------- 440bx · 2023-06-05 18:04 Quote from: domasz on June 05, 2023, 07:45:07 pmQuote from: wp on June 04, 2023, 01:00:39 pmAdd the text as a resource: Not great but thank you! Actually that solution is basically what you likened it to in PHP Quote from: domasz on June 04, 2023, 12:03:01 pmIs there a way to easily insert huge files of text into source code, like in PHP where I can just write: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i $Str := 'linesecond linethird line';? Once you get the pointer to the RCDATA resource you basically have a pointer to a string that is the entire text (probably a good idea to ensure the text is null terminated to make things simpler.) ---------------------------------------------------------------------- domasz · 2023-06-07 10:36 Quote from: 440bx on June 05, 2023, 08:04:27 pmOnce you get the pointer to the RCDATA resource you basically have a pointer to a string that is the entire text (probably a good idea to ensure the text is null terminated to make things simpler.) My problem here is with that "once". It would be so much better to just declare multiline strings in the source code and not add into resources and load. But this solution still seems like the best one. ---------------------------------------------------------------------- robert rozee · 2023-06-07 12:31 place your text in a file called mytext.txt then process it with the bin2obj utility provided with FPC: bin2obj -o mytext.inc -c mytext mytext.txt near the top of your program place the line: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$I mytext.inc} then within the body of your code have something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i textstring:='';for I:=low(mytext) to high(mytext) do   textstring:=textstring+chr(mytext[I]);where textstring is a string, and I is an integer. textstring will now contain your text, including line breaks. the downside of this approach is that your data will be held in memory twice - once as mytext[] and a second time as textstring. cheers, rob   :-) ---------------------------------------------------------------------- marcov · 2023-06-07 12:37 The fact that you describe the strings as "huge", makes resources the best option IMHO. ---------------------------------------------------------------------- Nicole · 2023-06-07 18:12 Depends of what you want to do with it and how huge is huge. I like to save the text as txt and import it by loadfromfile into a TStringList. *.rtf works fine as well. Search the forum for a really great tutorial how to implement it. Or you can use the odt-Format. Well, this is not easy, but very small as file. ---------------------------------------------------------------------- PascalDragon · 2023-06-08 10:43 Quote from: domasz on June 07, 2023, 12:36:51 pmQuote from: 440bx on June 05, 2023, 08:04:27 pmOnce you get the pointer to the RCDATA resource you basically have a pointer to a string that is the entire text (probably a good idea to ensure the text is null terminated to make things simpler.) My problem here is with that "once". It would be so much better to just declare multiline strings in the source code and not add into resources and load. But this solution still seems like the best one. Even if FPC would support multiline strings, resources should still be preferred, because it allows you to use whatever suitable editor there is for your data while that isn't easily possible if the data is embedded in a Pascal source file. ---------------------------------------------------------------------- BobDog · 2023-06-08 15:06 An include file works fine, you only need two lines to declare the string ... nope... I got it wrong ---------------------------------------------------------------------- Thaddy · 2023-06-08 15:13 Akira1264 is or was working on this. I don't know if it is finished yet: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i https://forum.lazarus.freepascal.org/index.php?topic=46050.30And fpc- develop mailing list. ---------------------------------------------------------------------- PascalDragon · 2023-06-08 16:14 Quote from: Thaddy on June 08, 2023, 05:13:13 pmAkira1264 is or was working on this. I don't know if it is finished yet: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i https://forum.lazarus.freepascal.org/index.php?topic=46050.30And fpc- develop mailing list. It's done and would simply need reintegration. However I won't do so until I've found the time to also finish the patch for $IncludeStringFile directive as a more sane alternative.