大侠们,请各位帮小弟解决一个自定义数据格式难题,代码给出。(50分)

  • 主题发起人 主题发起人 xieyj
  • 开始时间 开始时间
X

xieyj

Unregistered / Unconfirmed
GUEST, unregistred user!
type
PFileHead = ^TFileHead;
TFileHead = record
EditDate: TDateTime;
Pass: array[0..11] of char;
DBUser: array[0..15] of Char;
end;
type
TLeafObject = class
private
FFileHead: TFileHead;
public
constructor Create(Fn: string; Mode: Word);
property FileHead: TFileHead read FFileHead write FFileHead;

constructor TLeafObject.Create(Fn: string; Mode: Word);
begin
if Mode = fmCreate then
begin
FFileHandle := FileCreate(FFileName);
if FFileHandle = -1 then raise Exception.Create('对不起,无法创建数据库!');
{添充缺省信息头}
with FFileHead do
begin
EditDate := Now;
Pass[0] := #0;
DBUser := #0;
with FFileHead do
begin
Encypher(Key, DBUser, 4);
Encypher(Key, Pass, 3);
FileWrite(FFileHandle, FFileHead, sizeof(TFileHead));
FileWrite(FFileHandle, FIndexHead, sizeof(TIndexHead));
Decypher(Key, DBUser, 4);
Decypher(Key, Pass, 3);
end;
end;
end;
创建时同时更改密码,以下代码执行没有错误提示,但是值却没有传进去。
var MyObject=TLeafObject
begin
MyObject := TLeafObject.Create(文件名, fmCreate);
with MyObject.FileHead do
begin
UserName.GetTextBuf(DBUser, 16);
PassWord.GetTextBuf(Pass, 12);
EditDate := Now;
end;
MyObject.Free;
end;
 
Retrieves the control's text, copies it into a buffer, and returns the number of characters copied.

function GetTextBuf(Buffer: PChar; BufSize: Integer): Integer;

是向Buffer中复制,你究竟要做什么?向对象中副完值,马上又把对象释放,当然什么也没了!
你跟踪一下!
 
后退
顶部