function _hread(FileHandle:word; BufPtr:pointer; ByteCount:longint):longint; far;external 'KERNEL' index 349; Procedure CopyFileToClipboard( Const fname: String ); Varhmem, hFile : THandle;size : LongInt;p : Pointer;BeginhFile := FileOpen( fname, fmOpenRead );trysize := FileSeek( hFile, 0, 2 );FileSeek( hfile, 0, 0 );If size > 0 Then Beginhmem := GlobalAlloc( GHND, size );If hMem <> 0 Then Beginp := GlobalLock( hMem );If p <> Nil Then Begin_hread( hFile, p, size );GlobalUnlock( hMem );Clipboard.SetAsHandle( CF_TEXT, hMem );EndElseGlobalFree( hMem );End;End;finallyFileClose( hFile );end;End; procedure TForm1.SpeedButton2Click(Sender: TObject); Var fname: String[128];begin If OpenDialog1.Execute Then Beginfname := OpenDialog1.Filename;CopyFileToClipboard( fname );End;end; |
- Peter Below [000799]