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 判断uefi与 legacy bios启动模式

Delphi tstream详解

Delphi idhttp用法详解

Delphi tbytedynarray转化为string

Delphi 扫雷外挂

Delphi 复杂数据类型

Delphi 2009 泛型容器单元(generics.collections)[1]: tlist<t>

setwindowpos改变窗口的位置与状态

Delphi2007-Delphi2010 程序不出现在任务栏的方法

Delphi 取出一个字符在字符串出现的次数

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



打赏

取消

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

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

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

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

评论

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