{"action":"created","issue":{"url":"https://api.github.com/repos/BerndGabriel/HtmlViewer/issues/85","labels_url":"https://api.github.com/repos/BerndGabriel/HtmlViewer/issues/85/labels{/name}","comments_url":"https://api.github.com/repos/BerndGabriel/HtmlViewer/issues/85/comments","events_url":"https://api.github.com/repos/BerndGabriel/HtmlViewer/issues/85/events","html_url":"https://github.com/BerndGabriel/HtmlViewer/issues/85","id":73709670,"number":85,"title":"FindSourcePos bug (and probable solution)","user":{"login":"Micrologus","id":12280237,"avatar_url":"https://avatars.githubusercontent.com/u/12280237?v=3","gravatar_id":"","url":"https://api.github.com/users/Micrologus","html_url":"https://github.com/Micrologus","followers_url":"https://api.github.com/users/Micrologus/followers","following_url":"https://api.github.com/users/Micrologus/following{/other_user}","gists_url":"https://api.github.com/users/Micrologus/gists{/gist_id}","starred_url":"https://api.github.com/users/Micrologus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Micrologus/subscriptions","organizations_url":"https://api.github.com/users/Micrologus/orgs","repos_url":"https://api.github.com/users/Micrologus/repos","events_url":"https://api.github.com/users/Micrologus/events{/privacy}","received_events_url":"https://api.github.com/users/Micrologus/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/BerndGabriel/HtmlViewer/labels/bug-confirmed","name":"bug-confirmed","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-06T19:10:53Z","updated_at":"2015-05-15T15:30:13Z","closed_at":null,"body":"I have an HTML string, I load it in an THtmlViewer component, and then I click on the viewer with the mouse and I want to find the corresponding position in the HTML source. The code to find the source position should go something like this\r\n\r\n    // X and Y are the mouse coordinates:\r\n    DP := HtmlViewer1.XYToDisplayPos(X, Y);\r\n    // DP is an integer:\r\n    SP := HtmlViewer1.FindSourcePos(DP);\r\n\r\n...and now SP should contain the index of the position in the source code.\r\n\r\nHowever, when I look for the text in HtmlViewer1.DocumentSource near position SP, it's clearly the wrong place.\r\n\r\nThen, after a lot of head scratching, I found that the correct position is SP div 2. If I divide the result of FindSourcePos by two, that is the correct result.\r\n\r\nIf this is a bug, it guess that it has something to do with the AnsiString vs. WideString format of the HTML source.\r\n\r\nHopefully this will be helpful to someone... cheers :)"},"comment":{"url":"https://api.github.com/repos/BerndGabriel/HtmlViewer/issues/comments/102432926","html_url":"https://github.com/BerndGabriel/HtmlViewer/issues/85#issuecomment-102432926","issue_url":"https://api.github.com/repos/BerndGabriel/HtmlViewer/issues/85","id":102432926,"user":{"login":"Micrologus","id":12280237,"avatar_url":"https://avatars.githubusercontent.com/u/12280237?v=3","gravatar_id":"","url":"https://api.github.com/users/Micrologus","html_url":"https://github.com/Micrologus","followers_url":"https://api.github.com/users/Micrologus/followers","following_url":"https://api.github.com/users/Micrologus/following{/other_user}","gists_url":"https://api.github.com/users/Micrologus/gists{/gist_id}","starred_url":"https://api.github.com/users/Micrologus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Micrologus/subscriptions","organizations_url":"https://api.github.com/users/Micrologus/orgs","repos_url":"https://api.github.com/users/Micrologus/repos","events_url":"https://api.github.com/users/Micrologus/events{/privacy}","received_events_url":"https://api.github.com/users/Micrologus/received_events","type":"User","site_admin":false},"created_at":"2015-05-15T15:30:13Z","updated_at":"2015-05-15T15:30:13Z","body":"Right you are... I was sending plain ASCII strings without UTF8 encoded chars, so in that case UnicodeString / WideString is exactly twice the size, but that will not always be the case, e.g. if any UTF8 is there. \r\n\r\nIf I manage to improve the situation I'll contribute the code here.\r\n\r\nThanks for all the great work on this useful component :)\r\n\r\nMarco"}}