Autor Beitrag
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 17.05.05 15:22 
Hallo, ich möchte die Ausgewählten Items (können mehrere sein) einer Listbox in die Zwischenablage kopieren, sodass ich sie zb in wordpad wieder (mit zeilenumbrüchen) einfügen kann, wie mache ich das ?

Danke schonmal :wink:

hab da schonmal was gefunden:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
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;

mal gucken obs geht :?

funzt :mrgreen:

hätte man auch selbst drauf kommen können, aber warum mit mühe das rad neu erfinden :lol:
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 17.05.05 15:48 
Hallo,

darf es auch etwas einfacher sein :wink:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure LBSelectedToZwablage(LB: TListBox);
var S : String;
    z : Integer;
begin
  with LB do
    begin
    for z := 0 to Items.Count-1 do
      begin
      if Selected[z] then
        S := S+Items[z]+#13#10;
      end;
    ClipBoard.AsText := S;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  LBSelectedToZwablage(ListBox1);
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 17.05.05 15:49 
jo, aber funzt das auch wenn die LB leer ist ? :roll:

ok ich hab eh ne abfrage drin, weil itemindex darf nicht -1 sein

danke, dann kann ich auch deine nehmen, danke :D
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 17.05.05 16:03 
Hallo,

ja, weil die Schleife auf Count-1 basiert, und somit keinen Durchlauf hat. :wink:
Man könnte noch folgende Zeile hinzufügen, damit nur in die Zwablage geschrieben wird, wenn etwas zum Kopieren vorhanden ist:
ausblenden Delphi-Quelltext
1:
2:
if S <> '' then//neu
  ClipBoard.AsText := S;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )