Page 1 of 1

TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Posted: Tue May 12, 2020 10:53 pm
by Vitalii
Hi Sergey,
can you add something like that in TRVStyleTemplateCollection?

function TRVStyleTemplateCollection.SaveToStreamRVST(Stream: TStream; Units: TRVStyleUnits): Boolean;
var
ini: TMemIniFile;
begin
Result := False;
try
ini := TMemIniFile.Create(Stream, TEncoding.UTF8);
try
ini.EraseSection(STYLETEMPLATEINISECTION);
SaveToINI(ini, STYLETEMPLATEINISECTION);
ini.WriteInteger(STYLETEMPLATEINISECTION, RVINI_UNITS, Ord(Units));
ini.UpdateFile;
finally
ini.Free;
end;
Result := True;
except
end;
end;

function TRVStyleTemplateCollection.LoadFromStreamRVST(Stream: TStream; Units: TRVStyleUnits; ARVStyle: TRVStyle = nil): Boolean;
var
ini: TMemIniFile;
FileUnits: TRVStyleUnits;
begin
Result := False;
try
ini := TMemIniFile.Create(Stream, TEncoding.UTF8);
try
LoadFromINI(ini, STYLETEMPLATEINISECTION);
FileUnits := TRVStyleUnits(ini.ReadInteger(STYLETEMPLATEINISECTION,
RVINI_UNITS, Ord(rvstuPixels)));
UpdateReferences;
finally
ini.Free;
end;
if FileUnits <> Units then
begin
if ARVStyle = nil then
ARVStyle := FOwner as TRVStyle;
ConvertToDifferentUnits(ARVStyle, FileUnits, Units);
end;
Result := True;
except
end;
end;

For now I add this code manually in every engine update. It would be great to see this methods in next release of TRichView :)

Re: TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Posted: Sun May 17, 2020 8:51 pm
by Sergey Tkachenko
Ok, I'll add it in the next update.

Re: TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Posted: Mon May 18, 2020 11:13 am
by Sergey Tkachenko
I did not know that TMemIniFile can be linked to a stream. I checked, this feature was added in RAD Studio 10.3

Re: TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Posted: Sat Jun 06, 2020 8:32 am
by Vitalii
Thank you, Sergey!
>> I did not know that TMemIniFile can be linked to a stream. I checked, this feature was added in RAD Studio 10.3
work correctly with 10.2, don’t know for earlier versions

Re: TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Posted: Sat Jun 06, 2020 10:12 am
by Sergey Tkachenko
It's strange. In 10.2 source, I can see 3 constructors for TMemIniFile, all of them has FileName, not Stream parameter.

"ini.UpdateFile" code required!

Posted: Sun Jun 28, 2020 6:46 pm
by Vitalii
Hi Sergey,
method SaveToStreamRVST does not save data in ini file. To save the data, at the end of the operation you need to call the method "ini.UpdateFile":
...
try
ini.EraseSection(STYLETEMPLATEINISECTION);
SaveToINI(ini, STYLETEMPLATEINISECTION);
ini.WriteInteger(STYLETEMPLATEINISECTION, RVINI_UNITS, Ord(Units));
ini.UpdateFile; // <<<----- THIS CODE REQUIRED
finally
ini.Free;
end;
...

Re: TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Posted: Thu Jul 02, 2020 11:49 am
by Sergey Tkachenko
Thank you! It is fixed in TRichView v18.5.1