TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

General TRichView support forum. Please post your questions here
Post Reply
Vitalii
Posts: 61
Joined: Sat Oct 20, 2018 2:55 pm

TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Post 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 :)
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Post by Sergey Tkachenko »

Ok, I'll add it in the next update.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Post 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
Vitalii
Posts: 61
Joined: Sat Oct 20, 2018 2:55 pm

Re: TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Post 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
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Post 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.
Vitalii
Posts: 61
Joined: Sat Oct 20, 2018 2:55 pm

"ini.UpdateFile" code required!

Post 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;
...
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVStyleTemplateCollection : SaveToStreamRVST, LoadFromStreamRVST

Post by Sergey Tkachenko »

Thank you! It is fixed in TRichView v18.5.1
Post Reply