acFileStorage equivalent
searching for a vcl that can enable embed any files within dfm similar to acfilestorage
When there are bugs with the file naming, then the porting wasn't completely done. The problem with "malformed" strings is still always the same. A string is treated as ANSI, but since Delphi 2009 the strings in Delphi has the Unicode format. What means, a string of Length 5 needs 10 bytes to store. Another typical fault is to treat a Unicode Buffer as ANSI. Such things leads always into "malformed" strings.
Now, you need to change the way the file name is stored. The function "WriteStream(…)" should be something like this…
procedure TStoredFile.WriteData(Stream: TStream);
var
Buffer: TArray<Byte>;
TheSize: Cardinal;
Target: Pointer;
begin
// storing the file name
Buffer := TEncoding.UTF8.GetBytes(FFileName); <- The filename is converted to UTF8…
TheSize := Length(Buffer);
Stream.Write(TheSize, 4);
Stream.Write(Buffer, 0, TheSize); <- …and the bytes will be written // pack and write data
TheSize := SFCalcTargetSz(FSize); // calculate required size for taget buffer
GetMem(Target, TheSize);
try
TheSize := SFPack(FData.Memory, Target, FSize);
Stream.Write(TheSize, 4); // compressed size
Stream.Write(Target^, TheSize); // original size and compressed data
finally
FreeMem(Target);
end;
end;
Here is the function "ReadStream(…)"…
procedure TStoredFile.ReadData(Stream: TStream);
var
Buffer: TArray<Byte>;
TheSize: Cardinal;
Source: Pointer;
begin
// reading the file name
Stream.Read(TheSize, SizeOf(TheSize));
SetLength(Buffer, TheSize);
Stream.Read(Buffer, 0, TheSize); <- Read the UTF8 Bytes…
FFileName := TEncoding.UTF8.GetString(Buffer, 0, TheSize); <- …and convert them back to Unicode // reading the file size
Stream.Read(TheSize, 4); // compressed size
if (Owner = nil) or TacFileStorage(Owner).Compressed then
begin
dec(TheSize, 4);
GetMem(Source, TheSize); // allocating memory for compressed buffer
Stream.Read(FSize, 4); // original size
FData.SetSize(FSize); // allocating memory for decompressed buffer
try
Stream.Read(Source^, TheSize); // reading compressed data
SFUnpack(Source, FData.Memory, TheSize);
finally
FreeMem(Source);
end
end
else // this is for compatibility with older versions
begin
FSize := TheSize;
FData.SetSize(FSize);
// reading the stream
Stream.ReadBuffer(FData.Memory^, FSize);
end;
end;
The filename is stored in the format UTF8 byte, which allows in the best case one Byte for one Character. Please remember Unicode needs two Bytes per Character.
Useless to say, that this is a breaking change. The chance is high, that existing streams couldn't be read sucessfulyy. In this case the DFM should be clear manually. I should be enough to remove the content of the property "StoredData = { ... }", which is easy to find. The component could then be loaded again.
Note: Now, it's not recommended to use the component TacFileStorage, because in the worst case a file with 1 MiB became 2 MiB, because of it is stored as Hex string. It would be much better to use a resource file that is unpacked on run-time.
https://www.board4allcz.eu/showthread.php?t=626035
acFileStorage equivalent的更多相关文章
- Equivalent Strings
Equivalent Strings 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/E 题意: 给出 ...
- Codeforces Round #313 (Div. 1) B. Equivalent Strings
Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...
- Codeforces Round #313 (Div. 2) D. Equivalent Strings
D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...
- hdu 3836 Equivalent Sets
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3836 Equivalent Sets Description To prove two sets A ...
- Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力
B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559 ...
- hdoj 3836 Equivalent Sets【scc&&缩点】【求最少加多少条边使图强连通】
Equivalent Sets Time Limit: 12000/4000 MS (Java/Others) Memory Limit: 104857/104857 K (Java/Other ...
- 暴力求解——Equivalent Strings
Submit Status Description Today on a lecture about strings Gerald learned a new definition of string ...
- Equivalent Strings (字符串相等?)
Equivalent Strings E - 暴力求解.DFS Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I ...
- hdu 3836 Equivalent Sets(tarjan+缩点)
Problem Description To prove two sets A and B are equivalent, we can first prove A is a subset of B, ...
随机推荐
- [置顶] 使用红孩儿工具箱完成基于Cocos2d-x的简单游戏动画界面
[Cocos2d-x相关教程来源于红孩儿的游戏编程之路CSDN博客地址:http://blog.csdn.net/honghaier 红孩儿Cocos2d-X学习园地QQ3群:205100149,47 ...
- CSipSimple最新版本号(二)--加入视频功能
前面我们编译好了最新版本号的CSipSimple,并且測试已经能够打电话了.如今要把视频功能加上去. 不知道怎么编译的,能够看我的上一篇博文:CSipSimple最新版本号 我们先来看一下之前的项目是 ...
- windows下使用openssl的一种方法
下载openssl之后,全部解压到一个路径下,如:c:\program files\openssl sdk 举个例子,如使用SHA1,开发时引用头文件: #include <sha.h> ...
- 操作VCF卡片信息的第三方jar包:ez-vcard
ez-vcard https://github.com/mangstadt/ez-vcard 目前最新的版本已经更新到0.9.8 起初使用该jar包的时候,是0.9.3,当时遇到一个很尴尬的问题, 就 ...
- debian安装jdk8
1.官方下载java想安装的JAVA版本: http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.比如说,常安装的J ...
- CEOI2014 day1 task3 Question
题目 传送门. 算法 以下描述都举这个例子:\(x\)是\(11\),\(y\)是\(5\). 算法1 把\(x\)和\(y\)化成二进制,最多\(10\)位,那么\(x=1011_2\),\(y=0 ...
- 超级坑人的Couchbase数据库问题!!!
官网:http://www.couchbase.com/ 版本:1.8版 问题描述: 某次服务器因意外断电重启后,就进入不了Couchbase控制台,显示 "无法显示该页" 的错误 ...
- VS2010 安装 Boost 库 1.54
Boost库被称为C++准标准库, 功能很是强大, 下面记录我在VS2010中安装使用Boost库的过程. 首先上官网http://www.boost.org/下载最新的Boost库, 我的版本是1_ ...
- rackup工具
gem包rack提供了rackup工具来启动webapplication 下面是一个入门范例,使用 bundler 管理库的一个sinatra应用 在begin文件夹下有三个文件 begin.ru ...
- C# - InnerList
运行效果: 代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; name ...