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, ...
随机推荐
- Android进程内存上限
Android应用程序都是在自己单独的进程中运行.Android为不同类型的进程分配了不同的内存使用上限,如果应用进程使用的内存超过了这个上限,则会抛出Out Of Memory异常,接着进程也被ki ...
- linux 单网卡绑定两个ip
一.ubuntu系统: #vi /etc/network/interfaces OR $ sudo vi /etc/network/interfaces Modify as follows: au ...
- 在android解析json
1.采用一般方式解释json为对象 package com.heimazyh.testjson; import org.json.JSONException; import org.json.JSON ...
- Web端的Tab控件在切换Tab时Load数据出错的处理
我们在应用Web端的Tab控件时,不管是Jquery easyui的还是Ext的Tab控件都会遇到一个问题,在Tab1正在加载数据的时候我们切换到Tab2,再切换回来,Load数据的控件就会出错,出错 ...
- 关于负数的isdigit()判断
-->the start 今天写作业的时候突然想到,一直使用isdigit()方法来处理用户的输入选择是不是数字,但是如果用户输入的是负数呢,会不会导致bug? 然后我就试了一下,居然不报错.. ...
- perl 面向对象 use base
1.XXX.pm 文件里面的第一行要是:package XXX: 2.要有构造函数 sub new,实现如下: sub new { my $class = shift; # Get the reque ...
- Cocos2d-x 3.2 大富翁游戏项目开发-第七部分 获取角色路径_3
点击下载代码 http://download.csdn.net/detail/lideguo1979/8291803 新建一个类RouteNavigation,定义getPath()方法.用来获取 ...
- Ultra Office Control 2.0
http://www.ultrashareware.com/Ultra-Office-Control.htm
- FMXUI - UI.Dialog 示例
在 FMXUI 开源库,增加了 UI.Dialog 单元.此单元实现了跨平台的基础对话框组件.使用时引用 UI.Dialog 即可.如果需要自定义对话框的样式, 可以添加一个 TDialogStyle ...
- ORA-01092 ORA-12432: LBAC error: zllegnp:OCIStmtExecute 故障一例
最近由于数据库hang住,无奈之下直接干掉了pmon进程,再次启动的时候收到了ORA-01092: ORACLE instance terminated. Disconnection forced以及 ...