whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

74 Visitors Online


 
...stream multiple components to clipboard?
Autor: Peter Below
[ Print tip ]  

Tip Rating (6):  
     


{
  Clipboard has  methods  GetComponent and SetComponent but we need
  to stream multiple components to the clipboard to include copy paste type
  of feature.

  Die Zwischenablage hat die Methoden GetComponent and SetComponent
  aber wir wollen mehrere Komponenten in die
  Zwischenablage speichern und wieder auslesen.
}


procedure CopyStreamToClipboard(fmt: Cardinal; S: TStream);
var
  
hMem: THandle;
  pMem: Pointer;
begin
  
S.Position := 0;
  hMem       := GlobalAlloc(GHND or GMEM_DDESHARE, S.Size);
  if hMem <> 0 then 
  begin
    
pMem := GlobalLock(hMem);
    if pMem <> nil then 
    begin
      
S.Read(pMem^, S.Size);
      S.Position := 0;
      GlobalUnlock(hMem);
      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
  
hMem := Clipboard.GetAsHandle(fmt);
  if hMem <> 0 then 
  begin
    
pMem := GlobalLock(hMem);
    if pMem <> nil then 
    begin
      
S.Write(pMem^, GlobalSize(hMem));
      S.Position := 0;
      GlobalUnlock(hMem);
    end { If }
    
else
      raise 
Exception.Create('CopyStreamFromClipboard: could not lock global handle ' +
        'obtained from clipboard!');
  end{ If }
end{ CopyStreamFromClipboard }


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners