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, ...
随机推荐
- Cloud Engine
Cloud Engine:大杀器如何炼成 郑昀 创建于2016/6/18 最后更新于2016/6/19 点击查看我的<如何从零搭建一个技术平台>,这是一个系列.转载时请注明“转载自旁观 ...
- Unix时间戳 POSIX时间 Unix时间
Unix时间戳(Unix timestamp),或称Unix时间(Unix time).POSIX时间(POSIX time),是一种时间表示方式,定义为从格林威治时间1970年01月01日00时00 ...
- Service的开启和停止以及生命周期
1.清单文件 <service android:name=".TestService"></service> 2.开启Service Intent inte ...
- PHP - 接口&抽象类
什么时候使用抽象类什么时候使用接口? .如果要创建一个模型,这个模型将由一些紧密相关的对象采用,就可以使用抽象类.如果要创建将由一些不相关对象采用的功能,就使用接口. .如果必须从多个来源继承行为,就 ...
- Eclipse用法和技巧十九:eclipse修改workspace
工作中某一个项目的文件一般都在某一个路径,大多数人都习惯固定eclipse的workspace.不过偶尔也有点别的,比如做一个大项目中穿插着做些OJ,或者别的……这个时候当然可以选择在安装一个ecli ...
- NSThread的一些细节
1.NSThread创建方式(一个NSThread对象就代表一条线程)1.1>创建\启动线程(1)线程一启动,就会在thread中执行self的run方法NSTread *thread = [[ ...
- windows的消息传递--消息盒子(超详细EM_UNDO等消息)
使用delphi的消息机制可以方便操作后台,其中重要的就是sendmessage()函数.下面讲解一下这个函数 function SendMessage(hWnd: HWND; Msg: UINT; ...
- LWP::UserAgent - Web user agent class Web 用户agent 类:
LWPUserAgent: LWP::UserAgent - Web user agent class Web 用户agent 类: 概述: require LWP::UserAgent; my $u ...
- 关于android多点触控
最近项目需要一个多点触控缩放的功能.然后上网查了下资料 总结一下: 首先android sdk版本很重要,比如你在AndroidManifest.xml中指定android:minSdkVersion ...
- 零积分下载,2014年辛星mysql教程秋季版第一本已经完工,期待您的支持
经过一段时间的不懈努力.终于,2014年辛星mysql教程秋季版的第一本,即夯实基础已经完工,在csdn的下载地址为:去下载地址 ,假设左边地址跪了,能够去http://download.csdn.n ...