一个简单的问题,大家来看看啊!(42分)

  • 主题发起人 主题发起人 6713829
  • 开始时间 开始时间
6

6713829

Unregistered / Unconfirmed
GUEST, unregistred user!
DELPHI怎样将一个指针的数据保存到文件里面啊。<br>我在网上找到了一个!<br> &nbsp;uses &nbsp; IniFiles; &nbsp; <br> &nbsp; &nbsp;<br> &nbsp;procedure &nbsp; TForm1.Button1Click(Sender: &nbsp; TObject); &nbsp; <br> &nbsp;var &nbsp; <br> &nbsp; &nbsp; &nbsp;ConfigIni: &nbsp; TIniFile; &nbsp; <br> &nbsp; &nbsp; &nbsp;StreamTmp:TStream; &nbsp; <br> &nbsp; &nbsp; &nbsp;{?}TestPoint: &nbsp; PInteger;{?} &nbsp; <br> &nbsp;begin &nbsp; <br> &nbsp; &nbsp; &nbsp;New(TestPoint); &nbsp; <br> &nbsp; &nbsp; &nbsp;TestPoint^ &nbsp; := &nbsp; StrToIntDef(Edit1.Text, &nbsp; 0); &nbsp; <br> &nbsp; &nbsp; &nbsp;StreamTmp &nbsp; := &nbsp; TMemoryStream.Create; &nbsp; <br> &nbsp; &nbsp; &nbsp;StreamTmp.Write(TestPoint^, &nbsp; SizeOf(TestPoint^)); &nbsp; //这里是写入 &nbsp; <br> &nbsp; &nbsp; &nbsp;ConfigIni &nbsp; := &nbsp; TIniFile.Create(ExtractFilePath(Application.ExeName) &nbsp; + &nbsp; 'config.ini'); &nbsp; <br> &nbsp; &nbsp; &nbsp;try &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StreamTmp.Position &nbsp; := &nbsp; 0; &nbsp; //复位 &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ConfigIni.WriteBinaryStream('TEST', &nbsp; 'test', &nbsp; StreamTmp); &nbsp; <br> &nbsp; &nbsp; &nbsp;finally &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ConfigIni.Free; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StreamTmp.Free; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dispose(TestPoint); &nbsp; //不要忘记释放空间 &nbsp; <br> &nbsp; &nbsp; &nbsp;end; &nbsp; <br> &nbsp;end; &nbsp;<br><br>但是这个是利用INI文件的方法。<br>我想用一个更好的方法。<br>直接将指针存入文件。<br>像<br> procedure &nbsp; TForm1.Button1Click(Sender: &nbsp; TObject); &nbsp; &nbsp; <br> &nbsp;var &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp;F: &nbsp; TFileStream; &nbsp; &nbsp; <br> &nbsp;begin &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp;F:=TFileStream.Create('c:/TreeView.txt',fmCreate &nbsp; or &nbsp; fmShareCompat); &nbsp; <br> &nbsp; &nbsp; &nbsp;F.WriteComponent(TreeView1); &nbsp; <br> &nbsp; &nbsp; &nbsp;F.Free; &nbsp; <br> &nbsp;end;<br>这个一样。<br>比较简单点的!<br><br>请高手赐教!!!!
 
后退
顶部