1

Topic: File-> Clipboard....... Clipboard-> the File

Kind day of the Lord!
It is necessary to import a file to the buffer and it is reverse
I do so
[spoiler]

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;
Dialogs, StdCtrls, Clipbrd;
type
TForm1 = class (TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click (Sender: TObject);
procedure Button2Click (Sender: TObject);
procedure Button3Click (Sender: TObject);
private
{Private declarations}
public
{Public declarations}
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure CopyStreamToClipboard (fmt: Cardinal; S: TStream);
var
hMem: THandle;
pMem: Pointer;
begin
Assert (Assigned (S));
S.Position: = 0;
hMem: = GlobalAlloc (GHND or GMEM_DDESHARE, S.Size);
if hMem <> 0 then
begin
pMem: = GlobalLock (hMem);
if pMem <> nil then
begin
try
S.Read (pMem ^, S.Size);
S.Position: = 0;
finally
GlobalUnlock (hMem);
end;
Clipboard. Open;
try
Clipboard. SetAsHandle (fmt, hMem);
finally
Clipboard. Close;
end;
end {If}
else
begin
GlobalFree (hMem);
OutOfMemoryError;
end;
end {If}
else
OutOfMemoryError;
end; {CopyStreamToClipboard}
procedure CopyStreamFromClipboard (fmt: Cardinal; S: TStream);
var
hMem: THandle;
pMem: Pointer;
begin
Assert (Assigned (S));
hMem: = Clipboard. GetAsHandle (fmt);
if hMem <> 0 then
begin
pMem: = GlobalLock (hMem);
if pMem <> nil then
begin
try
S.Write (pMem ^, GlobalSize (hMem));
S.Position: = 0;
finally
GlobalUnlock (hMem);
end;
end {If}
else
raise Exception. Create (' CopyStreamFromClipboard: could not lock global handle ' +
' obtained from clipboard! ');
end; {If}
end; {CopyStreamFromClipboard}
procedure SaveClipboardFormat (fmt: Word; writer: TWriter);
var
fmtname: array [0. 128] of Char;
ms: TMemoryStream;
begin
Assert (Assigned (writer));
if 0 = GetClipboardFormatName (fmt, fmtname, SizeOf (fmtname)) then
fmtname [0]: = #0;
ms: = TMemoryStream. Create;
try
CopyStreamFromClipboard (fmt, ms);
if ms. Size> 0 then
begin
writer. WriteInteger (fmt);
writer. WriteString (fmtname);
writer. WriteInteger (ms. Size);
writer. Write (ms. Memory ^, ms. Size);
end; {If}
finally
ms. Free
end; {Finally}
end; {SaveClipboardFormat}
procedure LoadClipboardFormat (reader: TReader);
var
fmt: Integer;
fmtname: string;
Size: Integer;
ms: TMemoryStream;
begin
Assert (Assigned (reader));
fmt: = reader. ReadInteger;
fmtname: = reader. ReadString;
Size: = reader. ReadInteger;
ms: = TMemoryStream. Create;
try
ms. Size: = Size;
reader. Read (ms.memory ^, Size);
if Length (fmtname)> 0 then
fmt: = RegisterCLipboardFormat (PChar (fmtname));
if fmt <> 0 then
CopyStreamToClipboard (fmt, ms);
finally
ms. Free;
end; {Finally}
end; {LoadClipboardFormat}
procedure SaveClipboard (S: TStream);
var
writer: TWriter;
i: Integer;
begin
Assert (Assigned (S));
writer: = TWriter. Create (S, 4096);
try
Clipboard. Open;
try
writer. WriteListBegin;
for i: = 0 to Clipboard.formatcount - 1 do
SaveClipboardFormat (Clipboard. Formats [i], writer);
writer. WriteListEnd;
finally
Clipboard. Close;
end; {Finally}
finally
writer. Free
end; {Finally}
end; {SaveClipboard}
procedure LoadClipboard (S: TStream);
var
reader: TReader;
begin
Assert (Assigned (S));
reader: = TReader. Create (S, 4096);
try
Clipboard. Open;
try
clipboard. Clear;
reader. ReadListBegin;
while not reader. EndOfList do
LoadClipboardFormat (reader);
reader. ReadListEnd;
finally
Clipboard. Close;
end; {Finally}
finally
reader. Free
end; {Finally}
end; {LoadClipboard}
//Examples:
{Save Clipboard}
procedure TForm1.Button1Click (Sender: TObject);
var
ms: TMemoryStream;
begin
ms: = TMemoryStream. Create;
try
SaveClipboard (ms);
ms. SaveToFile (' c:\temp\save.dat ');
finally
ms. Free;
end; {Finally}
end;
{Clear Clipboard}
procedure TForm1.Button2Click (Sender: TObject);
begin
clipboard. Clear;
end;
{Restore Clipboard}
procedure TForm1.Button3Click (Sender: TObject);
var
fs: TfileStream;
begin
fs: = TFilestream. Create (' C:\Temp\load.dat ', fmOpenRead);
try
LoadClipboard (fs);
finally
fs. Free;
end; {Finally}
end;
end.

[/spoiler]
Error here
reader: = TReader. Create (S, 4096);
Prompt how to correct... Thanks
(Like in Null I fall)

2

Re: File-> Clipboard....... Clipboard-> the File

HOME_X wrote:

Prompt as to correct

1) to Throw out  the code which is not corresponding to the task.
2) To be defined with the task.
3) to Write the correct code.

