* * *

Author Topic: SetLink(...) fails on Linux  (Read 232 times)

dbannon

  • New member
  • *
  • Posts: 34
SetLink(...) fails on Linux
« on: August 09, 2017, 10:34:54 am »
Procedure RichMemo1.SetLink(...);  does not appear to work on linux. Ubuntu Mate 17.04 and Lazarus 1.8.0RC3. Sometimes (see below).

 I have a unit of about 500 lines in total that works around a RichMemo control. Does not appear to make any changes to text.

I have checked with the debugger that I am passing valid parameters, right down to line #1348 of GTK2RichMemo where it calls -

gtk_text_buffer_apply_tag_by_name(buffer, TagNameLink, @istart, @iend);

The GTK Buffer does seem to have a valid 'link' entry in its TagTable but it still, apparently fails. Can anyone suggest how I can further debug ?

Interestingly, a bare bones form does work. Wondering if I should slowly add back my code to that bare bones app and see when it breaks ? And it works unconditionally under Windows but it obviously uses different code.

david

dbannon

  • New member
  • *
  • Posts: 34
Re: SetLink(...) fails on Linux
« Reply #1 on: August 09, 2017, 01:16:02 pm »
OK, simplified version reveals something.  Seems that text written into RichMemo using Append can be marked as a Link but NOT that added using RichMemoUtils.InsertFontText(RichMemo1, 'This is a link in some text', FP, -1);   So, as I can demonstrate,

Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   FP :  TFontParams;
  4. begin
  5.   RichMemo1.Clear;
  6.   FP.Size:= 10;
  7.   FP.Color := clBlack;
  8.   FP.Style := [];
  9.   FP.HasBkClr := false;
  10.   FP.BkColor := clYellow;
  11.   FP.VScriptPos := vpNormal;
  12.   RichMemo1.Append('This is a link in some text');
  13.   InsertFontText(RichMemo1, 'This is a link in some text', FP, -1);
  14.   RichMemo1.Append('This is a link in some text');
  15.   InsertFontText(RichMemo1, 'This is a link in some text', FP, -1);
  16. end;
   

and then calling -

Code: Pascal  [Select]
  1. procedure TForm1.ButtonLinkClick(Sender: TObject);
  2. var
  3.     Beginning, Start, len, Textlength : longint;
  4. begin
  5.   TextLength := RichMemo1.GettextLen();
  6.   Beginning := 0;
  7.   while  RichMemo1.Search('link', Beginning, TextLength, [], Start, Len) do begin
  8.       Richmemo1.SetLink(Start, 4, true, 'local:link');
  9.       Beginning := Start+1;
  10.   end;
  11. end;
   

Only the first and third 'link' will get marked.

So, something about an existing tag is preventing a bit of the text being marked as a link ?? Maybe I'll experiment with clearing the text first ?

David

dbannon

  • New member
  • *
  • Posts: 34
Re: SetLink(...) fails on Linux
« Reply #2 on: August 10, 2017, 09:08:13 am »
OK, here is a solution that suits me, maybe not everyone though.

Add a line to  GTK2RichMemo, #1349 in  class procedure Gtk2WSCustomRichMemo.SetTextUIParams(...) just before the call to gtk_text_buffer_apply_tag_by_name(...) -
Code: Pascal  [Select]
  1. gtk_text_buffer_remove_all_tags(buffer,  @istart, @iend);
This will clear all tags and so gtk_text_buffer_apply_tag_by_name(...) has no problem setting 'link'. I am afraid I do not know why this is necessary and, yes, it will obviously clear tags on that text you may want there so, I don't think its a great solution, just one that suits me and is, perhaps, better than the existing behaviour.
David

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus