Search results for 'AssignFile'. 1 post(s) found.

  1. 2007/09/25 How to save text from Clipboard to a file
2007/09/25 14:19

How to save text from Clipboard to a file


If you want to save the text data contained in the Clipboard to a text file on a disk, use the next code:

{
Usage:

ClipboardTxtToFile(c:\dir\cliptext.txt)
}

uses Clipbrd;

function ClipboardTxtToFile
         (sFileTXT : string) : boolean;
var
   ps1, ps2 : PChar;
   dwLen : DWord;
   tf : TextFile;
   hData : THandle;
begin
  Result := False;
  with Clipboard do begin
   try
    Open;
     if(HasFormat(CF_TEXT)) then begin
      hData := GetClipboardData(CF_TEXT) ;
      ps1 := GlobalLock(hData) ;
      dwLen := GlobalSize(hData) ;
      ps2 := StrAlloc(1 + dwLen) ;
      StrLCopy( ps2, ps1, dwLen ) ;
      GlobalUnlock( hData ) ;

      AssignFile(tf, sFileTXT) ;
      ReWrite(tf) ;
      Write(tf, ps2) ;
      CloseFile(tf) ;

      StrDispose( ps2 ) ;
      Result := True;
     end;
    finally
     Close;
   end;
  end;
end;
Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 03:13 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 12:10 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:41 delete

    moneyideas