3

Re: File-> Clipboard....... Clipboard-> the File

Dimitry Sibiryakov wrote:

it is passed...
1) to Throw out  the code which is not corresponding to the task.
2) To be defined with the task.
3) to Write the correct code.

The task
- File in a clipboard to load
- File from a clipboard to preempt
- You awake to invent the decisions?
- Or throw off similar links (google) in an image of the help?
- Or on the basis of already ready implementation correct possible inaccuracies?

4

Re: File-> Clipboard....... Clipboard-> the File

HOME_X wrote:

the Task
- File in a clipboard to load
- File from a clipboard to preempt

What file? Text? Graphic? Any another?
What further with these contents of a clipboard will become? Into the document to be interposed? In
Explorer?
Depending on answers to these questions the code will be absolutely different.

5

Re: File-> Clipboard....... Clipboard-> the File

Dimitry Sibiryakov;
It would be desirable
- To have under loading ANY file (txt, zip, exe, msi)
- On the the PC loaded a file in a clipboard
- Passage on the remote PC (the buffer content was transferred)
- Outswapping from the buffer of the remote PC in the same format
What for it is necessary?
On a building of a trust relationships policy of the enterprise I have
But transfer of files is forbidden, I try to compensate for the deficiency
Transfer files of great volumes certainly it is impossible, but small
The sizes .
Thanks

6

Re: File-> Clipboard....... Clipboard-> the File

Then file loading in a clipboard is not necessary to you. And the program is not necessary. You open
Explorer here, an explorer there - also it is ready. And if so access to the remote does not work also
To clipboard it is forbidden - your program too can nothing.

7

Re: File-> Clipboard....... Clipboard-> the File

HOME_X wrote:

the Task
- File in a clipboard to load
- File from a clipboard to preempt

And the buffer does not burst from a file?

8

Re: File-> Clipboard....... Clipboard-> the File

HOME_X wrote:

What for it is necessary?
On a building of a trust relationships policy of the enterprise I have
But transfer of files is forbidden, I try to compensate for the deficiency
Transfer files of great volumes certainly it is impossible, but small
The sizes .

mail, dropbox, litemanager, teamviewer

9

Re: File-> Clipboard....... Clipboard-> the File

HOME_X wrote:

On a building of a trust relationships policy of the enterprise I have
But transfer of files is forbidden, I try to compensate for the deficiency

This direct violation of "an enterprise trust relationships policy"

10

Re: File-> Clipboard....... Clipboard-> the File

Dimitry Sibiryakov;
Access to the buffer is resolved... !
It is impossible to swing only files through an explorer - too !
What for so - well I do not know, so it is conceived.
So implementation prompt?

11

Re: File-> Clipboard....... Clipboard-> the File

I do not know, but even more often I think that  in the buffer should live no more minutes (60s)
Well because printing/imposing texts/pictures you it you do quickly,
And what for to store the buffer while you have dinner in a dining room...
Or you extinguish a fire (God forbid)

12

Re: File-> Clipboard....... Clipboard-> the File

DimaBr;
You when the last time paid for the license (it is unimportant what software)?
And if paid as paid back expenses?
"The kind" chief selected the budget?
To me is not present - speak well you understand - "it should be made"?
Still "correct" remarks are?

13

Re: File-> Clipboard....... Clipboard-> the File

Gator wrote:

I do not know, but even more often I think that  in the buffer should live no more minutes (60s)
Well because printing/imposing texts/pictures you it you do quickly,
And what for to store the buffer while you have dinner in a dining room...
Or you extinguish a fire (God forbid)

Who told - that I will store?
It is necessary to transfer only a few data there and reversely?
It is possible to receive council about the code how to implement?

14

Re: File-> Clipboard....... Clipboard-> the File

HOME_X wrote:

Access to the buffer is resolved... !
It is impossible to swing only files through an explorer - too !

Then break off. It won't work.

15

Re: File-> Clipboard....... Clipboard-> the File

HOME_X, And here?
You about what such "" speak?
You give do not confuse commercial offices (a software selling)
And their employees, who put pirates for training and development (including ) - they after all do not sell anything!

16

Re: File-> Clipboard....... Clipboard-> the File

Dimitry Sibiryakov;
Justify... Why it is impossible to tire out a file in the buffer
In what a difference between Ctrl+C (buffer) and info in the buffer is simple?

17

Re: File-> Clipboard....... Clipboard-> the File

Gator wrote:

HOME_X, And here?
You about what such "" speak?
You give do not confuse commercial offices (a software selling)
And their employees, who put pirates for training and development (including ) - they after all do not sell anything!

Yes is not present - simply person (DimaBr) wants looks correct
I as a whole not against, but only somehow am feeble in life it turns out
Let's talk about a message essence... Where an error?

18

Re: File-> Clipboard....... Clipboard-> the File

HOME_X wrote:

where an error?

IN DNA.

19

Re: File-> Clipboard....... Clipboard-> the File

HOME_X;
1. It is possible to try .
2. If all is closed - that the buffer in any way does not help.

20

Re: File-> Clipboard....... Clipboard-> the File

HOME_X wrote:

Who told - that I will store?
It is necessary to transfer only a few data there and reversely?
It is possible to receive council about the code how to implement?

you can look for networks.
To me interesting another: Who told - that I will store? And what for you want to spoil the data of the user?
And council "on the code" - them as a dirt.
Check! Me for such here kicked, washed and so forth even worse... About 10 years ago.
Since then I like.
For " It is necessary to transfer only a few data there and reversely " open to itself , wm_command etc
IT IS NOT NECESSARY TO CONTACT THE CLIPBOARD!!!
(hi-hi) a tour operator Slogan:
There-here-back and  it is pleasant

Well, and if you want to attack an old rake and to receive spalls on eggs;
Present...
Your user (the client of yours ) skontrol-iksil (CTRL+X) two pages from a Word.
Here you got with (ostensibly "the" buffer)...

21

Re: File-> Clipboard....... Clipboard-> the File

HOME_X wrote:

Let's talk about a message essence... Where an error?

to Speak there is nothing.
Try to answer two simple question:
- What is the FILE? What it of a format?
- What is the text? In what it to the coding?
______________
Where an error?
Probably in a choice.
IT - not yours! Well even questions... In 21 century... Not . Excuse!!! (Though to me - it is cold, hot)
Perhaps from you the yard keeper good turns out... Also there will be Nach. Housing and communal services and then the mayor.
Or  you will become and then  you will recover both the minister and the prime minister...
Or in agricultural then the whole world you will feed...
But if itself the book you will not read;
That and not . Anybody on shoulders does not deliver the head to you...

22

Re: File-> Clipboard....... Clipboard-> the File

Generally speaking, strange.
The HARDWARE (judging by niku-memberu) such snowstorm should not plant...
Here I was moved...

23

Re: File-> Clipboard....... Clipboard-> the File

HOME_X wrote:

you when the last time paid for the license (it is unimportant what software)?
And if paid as paid back expenses?
"The kind" chief selected the budget?
To me is not present - speak well you understand - "it should be made"?
Still "correct" remarks are?

And here the license for a computer standing at the enterprise and attempt to steal the data from this computer.
You pay for the license not, and the enterprise, and here to steal files just you want. That is go against an enterprise policy on which work.

24

Re: File-> Clipboard....... Clipboard-> the File

How the clipboard works - if it synchronizes at the moment of copying it turns out. And if it is synchronized only at an input/exit in virtualku/udalenku does not quit. The approximate decision:
- We do two utilities. One writes to the buffer of a part of a file, and another reads them;
- If a file big we write parts - one part wrote down, waited, while it read and "delete", and it is writeable the following;
- On other side the utility  the buffer, reads a part, starts to write a file on a disk and waits for the next portion of the data;
- It is possible to read files in a flow, the equal sizes, for example, on 1000 to translate in base64, to mark in the beginning that is a file. And in the end to add a label that is the file end.
For example:
- There is a file "topsecret.txt" with the big content;
- We read in a flow one part, we translate in base64 these bytes and we write to the buffer with beginning labels: FILESTART:topsecret.txt:0YHQtdC60YDQtdGC0L3Ri9C5INGE0LDQudC7
- We wait, while the buffer (a sign that the data from that side accepted) will be cleared or thrown off on the timer (if to accept there is nobody)
- We read the following part of the data and we write in the same way... And if suddenly the file end it is added in the end:FILEEND.

25

Re: File-> Clipboard....... Clipboard-> the File

We do a program which the binary file loses as video from QR-code frames
We remove it on a normal videocamera, then we decode
The clipboard is not necessary :-)