您现在的位置是:首页 >

wps入门基础教程 DELPHI基础教程:文件管理(一)[4]

火烧 2022-09-21 02:34:15 1088
DELPHI基础教程:文件管理(一)[4]   增加一条记录  当用户单击 增加 按钮时屏幕将会弹出一个记录编辑模式对话框EditForm 在编辑框中填入合适的内容并按OK键关闭后 相应值写入一个TM

DELPHI基础教程:文件管理(一)[4]  

  增加一条记录

  当用户单击 增加 按钮时屏幕将会弹出一个记录编辑模式对话框EditForm 在编辑框中填入合适的内容并按OK键关闭后 相应值写入一个TMethod类型的变量MethodRec中 其中Nature和Result 域需要进行转换 之后增加的记录添加到StringGrid 的显示中

  最后文件定位于尾部 写入当前记录 总记录数加

  Seek(MethodFile Count)

  Write(MethodFile MethodRec)

  Count := Count+ ;

  完整的程序清单如下

  procedure TRecFileForm AddButtonClick(Sender: TObject)

  var

  MethodRec: TMethod;

  Rl: Real;

  k: Integer;

  EditForm: TEditForm;

  begin

  if FileOpenEd = False then Exit;

  EditForm := TEditForm Create(self)

  if EditForm ShowModal <> idCancel then

  begin

  HazAttr text := ;

  MethodRec Name := EditForm MethodName text;

  MethodRec Condition := EditForm Condition text;

  case EditForm NatureCombo ItemIndex of

   :

  MethodRec Nature := Micro;

   :

  MethodRec Nature := Macro ;

  end;

  Val(EditForm Result text Rl k)

  MethodRec Result := Rl;

  with StringGrid do

  begin

  if Count < MaxShow then

  Height := Height+DefaultRowHeight;

  RowCount := RowCount+ ;

  end;

  ShowMethod(MethodRec Count+ )

  seek(MethodFile Count)

  write(MethodFile MethodRec)

  Count := Count+ ;

  end;

  end;

  修改记录

  首先获取当前记录位置

  CurrentRec := StringGrid Row ;

  而后打开编辑对话框并显示当前值 修改完毕后 修改结果保存在一个记录中并在StringGrid 中重新显示

  最后修改结果写入文件

  Seek(MethodFile CurrentRec)

  Write(MethodFile MethodRec)

  完整程序如下

  procedure TRecFileForm ModifyButtonClick(Sender: TObject)

  var

  MethodRec: TMethod;

  Rl: Real;

  k: Integer;

  EditForm: TEditForm;

  begin

  if FileOpened = False then Exit;

  EditForm := TEditForm Create(self)

  CurrentRec := StringGrid Row ;

  with EditForm do

  begin

  MethodName text := StringGrid Cells[ CurrentRec+ ];

  Condition text := StringGrid Cells[ CurrentRec+ ];

  if StringGrid Cells[ CurrentRec+ ] = 微 观 then

  NatureCombo ItemIndex :=

  else

  NatureCombo ItemIndex := ;

  Result text := StringGrid Cells[ CurrentRec+ ];

  if ShowModal <> idCancel then

  begin

  HazAttr text := ;

  MethodRec Name := MethodName text;

  MethodRec Condition := Condition text;

  case NatureCombo ItemIndex of

   :

  MethodRec Nature := Micro;

   :

  MethodRec Nature := Macro ;

wps入门基础教程 DELPHI基础教程:文件管理(一)[4]

  end;

  Val(Result text Rl k)

  MethodRec Result := Rl;

  ShowMethod(MethodRec CurrentRec+ )

  seek(MethodFile CurrentRec)

  write(MethodFile MethodRec)

  end;

  end;

  end;

  返回目录DELPHI基础教程

      编辑推荐

      Java程序设计培训视频教程

       J EE高级框架实战培训视频教程

  Visual C++音频/视频技术开发与实战

  Oracle索引技术

  ORACLE G数据库开发优化指南

  Java程序性能优化 让你的Java程序更快 更稳定

  C嵌入式编程设计模式

  Android游戏开发实践指南

lishixinzhi/Article/program/Delphi/201311/25243  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码