//录像备份(包括创建及追加),另存为本地文件sFileName, bCreate: True--Create;False--Append //return -1: Record Backup Failed function TFrmPublic.RecordBackup(var sFileName: string;pStreamData: pointer;var StreamLen: LongWord;var bCreate: Boolean): Integer; var F: File; fHandle: THandle; CountByte: Integer; //写入及返回的数据大小 WriteBuf: array[0..BACKUPSIZE-1] of Byte; //数据缓冲 begin //Initialized //ZeroMemory(@WriteBuf[0],BACKUPSIZE); try
if StreamLen <= BACKUPSIZE then begin CopyMemory(@(WriteBuf[0]),pStreamData,StreamLen); end //end of [if StreamLen <= BACKUPSIZE then] else //缓冲区溢出 begin result := -1; //MessageBeep(MB_ICONEXCLAMATION); Exit; end; //end of [esle..] begin if bCreate then //产生新文件 begin //Create File //CreateFile(Pchar(sFileName),0,FILE_SHARE_READ,Nil,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0); //CreateFile(Pchar(sFileName),GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,Nil,OPEN_ALWAYS,0,0); //CreateFile(Pchar(sFileName),0,FILE_SHARE_READ or FILE_SHARE_WRITE,Nil,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0); fHandle := CreateFile(Pchar(sFileName),GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE,Nil,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0); //Associate File AssignFile(F,sFileName); //Opne File Reset(F,1); //Opens an existing file,and RecSize := 1; //Write Data to File BlockWrite(F,WriteBuf,StreamLen,CountByte); //Close File CloseFile(F); //Close File Handle CloseHandle(fHandle); end //end of [if..] else //向文件追加数据 begin //Associate File AssignFile(F,sFileName); //Opne File Reset(F,1); //Opens an existing file,and RecSize := 1; //Set the postion to the end of File Seek(F,FileSize(F)); //Write Data to File BlockWrite(F,WriteBuf,StreamLen,CountByte); //Close File CloseFile(F); end; //end of [else..] end; //end of [try..] except on E: Exception do begin result := -1; Exit; //MessageBeep(MB_ICONEXCLAMATION); end; end; //end of [try..except..] result := CountByte;end; 根据你的需要,你看看再改造一下就可以了。
一、直接将文本文件重新命名为.HTML
二、将txt文件中内容插入到以下html代码中,然后保存为html网页格式
<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>TXT2HTML</title>
</head>
<body>
<pre>
...........
将您的文本内容插入此处就可以了
...........
</pre>
</body>
</html>
//return -1: Record Backup Failed
function TFrmPublic.RecordBackup(var sFileName: string;pStreamData: pointer;var StreamLen: LongWord;var bCreate: Boolean): Integer;
var
F: File;
fHandle: THandle;
CountByte: Integer; //写入及返回的数据大小
WriteBuf: array[0..BACKUPSIZE-1] of Byte; //数据缓冲
begin
//Initialized
//ZeroMemory(@WriteBuf[0],BACKUPSIZE); try
if StreamLen <= BACKUPSIZE then
begin
CopyMemory(@(WriteBuf[0]),pStreamData,StreamLen);
end //end of [if StreamLen <= BACKUPSIZE then]
else //缓冲区溢出
begin
result := -1;
//MessageBeep(MB_ICONEXCLAMATION);
Exit;
end; //end of [esle..] begin
if bCreate then //产生新文件
begin
//Create File
//CreateFile(Pchar(sFileName),0,FILE_SHARE_READ,Nil,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0);
//CreateFile(Pchar(sFileName),GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,Nil,OPEN_ALWAYS,0,0);
//CreateFile(Pchar(sFileName),0,FILE_SHARE_READ or FILE_SHARE_WRITE,Nil,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0);
fHandle := CreateFile(Pchar(sFileName),GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE,Nil,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0); //Associate File
AssignFile(F,sFileName);
//Opne File
Reset(F,1); //Opens an existing file,and RecSize := 1;
//Write Data to File
BlockWrite(F,WriteBuf,StreamLen,CountByte); //Close File
CloseFile(F);
//Close File Handle
CloseHandle(fHandle); end //end of [if..]
else //向文件追加数据
begin
//Associate File
AssignFile(F,sFileName);
//Opne File
Reset(F,1); //Opens an existing file,and RecSize := 1;
//Set the postion to the end of File
Seek(F,FileSize(F));
//Write Data to File
BlockWrite(F,WriteBuf,StreamLen,CountByte); //Close File
CloseFile(F); end; //end of [else..]
end; //end of [try..]
except
on E: Exception do
begin
result := -1;
Exit;
//MessageBeep(MB_ICONEXCLAMATION);
end;
end; //end of [try..except..] result := CountByte;end; 根据你的需要,你看看再改造一下就可以了。
如果有一些格式上的要求你就要根据需要添加控制字符串到你的新的文档(html)里面了
有什么问题给我邮件
[email protected]