procedure TForm1.BitBtn1Click(Sender: TObject); begin with OpenDialog1 do if Execute then if FileSetAttr(filename, faArchive)=0 then Caption:='attribute was changed' else Caption:='attribute was not changed'; end;
Delphi 设置文件属性
请在interface下的uses中引用filectrl单元
2. 首先取文件属性
var
attr : integer;
filename : string; begin
filename := 'myfile';
attr := FileGetAttr(filename); end;
3. 设置文件属性(如设置归档属性 -> faArchive )
attr := attr or faArchive; //如要去掉某一属性,则如下句 attr := attr and (not faArchive); //保留其它属性 if FileSetAttr(filename, attr)=0 then //成功代码 else //失败代码