delphi读写INI文件加锁(独占)


本文整理自网络,侵删。

 

unit Unit7;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IniFiles, StdCtrls;

type
  TForm7 = class(TForm)
    Button1: TButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form7: TForm7;
  FileHandle: Integer;

implementation

{$R *.dfm}

procedure TForm7.FormDestroy(Sender: TObject);
begin
  FileClose(FileHandle);
end;

procedure TForm7.FormCreate(Sender: TObject);
begin
  FileHandle := FileOpen('C:\test.ini',
    fmOpenWrite or fmShareDenyNone);
end;

procedure TForm7.Button1Click(Sender: TObject);
var
  FIni: TIniFile;
begin
  FIni := TIniFile.Create('C:\test.ini');
  try
    FIni.WriteString('ddd', 'dsadsa', 'dsadsadsadsasada');
  finally
    FIni.Free;
  end;

end;

end.

相关阅读 >>

Delphi 取时间戳

Delphi richedit文字背景色的处理

Delphi 自动把combobox控件的内容里没有的内容加入列表中

Delphi firedac 连接access mdb数据库的方法

winapi 字符及字符串函数(13): lstrcmp、lstrcmpi - 对比串

Delphi windows 编程[7] - wm_create 消息

Delphi 分解时间 �cdecodedate、decodetime … decodedatetime …

Delphi添加任务栏右键菜单

Delphi dos编程

Delphi 网卡工作状态检测

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...