懒得修改了。参数里应该再加一个字段名称,有兴趣的修改一下。。。目前是根据VersionNO来判断,读的时候也可以根据数据库中流的长度来比较。。最好是通过外界手段。。自己控制吧。。。

只要是连续内存的东西,都可以拿来存...

 1 function TDataModuleDataBase.LoadRecFromDB(const aName, TableName: string;
2 var Rec; RecSize: Integer): Boolean;
3 var
4 MS: TMemoryStream;
5 begin
6 Result := False;
7 if Trim(aName)='' then
8 Exit;
9 MS := TMemoryStream.Create;
10 try
11 try
12 ADOConnection.Open;
13 except
14 Exit;
15 end;
16 with ADOQuery do begin
17 Active:=False;
18 SQL.Text:='SELECT * FROM '+ TableName +' WHERE Name='+''''+ aName +'''' + ' and AppVersion=' + '''' + VersionNO + '''';
19 Active:=True;
20 if RecordCount <> 1 then
21 Exit;
22 with FieldByName('RecOLE') as TBlobField do begin
23 MS.Position := 0;
24 SaveToStream(MS);
25 MS.Position := 0;
26 MS.Read(Rec, RecSize);
27 end;
28 end;
29 finally
30 ADOConnection.Close;
31 MS.Free;
32 end;
33 Result := True;
34 end;
35
36 function TDataModuleDataBase.SaveRecToDB(const aName, TableName: string;
37 var Rec; RecSize: Integer): Boolean;
38 var
39 MS: TMemoryStream;
40 begin
41 Result := False;
42 MS := TMemoryStream.Create;
43 try
44 try
45 ADOConnection.Open;
46 except
47 Exit;
48 end;
49 with ADOQuery do begin
50 Active:=False;
51 SQL.Clear;
52 SQL.Text:='SELECT * FROM ' + TableName + ' WHERE Name='+''''+ aName + '''';
53 Active:=True;
54 if RecordCount>=1 then
55 Exit;
56 Active:=False;
57 SQL.Text:='SELECT * FROM ' + TableName;
58 Prepared;
59 Open;
60 Append;
61 FieldByName('Name').Value := aName;
62 FieldByName('AppVersion').Value := VersionNO;
63 with FieldByName('RecOLE') as TBlobField do begin
64 MS.Position := 0;
65 MS.Write(Rec, RecSize);
66 MS.Position := 0;
67 LoadFromStream(MS);
68 end;
69 Post;
70 end;
71 finally
72 ADOConnection.Close;
73 MS.Free;
74 end;
75 Result := True;
76 end;

  

posted on 2011-07-21 22:42  solokey  阅读(442)  评论(0编辑  收藏  举报