unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, ComCtrls;<br><br>type<br> TForm1 = class(TForm)<br> RichEdit1: TRichEdit;<br> Button1: TButton;<br> Button2: TButton;<br> Edit1: TEdit;<br> UpDown1: TUpDown;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> public<br> procedure SaveREFile;<br> procedure LoadREFile(AutoID: Integer);<br> end;<br><br> TSoftDetailRecord=packed record<br> Autoid:integer;<br> Classid:integer;<br> SoftName:String[100];<br> SoftPath:String[200];<br> Description
ointer;<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> SaveREFile;<br>end;<br><br>procedure TForm1.LoadREFile(AutoID: Integer);<br>var<br> tmpStream, tmpFStream: TStream;<br> tmpRd: TSoftDetailRecord;<br>begin<br> tmpStream := TMemoryStream.Create;<br> tmpFStream := TFileStream.Create('c:/1.dat', fmOpenReadWrite);<br> try<br> repeat<br> tmpFStream.Read(tmpRd, SizeOf(tmpRd));<br> if tmpRd.Autoid <> AutoID then<br> begin<br> if tmpFStream.Size > (tmpFStream.Position + Integer(tmpRd.Description)) then<br> tmpFStream.Seek(Integer(tmpRd.Description), soCurrent)<br> else<br> begin<br> showmessage('找不到这条记录!');<br> exit;<br> end;<br> end<br> else break;<br> until tmpRd.Autoid = AutoID;<br> //读入数据<br> tmpStream.CopyFrom(tmpFStream, Integer(tmpRd.Description));<br> tmpStream.Position := 0;<br> RichEdit1.Lines.LoadFromStream(tmpStream);<br> finally<br> tmpFStream.Free;<br> tmpStream.Free;<br> end;<br>end;<br><br>procedure TForm1.SaveREFile;<br>var<br> tmpStream, tmpFStream: TStream;<br> tmpRd: TSoftDetailRecord;<br>begin<br> tmpStream := TMemoryStream.Create;<br> if not FileExists('c:/1.dat') then<br> tmpFStream := TFileStream.Create('c:/1.dat', fmOpenReadWrite or fmCreate)<br> else tmpFStream := TFileStream.Create('c:/1.dat', fmOpenReadWrite);<br> try<br> RichEdit1.Lines.SaveToStream(tmpStream);<br> tmpRd.Autoid := StrToInt(Edit1.Text);<br> Integer(tmpRd.Description) := tmpStream.Size;<br> tmpFStream.Seek(0, soEnd); //移到文件最后<br> tmpFStream.Write(tmpRd, SizeOf(tmpRd));<br> tmpStream.Position := 0;<br> tmpFStream.CopyFrom(tmpStream, tmpStream.Size);<br> finally<br> tmpFStream.Free;<br> tmpStream.Free;<br> end;<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> LoadREFile(StrToInt(Edit1.Text));<br>end;<br><br>end.