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…

Code:
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(…)"…

Code:
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的更多相关文章

  1. Equivalent Strings

    Equivalent Strings 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/E 题意: 给出 ...

  2. Codeforces Round #313 (Div. 1) B. Equivalent Strings

    Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...

  3. Codeforces Round #313 (Div. 2) D. Equivalent Strings

    D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...

  4. hdu 3836 Equivalent Sets

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3836 Equivalent Sets Description To prove two sets A ...

  5. 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 ...

  6. hdoj 3836 Equivalent Sets【scc&&缩点】【求最少加多少条边使图强连通】

    Equivalent Sets Time Limit: 12000/4000 MS (Java/Others)    Memory Limit: 104857/104857 K (Java/Other ...

  7. 暴力求解——Equivalent Strings

    Submit Status Description Today on a lecture about strings Gerald learned a new definition of string ...

  8. Equivalent Strings (字符串相等?)

    Equivalent Strings   E - 暴力求解.DFS Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I ...

  9. 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, ...

随机推荐

  1. Animation 的setFillAfter

    疑问:如果图片从其他地方回到原先位置,则setFillAfter(false)也可以保持图片在原先位置?

  2. 【转】linux下 postgres的一些操作总结

    参考博文: PostgreSQL详解     1. 基本操作命令 安装完成后,PostgreSQL默认创建了名为postgres数据库用户账户,其与MySQL的root以及SQL Server的sa账 ...

  3. IntelliJ IDEA导出Java 可执行Jar包

    原文:IntelliJ IDEA导出Java 可执行Jar包 保证自己的Java代码是没有问题的,在IDEA里面是可以正常运行的,然后,按下面步骤: 打开File -> Project Stru ...

  4. Mockito简介(转)

    Mockito 是目前 java 单测中使用比较流行的 mock 工具.其他还有 EasyMock,JMock,MockCreator,Mockrunner,MockMaker 及 PowerMock ...

  5. stringstream clear()的疑问 - yuanshuilee的日志 - 网易博客

    stringstream clear()的疑问 - yuanshuilee的日志 - 网易博客 stringstream clear()的疑问   2013-09-05 08:43:13|  分类: ...

  6. Java 自定义日志写入

    /** * 将信息写入到日志 * @param content * @return * @throws IOException */ public static boolean writeLog(St ...

  7. sort uniq妙用

    cat a b | sort | uniq > c   # c是a和b的并集 cat a b | sort | uniq -d > c   # c是a和b的交集 cat a b b | s ...

  8. 用lisp来让计算机学会写作

    大部分的代码.思路参考了<Ansi Common Lisp>P138~P141. 问题:给一篇英文文本,如何让计算机依据此文本而生成随机但可读的文本.如: |Venture| The Na ...

  9. linux下tomcat shutdown后 java进程依然存在

    今天遇到一个非常奇怪的问题,如标题所看到的: linux下(之所以强调linux下,是由于在windows下正常),运行tomcat ./shutdown.sh 后,尽管tomcat服务不能正常訪问了 ...

  10. Twenty Newsgroups Classification任务之二seq2sparse

    seq2sparse对应于mahout中的org.apache.mahout.vectorizer.SparseVectorsFromSequenceFiles,从昨天跑的算法中的任务监控界面可以看到 ...