Procedures no Delphi - parte 1

procedure TROT.MudaCorRadioGroup(Sender: TObject);
var
  n, i : integer;
  RG : TRadioGroup;
begin
  {if Sender is TRadioGroup then begin
    for n := 0 to TRadioGroup(Sender).ControlCount -1 do begin
      TRadioButton(TRadioGroup(Sender).Controls[n]).Font.Color := clWindowText;
      TRadioButton(TRadioGroup(Sender).Controls[n]).Font.Style := [];
    end;
  end;}

  // Foi passado um RadioGroup
  if Sender is TRadioGroup then begin
    RG := TRadioGroup(Sender);
    for n := 0 to RG.ControlCount -1 do begin
      // Muda a cor e o estilo da fonte dos radiobutons
      TRadioButton(RG.Controls[n]).Font.Color := clWindowText;
      TRadioButton(RG.Controls[n]).Font.Style := [];
    end;
  end;

  // foi passado um formulario
  if Sender is TForm then begin
    for n := 0 to TForm(Sender).ControlCount -1 do begin
      if TForm(Sender).Controls[n] is TRadioGroup then begin
        RG := TRadioGroup(TForm(Sender).Controls[n]);
        MudaCorRadioGroup(RG);
      end;
    end;
  end;
end;

 

procedure TForm1.GravaStrEmArq(Texto, sNomeArq: String; Substituir : Boolean = True);
var
  Arquivo   : TextFile;
  sPath     : String;
  nAux      : integer;
  BackupName: string;
  bArqExiste : Boolean;
begin
  sPath := uppercase(ExtractFilePath(Application.ExeName));
//  sPath := ROT.SubstituiStr('PROGS','DADOS',sPath);
  // se Substituir = False o texto será acrescido no arquivo caso o mesmo exista
  bArqExiste := FileExists(sPath+sNomeArq);
  if bArqExiste and Substituir then  begin
     // Cria backup caso exista no formato nome.b00
     nAux:= 0;
     BackupName := ROT.SubstituiStr(ExtractFileExt(sNomeArq),
                                    '.Bak',
                                    sPath+sNomeArq);
     while FileExists(BackupName) do begin
       nAux:= nAux + 1;
       BackupName := ROT.SubstituiStr(ExtractFileExt(sNomeArq),
                                      '.B'+ZerosAEsquerda(nAux,2),
                                      sPath+sNomeArq);
     end;
     if not RenameFile(sPath+sNomeArq, BackupName) then
        raise Exception.Create('Não foi possível renomear o arquivo existente.');
  end;
  try
  AssignFile(Arquivo, sPath+sNomeArq);
  if (not bArqExiste) or (bArqExiste and Substituir) then
     Rewrite(Arquivo)
  else
     Append(Arquivo);
  Write(Arquivo, Texto);
  CloseFile(Arquivo);
  except
  end;
end;