Guest User

Untitled

a guest
May 26th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. procedure Tuiwin.Copy1Click(Sender: TObject);
  2. var
  3. lv:tlistview;
  4. i,j,b,cols,items,x,len,newLen,margin:integer;
  5. str:string;
  6. arr1:array of array of string;
  7. tempList:tstringlist;
  8. begin
  9. if strClipboard = '' then
  10. begin
  11. if focusItem is TEdit then showmessage('g');
  12.  
  13. if focusItem is TListView then
  14. begin
  15. tempList := tstringlist.create;
  16. lv := TListView(focusItem);
  17. cols := lv.Columns.Count;
  18. str := '';
  19. items := 0;
  20. x := 1;
  21. margin := 4;
  22.  
  23. for i := 0 to lv.Items.Count -1 do
  24. if lv.Items[i].Selected then inc(items);
  25.  
  26. SetLength(arr1,items+1,cols); //prepare array
  27.  
  28. for i := 0 to lv.Columns.Count -1 do
  29. arr1[0][i] := lv.Columns[i].Caption;
  30.  
  31. for j := 0 to lv.items.Count - 1 do
  32. begin
  33. if lv.Items[j].Selected then
  34. begin
  35. arr1[x][0] := lv.Items.Item[j].Caption;
  36. for b := 0 to lv.Columns.Count -2 do
  37. begin
  38. arr1[x][b+1] := lv.Items.Item[j].SubItems[b];
  39. end;
  40. inc(x);
  41. end;
  42. end;
  43.  
  44. //determine the longest string length
  45. for i := 0 to length(arr1[0]) -1 do
  46. begin
  47. len := 0;
  48. for j := 0 to length(arr1) - 1 do
  49. begin
  50. newLen := length(arr1[j][i]);
  51. if newLen > len then len := NewLen;
  52. end;
  53. tempList.Add(inttostr(len))
  54. end;
  55.  
  56. for i := 0 to length(arr1[0]) - 1 do
  57. str := str + FillBlankSpace(LengthDifference(arr1[0][i],strtoint(tempList.Strings[i])),' ') + arr1[0][i] + FillBlankSpace(margin,' ');
  58.  
  59. str := str + #13#10;
  60.  
  61. for i := 1 to length(arr1) - 1 do
  62. begin
  63. for j := 0 to length(arr1[0]) - 1 do
  64. begin
  65. str := str + FillBlankSpace(LengthDifference(arr1[i][j],strtoint(tempList.Strings[j])),' ') + arr1[i][j] + FillBlankSpace(margin,' ');
  66. end;
  67. str := str + #13#10;
  68. end;
  69. strClipboard := str;
  70. tempList.free;
  71. end;
  72. end;
  73.  
  74. //send text to clipboard
  75. clipboard.AsText := strClipboard;
  76.  
  77. strClipboard := '';
  78. end;
Add Comment
Please, Sign In to add comment