// نسخ عناصر الـ ListBox إلى الحافظة ...
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; if not CopyAll and ListBox.MultiSelect and (not ListBox.Selected) then Continue; // تفحص فيض الـ buffer Count := Count + Length(Line) + 3; if Count = BufferSize then Break; // نسخ إلى الـ 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; //نسخ العناصر إلى الحافظة procedure TForm1.Button1Click(Sender: TObject); begin ListBoxToClipboard(ListBox1, 1024, True); end; //النسخ من الحافظة إلى الـ ListBox2 procedure TForm1.Button2Click(Sender: TObject); begin ClipboardToListBox(Listbox2); end; //نسخ العناصر المحددة فقط من الـ ListBox إلى الحافظة procedure TForm1.Button3Click(Sender: TObject); begin ListBoxToClipboard(Listbox1, 1024, False); end;
المبرمج عماد ... B) B)