Go Back   Wiki NewForum > Career Forum > Tech Forum & Tutorial > Oracle Database, SQL, Application, Programming

Sponsored Links

Click Here to see Poll Results @ Poll
Reply
Views: 1678  
Thread Tools Rate Thread Display Modes
  #1  
Old 08-20-2010, 11:21 AM
bholas bholas is offline
Award Winner
 
Join Date: Apr 2010
Posts: 5,181
Default How to save clipboard data to a file

Looking for a way to save the data in the clipboard to a file in a hurry? All you have to do is call the following SaveClipboardTextDataToFile() function with the file name:

SaveClipboardTextDataToFile( 'c:\temp.txt' );
Please note that the following code is written to handle only text data in the clipboard. You can easily change this by modifying the clipboard data format specified -- CF_TEXT -- and changing the file handling methods.

function SaveClipboardTextDataToFile(
sFileTo : 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, sFileTo );
ReWrite( tf );
Write( tf, ps2 );
CloseFile( tf );

StrDispose( ps2 );

Result := True;
end;
finally
Close;
end;
end;
end;

Reply With Quote
Reply

Tags
programming tips

New topics in Oracle Database, SQL, Application, Programming


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump


Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2020, vBulletin Solutions, Inc.