کد دلفی - آیا متنی در کامپوننت TWebbrowser انتخاب شده است؟

(* ------------------------------ If you need to know if there is any text selected in a TWebbrowser use this code: Required unit: MSHTML // *) function HasSelection(Document: IHTMLDocument2): Boolean; var LEnabled: Boolean; pSel: IHTMLSelectionObject; pRange: IHTMLTxtRange; begin LEnabled := False; if Document < > nil then begin pSel := Document.selection as IHTMLSelectionObject; if pSel < > nil then begin if pSel.type_ = 'Text' then begin pRange := pSel.createRange as IHTMLTxtRange; if (pRange < > nil) and (Length(Trim(pRange.text)) > 0) then LEnabled := True; end; end; end; Result := LEnabled; end; // -------- // Usage: // -------- if HasSelection(WebBrowser1.Document as IHTMLDocument2) then begin // ... end;
/ 0 نظر / 1102 بازدید