#1 2018-07-04 17:18:45

wai-kit
Member
From: Amsterdam, the Netherlands
Registered: 2012-11-27
Posts: 90

Persist a TDocVariant object

Hi all,

Can anybody help me with this?
How do I persist a TDocVariant object to a file?
Let's say I have this code:

aTemplate:variant;

TDocVariant.New(aTemplate);

aTemplate.Subject := 'some Subject';
aTemplate.Description := 'some Description';

// Persist aTemplate to file ...something like SaveToFile(someFileName);

Any help in the right direction much appreciated.

Cheers,
Wai

Last edited by wai-kit (2018-07-04 17:27:06)


fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...

Offline

#2 2018-07-04 18:22:02

5c4f394a
Member
Registered: 2013-03-22
Posts: 11

Re: Persist a TDocVariant object

wai-kit wrote:

Hi all,

Can anybody help me with this?
How do I persist a TDocVariant object to a file?
Let's say I have this code:

aTemplate:variant;

TDocVariant.New(aTemplate);

aTemplate.Subject := 'some Subject';
aTemplate.Description := 'some Description';

// Persist aTemplate to file ...something like SaveToFile(someFileName);

Any help in the right direction much appreciated.

Cheers,
Wai

procedure TForm1.Button1Click(Sender: TObject);
var
  aTemplate: Variant;
begin
  TDocVariant.New(aTemplate);
  aTemplate.Subject := 'some Subject';
  aTemplate.Description := 'some Description';

  Memo1.Lines.Add( aTemplate );
  // {"Subject":"some Subject","Description":"some Description"}
  Memo1.Lines.Add( aTemplate.Subject );
  // some Subject
  Memo1.Lines.Add( aTemplate.Description );
  // some Description

  FileFromString( aTemplate, 'test.txt' );
  // {"Subject":"some Subject","Description":"some Description"}
end;

Offline

#3 2018-07-04 22:35:45

wai-kit
Member
From: Amsterdam, the Netherlands
Registered: 2012-11-27
Posts: 90

Re: Persist a TDocVariant object

Thank you very much for the help!!
That did the trick.


fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...

Offline

Board footer

Powered by FluxBB