Embedding text file into Lazarus resources error lazarus / 61-Beginners ---------------------------------------------------------------------- Paloski · 2017-08-18 14:55 Hi, I have an application consisting of a TForm1, TMemo, TButton and TRadioButton . I want to display text from a .txt file in the TMemo when TRadioButton is selected and TButton copies all text in TMemo. I can do this with LoadFromFile however, now I want to "embed" the .txt file into my program so I don't have Read/write text files exposed for people to modify. I was able to follow the tutorial below: http://wiki.freepascal.org/Lazarus_Resources I successfully created an embedded Image file by using glazres to create a .lrs file however, now I want to embed a .txt file and I receive the error below: Compile Project, Target: project1.exe: Exit code 1, Errors: 1, Warnings: 2 Warning: windres [option(s)] [input-file] [output-file] Warning: windres: supported targets: pe-i386 pei-i386 elf32-i386 elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex Error: Error while compiling resources -> Compile with -vd for more details. Check for duplicates. Here is my code: 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 unit Unit1; {$mode objfpc}{$H+}{$R *.lfm}{$R stuff.rc}interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,  ExtCtrls, Windows;type  { TForm1 }  TForm1 = class(TForm)  Button1: TButton;    Memo1: TMemo;    RadioButton1: TRadioButton;    procedure Button1Click(Sender: TObject);    procedure RadioButton1Change(Sender: TObject);  private    { private declarations }  public    { public declarations }  end; var  Form1: TForm1;  memo1: String;  Data: String;  RStream: TResourceStream;implementation{ TForm1 }procedure TForm1.Button1Click(Sender: TObject);begin  Memo1.SelectAll;  Memo1.CopyToClipboard;end; procedure TForm1.RadioButton1Change(Sender: TObject);begin  RStream := TResourceStream.Create(HInstance, 'awe', RT_RCDATA);  memo1.lines.LoadFromStream(RStream);  end; end.          For the life of me I can't figure it out... seems to be something wrong with windres making the .res file? Any help/suggestions will be greatly appreciated thanks. Windows 10 x64 Lazarus IDE v1.6.4 ---------------------------------------------------------------------- RAW · 2017-08-18 17:33 The easiest way to get text into the exe-file is 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 UNIT Unit1; {$MODE OBJFPC}{$H+}{$J-} Interface USES  Classes, SysUtils, Forms, Controls, StdCtrls;  TYPE  TForm1 = Class(TForm)    radBtnText: TRadioButton;   memo      : TMemo;   btn       : TButton;    Procedure FormCreate       (Sender: TObject);   Procedure btnClick         (Sender: TObject);   Procedure radBtnTextChange (Sender: TObject);   PRIVATE     strData: String;     //resStream: TResourceStream;  End;  VAR  Form1: TForm1; Implementation {$R *.LFM}  Procedure TForm1.FormCreate(Sender: TObject); Begin  // copy&paste your text into a memo...  strData:= memo.Text;  //memo.Free; if you don't need the memo anymore...   memo.Text:= 'LAZARUS forever and forever and forever ...'; End;  Procedure TForm1.btnClick(Sender: TObject); Begin  memo.SelectAll;  memo.CopyToClipboard; End;  Procedure TForm1.radBtnTextChange(Sender: TObject); Begin  memo.Text:= strData; End; END. ---------------------------------------------------------------------- Cyrax · 2017-08-18 17:54 Make sure that you don't have spaces or special characters (unicode) in your project directory path. ---------------------------------------------------------------------- Paloski · 2017-08-18 18:36 Thanks for the help. I found a way to get it working by using a text file and cleaned up a bit: 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 unit Unit1; {$mode objfpc}{$H+}{$R 'stuff.RC'}interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,  ExtCtrls, LResources, Windows; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Memo1: TMemo;    RadioButton1: TRadioButton;    procedure Button1Click(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure RadioButton1Change(Sender: TObject);  private    { private declarations }  public    { public declarations }  end; var  Form1: TForm1;  RStream: TResourceStream;implementation {$R *.lfm} { TForm1 }   procedure TForm1.Button1Click(Sender: TObject);begin  Memo1.SelectAll;  Memo1.CopyToClipboard;end; procedure TForm1.FormCreate(Sender: TObject);begin memo1.clear;end;  procedure TForm1.RadioButton1Change(Sender: TObject);begin  RStream := TResourceStream.Create(HInstance, 'awe', RT_RCDATA);  memo1.lines.LoadFromStream(RStream);  end;end. ---------------------------------------------------------------------- Thaddy · 2017-08-18 18:40 You mean: 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   RStream := TResourceStream.Create(HInstance, 'awe', RT_RCDATA);  try      memo1.lines.LoadFromStream(RStream);  finally     RStream.free;  end; ---------------------------------------------------------------------- RAW · 2017-08-18 19:04 YOU MEAN THIS... 1. USE Project: Project Options: Resources     Right now it's 2017 !!! rc and res files are STONE AGE FUCKSHIT !!!!  2. USE 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 UNIT Unit1; {$MODE OBJFPC}{$H+}{$J-} Interface USES  Classes,  SysUtils, Forms, LCLType,  Controls, StdCtrls;  TYPE  TForm1 = Class(TForm)    radBtnText: TRadioButton;   memo      : TMemo;   btn       : TButton;    Procedure FormCreate       (Sender: TObject);   Procedure btnClick         (Sender: TObject);   Procedure radBtnTextChange (Sender: TObject);     PRIVATE     strData: String;  End;  VAR  Form1: TForm1; Implementation {$R *.LFM}  Procedure TForm1.FormCreate(Sender: TObject);  Var   resStream: TResourceStream; Begin  // copy&paste your text into a memo...  // strData:= memo.Text;  // memo.Free; if you don't need the memo anymore...   resStream:= TResourceStream.Create(HInstance, 'HELLO', RT_RCDATA);   Try    SetLength(strData, resStream.Size);    resStream.Read(strData[1], resStream.Size);   Finally    resStream.Free;   End;   memo.Text:= 'LAZARUS forever and forever and forever ...'; End;  Procedure TForm1.btnClick(Sender: TObject); Begin  memo.SelectAll;  memo.CopyToClipboard; End;  Procedure TForm1.radBtnTextChange(Sender: TObject); Begin  memo.Text:= strData; End; END. 3. Don't use global variables ... (only if absolutely necessary !!!). ---------------------------------------------------------------------- eny · 2017-08-18 20:26 Quote from: RAW on August 18, 2017, 09:04:21 pm1. USE Project: Project Options: Resources     Right now it's 2017 !!! rc and res files are STONE AGE ****SHIT !!!! If that were to work reliably it would be a nice solution. Unfortunately changes in resources defined like that are not always picked up correctly. ---------------------------------------------------------------------- RAW · 2017-08-18 21:58 QuoteUnfortunately changes in resources defined like that are not always picked up correctly. Thanks for the info... I didn't know that... (I keep that in mind...). The example works nice, but that doesn't mean it will always work correctly... Normally I don't put everything into the exe-file, I like the idea that the user can change for example PNG's if he really want to.. of course it depends on the program and the purpose... Some people think if they store data inside a executable then nobody can access or change it... ..far from the truth... I don't see a big difference in one exe-file or one zip-file or 7z-file or whatever format... but of course everybody can do it as he/she likes. EDIT: If there are problems after a path change for one res-file, then it can be useful to delete the lib-folder and the *.exe and *.dgb file. That solved my problem once...  EDIT II: Now I know why rc-files didn't work: I tried all this with 1.6.4 FPC 3.0.2... obviously a bug... No problem at all with 1.8: RC-File: MyRes.rc: HELLO RCDATA Hello.txt Unit: {$R MyRES.RC} This way it's easy enough... I don't like to precompile a *.res file or *.lrs-file... and this way there is nothing to change if I change some files... That's nice...