View Issue Details

IDProjectCategoryView StatusLast Update
0032296Lazarus CCRPackagespublic2020-09-29 10:15
ReporterDavid Assigned ToDmitry Boyarintsev  
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
PlatformWindows 
Summary0032296: RichMemo.GetTextAttributes() does not return false when first param out of range
DescriptionFirst Param to this function points to a char in the Memo that it should report on. The function is described as returning False if the indicated char is somehow invalid. Passing -1 or a number greater than RichMemo.GetTexLen() however returns True.
Works fin under Linux.
Steps To Reproduce
if Richmemo1.GetTextAttributes(-1, FP) then showmessage('Failed on -1');
if Richmemo1.GetTextAttributes(30000, FP) then showmessage('Failed on 30000');
Additional InformationAn easy fix appears to add a test at entry into the function, insert into line 677 of RichMemo.pas -

677 Result := False;
678 if (textStart < 0) or (TextStart >= GetTextLen) then exit();

Its unnecessary under linux but does no harm. I have tested under Win10 and GTK2 based Linux.
TagsNo tags attached.
WidgetsetWin32/Win64
Attached Files

Activities

David

2017-09-16 10:29

reporter   ~0102866

This approach does not work on Cocoa because GetTextLen is also not working there. So, it becomes length(Lines.Text) unless GetTextLen is fixed first. I wish ....

Dmitry Boyarintsev

2020-01-13 16:09

developer   ~0120406

please test and close if ok

David

2020-02-13 02:09

reporter   ~0121075

Thanks Dmitry, all good.

David

2020-09-26 02:24

reporter   ~0125864

Sorry to have to reopen however, does not work on the Mac. Back in Feb, I tested on Linux/Windows because I did not have my old Mac with me. Sadly I did not look at the code, just tested.
As I note in the report, we cannot use GenTextLen() on the Mac, it fails. You have called a function, TCustomRichMemo.isValidCharOfs(), 0001128 of RichMemo.pas and it calls GetTextLen().
If you still want to use isValidCharOfS() then it needs to be patched to avoid GetTextLen(). Its ugly but this works -

function TCustomRichMemo.isValidCharOfs(TextStart: integer): Boolean;
begin
  // TextStart, where TextStart = GetTextLen, is a location at the end of the text
  // it's technically a valid character offset (position)
  // Because it's where the entry should occur
  {$ifdef LCLCOCOA}Result := (TextStart >= 0) and (TextStart <= UTF8length(Text));
  {$else}Result := (TextStart >= 0) and (TextStart <= GetTextLen);{$endif} // DRB 2020-09-25
end;

Without either this ugly fix or a working GetTextlen() almost all of RichMemo does not work on the Mac.

Very sorry I have taken so long to looking at this on the Mac !

Davo

David

2020-09-29 03:14

reporter   ~0125950

Worth holding off on this, I have a working fix for gentextlen that is much better solution. Will need to do some extensive testing first ....

David

2020-09-29 10:15

reporter   ~0125954

A far better solution to this problem is detailed in 37835, please disregard this issue (apparently I cannot re-close it ??).

Issue History

Date Modified Username Field Change
2017-08-19 12:41 David New Issue
2017-08-19 15:08 Bart Broersma Project Packages => Lazarus CCR
2017-09-16 10:29 David Note Added: 0102866
2019-01-29 19:56 Dmitry Boyarintsev Status new => assigned
2019-01-29 19:56 Dmitry Boyarintsev Assigned To => Dmitry Boyarintsev
2020-01-13 16:09 Dmitry Boyarintsev Status assigned => resolved
2020-01-13 16:09 Dmitry Boyarintsev Resolution open => fixed
2020-01-13 16:09 Dmitry Boyarintsev Widgetset Win32/Win64 => Win32/Win64
2020-01-13 16:09 Dmitry Boyarintsev Note Added: 0120406
2020-02-13 02:09 David Status resolved => closed
2020-02-13 02:09 David Note Added: 0121075
2020-09-26 02:24 David Status closed => feedback
2020-09-26 02:24 David Resolution fixed => open
2020-09-26 02:24 David Note Added: 0125864
2020-09-29 03:14 David Note Added: 0125950
2020-09-29 03:14 David Status feedback => assigned
2020-09-29 10:15 David Note Added: 0125954