Delphi - Few Tricks

How to handle screen saver programmatically

Turn on the Screen Saver using
   SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, nil, 0);
and off by
   SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, nil, 0);
 

How to set the focus to a particular line in TMemo Component?

Procedure SelectMemoLine(Memo : TMemo; N : Integer);
Var
    I,SStart,SLength : Integer;
Begin
  with Memo do
  begin
    if N>=Lines.Count then
    begin
      SStart:=Length(Text);
      SLength:=0;
    end
    else
    begin
      SLength:=Length(Lines[N]);
      Dec(N);
      SStart:=0;
      for I:=0 to N do
      begin
        Inc(SStart,Length(Lines[I]));
      end;
    end;
    SelStart:=SStart;
    SelLength:=SLength;
  end;
end;
 

Deleting the files to Recycle Bin

procedure TfrmGetConFile.SendToRecycleBin(FileName: string);
var
  SHF: TSHFileOpStruct;
begin
  fillchar(SHF, sizeof(SHF),0);
  FileName := FileName + #0 ;
  with SHF do
    begin
      Wnd := Handle;
      wFunc := FO_DELETE;
      pFrom := PChar(FileName);
      fFlags := FOF_ALLOWUNDO
                or FOF_NOCONFIRMATION
                or FOF_SILENT;
    end;
    SHFileOperation(SHF);
end;