was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

26 Visitors Online


 
...die Items einer Listbox in die Zwischenablage kopieren?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (28):  
     


uses
  
Clipbrd;

procedure ListBoxToClipboard(ListBox: TListBox;
  BufferSize: Integer;
  CopyAll: Boolean);
var
  
Buffer: PChar;
  Size: Integer;
  Ptr: PChar;
  I: Integer;
  Line: string[255];
  Count: Integer;
begin
  if not 
Assigned(ListBox) then
    
Exit;

  GetMem(Buffer, BufferSize);
  Ptr   := Buffer;
  Count := 0;
  for I := 0 to ListBox.Items.Count - 1 do
  begin
    
Line := ListBox.Items.strings[I];
    if not CopyAll and ListBox.MultiSelect and (not ListBox.Selected[I]) then
      
Continue;
    { Check buffer overflow }
    
Count := Count + Length(Line) + 3;
    if Count = BufferSize then
      
Break;
    { Append to buffer }
    
Move(Line[1], Ptr^, Length(Line));
    Ptr    := Ptr + Length(Line);
    Ptr[0] := #13;
    Ptr[1] := #10;
    Ptr    := Ptr + 2;
  end;
  Ptr[0] := #0;
  ClipBoard.SetTextBuf(Buffer);
  FreeMem(Buffer, BufferSize);
end;

procedure ClipboardToListBox(ListBox: TListbox);
begin
  if not 
Assigned(ListBox) then
    
Exit;

  if not Clipboard.HasFormat(CF_TEXT) then
    
Exit;

  Listbox.Items.Text := Clipboard.AsText;
end;


//Copy all items from Listbox1 to the clipboard
procedure TForm1.Button1Click(Sender: TObject);
begin
  
ListBoxToClipboard(ListBox1, 1024, True);
end;

//Paste items in clipboard to Listbox2
procedure TForm1.Button2Click(Sender: TObject);
begin
  
ClipboardToListBox(Listbox2);
end;

//Copy only selected items from Listbox1 to the clipboard
procedure TForm1.Button3Click(Sender: TObject);
begin
  
ListBoxToClipboard(Listbox1, 1024, False);
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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