Bookstore

Recent

Author Topic: How do you convert LFM-to-PAS at runtime?  (Read 193 times)

vfclists

  • Hero Member
  • *****
  • Posts: 827
    • HowTos Considered Harmful?
How do you convert LFM-to-PAS at runtime?
« on: February 17, 2020, 07:45:21 pm »
There is this video on youtube https://www.youtube.com/watch?v=M250unH3Ltw that according to the uploader shows how convert the state of the form to a pascal file.

It isn't very clear according to thes mailing list thread https://lists.freepascal.org/pipermail/pas2js/2018-April/000182.html it uses  the TCompWriterPas class.

Does any one have working examples of the use of this class?
Windows - Lazarus 1.0.8/FPC 2.6.0
Linux - Lazarus 1.4.4 /FPC 2.6.4

howardpc

  • Hero Member
  • *****
  • Posts: 3358
Re: How do you convert LFM-to-PAS at runtime?
« Reply #1 on: February 17, 2020, 08:29:36 pm »
There is some code in the Lazarus sources at
$LazarusDir/components/codetools/tests/testcompreaderwriterpas.pas

eljo

  • Full Member
  • ***
  • Posts: 181
Re: How do you convert LFM-to-PAS at runtime?
« Reply #2 on: February 17, 2020, 08:54:50 pm »
Code: Pascal  [Select]
  1. uses CompWriterPas, ....
  2. procedure TForm1.MenuItem7Click(Sender: TObject) ;
  3. var
  4.   Strm:TFileStream;
  5. begin
  6.   if SaveDialog1.Execute then begin
  7.     Strm := TFileStream.Create(SaveDialog1.FileName,fmCreate or fmShareExclusive);
  8.     try
  9.       WriteComponentToPasStream(self, Strm);
  10.     finally
  11.       Strm.Free;
  12.     end ;
  13.   end;
  14. end;      
  15.  

dsiders

  • Sr. Member
  • ****
  • Posts: 280
Re: How do you convert LFM-to-PAS at runtime?
« Reply #3 on: February 17, 2020, 08:55:29 pm »
There is some code in the Lazarus sources at
$LazarusDir/components/codetools/tests/testcompreaderwriterpas.pas

And in:

examples/pascalstream/CopyAsPasPkg/copyaspasdemounit1.pas:
Lazarus 2.0.6 / Lazarus 2.1 (SVN) / FPC 3.0.4 / Windows 8.1 64-bit