操作TAB文件和TStringGrid赋值;

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    btn1: TButton;
    btn2: TButton;
    bvl1: TBevel;
    strngrd: TStringGrid;
    btn3: TBitBtn;
    procedure btn1Click(Sender: TObject);
    procedure btn2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure strngrdGetEditMask(Sender: TObject; ACol, ARow: Integer;
      var Value: String);
    procedure btn3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    path:string;
    Function  ReadOnePara(sIniFile,Sct,Idt:String):String;
    procedure WriteOnePara(sIniFile,Sct,Idt,Value:String);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
begin
  WriteOnePara(path+'基本配置.TAB','SHUTDOWN','chkHintMusic','ddalf');
  WriteOnePara(path+'基本配置.TAB','关机时间','Music','1313');
  WriteOnePara(path+'基本配置.TAB','桌面视频','chktMusic','fdasf455');
  WriteOnePara(path+'基本配置.TAB','服务配置','chk','是真的吗');
end;

procedure TForm1.btn2Click(Sender: TObject);
var s:string;
begin
  s:=ReadOnePara(path+'基本配置.TAB','SHUTDOWN','chkHintMusic');
  ShowMessage(s);
  s:=ReadOnePara(path+'基本配置.TAB','关机时间','Music');
  ShowMessage(s);
  s:=ReadOnePara(path+'基本配置.TAB','桌面视频','chktMusic');
  ShowMessage(s);
  s:=ReadOnePara(path+'基本配置.TAB','服务配置','chk');
  ShowMessage(s);

end;
function TForm1.ReadOnePara(sIniFile, Sct, Idt: String): String;
Var aIniFile:TIniFile;
begin
  Result:='';
  aIniFile:=TIniFile.Create(sIniFile);
  try
    Result:=aIniFile.ReadString(Sct,Idt,'');
  finally
    aIniFile.Free;
  end;
end;


procedure TForm1.WriteOnePara(sIniFile, Sct, Idt, Value: String);
Var aIniFile:TIniFile;
begin
  aIniFile:=TIniFile.Create(sIniFile);
  try
    aIniFile.WriteString(Sct,Idt,Value);
  finally
    aIniFile.Free;
  end;
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
  Path:=ExtractFilePath(Application.ExeName);
end;

procedure TForm1.strngrdGetEditMask(Sender: TObject; ACol,
  ARow: Integer; var Value: String);
begin
  Value:='00:00:00';
end;

procedure TForm1.btn3Click(Sender: TObject);
begin
  strngrd.Cells[0,0]:='序号';
  strngrd.Cells[1,0]:='关机时间';
  strngrd.Cells[2,0]:='开机时间';
  strngrd.Cells[3,0]:='给';
end;

end.

  

posted @ 2015-04-10 13:59  海蓝7  阅读(267)  评论(0编辑  收藏  举报