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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| uses
// (...)
ClipBrd;
var
CF_HTML: UINT;
function ClipboardHtmlToString: string;
var
Data: THandle;
Ptr: PChar;
begin
Result := '';
with Clipboard do begin
Open;
try
Data := GetAsHandle(CF_HTML);
if Data <> 0 then begin
Ptr := GlobalLock(Data);
if Ptr <> nil then begin
try
Result := string(Ptr);
finally
GlobalUnlock(Data);
end;
end;
end;
finally
Close;
end;
end;
end;
procedure TForm1.btnCollerClick(Sender: TObject);
var
slItems, slClipBoard: TStringList;
s, sItem, sTmp: string;
i1, iCount: Integer;
begin
slClipBoard := TStringList.Create;
try
slClipBoard.Text := Clipboard.AsText;
iCount := 0;
s := ClipboardHtmlToString; // \\ // \\ Sous Wine, retourne "<" au lieu du contenu complet !? // \\ // \\
// ShowMessage(s);
if Pos('monsite1.com', s) > 0 then begin
slItems := TStringList.Create;
try
repeat
Split(slClipBoard[iCount], #9, slItems); // #9 = TAB
sItem := Trim(slItems[1]);
i1 := Pos(' -', sItem) + 1;
if Length(sItem) = i1 then
SetLength(sItem, i1 - 1);
edt[iCount, 0].Text := sItem;
edt[iCount, 1].Text := Trim(slItems[2]);
Inc(iCount);
until (iCount >= slClipBoard.Count) or (iCount >= speNbItems.IntValue);
finally
slItems.Free;
end;
end
else if Pos('monsite2.com', s) > 0 then begin
repeat
sTmp := Trim(slClipBoard[5 * iCount]);
i1 := Pos(' ', sTmp);
sItem := Copy(sTmp, i1, Length(sTmp));
edt[iCount, 0].Text := Trim(sItem);
edt[iCount, 1].Text := slClipBoard[5 * iCount + 4];
Inc(iCount);
until ((5 * iCount) >= slClipBoard.Count) or (iCount >= speNbItems.IntValue);
end
else if Pos('monsite3.com', s) > 0 then begin
slClipBoard.Delete(0); // Supprime la première ligne, vide
repeat
edt[iCount, 0].Text := Trim(slClipBoard[8 * iCount + 1]);
edt[iCount, 1].Text := Trim(slClipBoard[8 * iCount + 5]);
Inc(iCount);
until ((8 * iCount) >= slClipBoard.Count) or (iCount >= speNbItems.IntValue);
end;
finally
slClipBoard.Free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CF_HTML := RegisterClipboardFormat('HTML Format');
end; |
Partager