IOUtilsFileAttr (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses several forms. The first form has its FormStyle property set to MDIForm. The others have their FormStyle properties set to MDIChild and their Visible properties set to True. Add a main menu component and name one of the menu items MyArrangeIcons. This is the code for the MyArrangeIconsClick handler. When you choose the ArrangeIcons command, minimized child forms are arranged so that they are evenly spaced and do not overlap. Do not name the menu items "ArrangeIcons", as that will override the TForm method.

Code

procedure TIOMain.btSetAttrClick(Sender: TObject);
begin
  Attrs := [];

	{ This part of code creates the set of attributes based on
    the values of the check boxes. }

  if CheckBox1.Checked then
    Attrs := Attrs + [TFileAttribute.faNormal];

  if CheckBox2.Checked then
    Attrs := Attrs + [TFileAttribute.faArchive];

  if CheckBox3.Checked then
    Attrs := Attrs + [TFileAttribute.faSystem];

  if CheckBox4.Checked then
    Attrs := Attrs + [TFileAttribute.faHidden];

  if TFile.Exists(Edit1.Text) then
    TFile.SetAttributes(Edit1.Text, Attrs);
end;

procedure TIOMain.btGetAttrClick(Sender: TObject);
begin

	{ If the filename declared in the edit control exists, read
	  it from the file and display the results on one or more
	  of the four check boxes. }

  if TFile.Exists(Edit1.Text) then
  begin
    Attrs := TFile.GetAttributes(Edit1.Text);

    if TFileAttribute.faNormal in Attrs then
      CheckBox1.Checked := True;

    if TFileAttribute.faArchive in Attrs then
      CheckBox2.Checked := True;

    if TFileAttribute.faSystem in Attrs then
      CheckBox3.Checked := True;

    if TFileAttribute.faHidden in Attrs then
      CheckBox4.Checked := True;
  end;
end;

Uses

Personal tools
Assistance