Forum > RichMemo
RichMemo.Color behaviour at Runtime
AgriMensor:
Hi!
I'm new to Pascal and Lazarus but have 25+ years of programming experience in other languages. Can anyone please help me with this problem?
I'm having difficulty changing the .Color at runtime in RichMemo. If I set it in the Object Inspector it works fine (on Windows 10 at least) but if I do something like the following, it changes the .color to black, not to the color selected from the ColorDialog. However, it does work fine for the ColorButton:
procedure TForm1.ColorButton2Click(Sender: TObject);
var
Fred : TColor;
begin
Fred := ColorDialog1.Color;
ColorButton2.ButtonColor := Fred; //Works OK
RichMemo1.Color := Fred; //Sets to Black
end;
Any helpful suggestions much appreciated!
Thanks,
Steve
skalogryz:
what an interesting bug.
try this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.ColorButton2Click(Sender: TObject);var Fred : TColor;begin if not ColorDialog1.Execute then Exit; Fred := ColorDialog1.Color; ColorButton2.ButtonColor := Fred; //Works OK RichMemo1.Color := Fred; //Sets to Blackend;
AgriMensor:
Many thanks, skalogryz, this has cured the problem, but begs the question 'Why?'
Interestingly, I did originally try something similar:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if ColorDialog1.Execute then begin Fred := ColorDialog1.Color; ColorButton2.ButtonColor := Fred; RichMemo1.Color := Fred; end;
with the same result as your code, but because both solutions make the ColorDialog appear twice (unless the Cancel button is pressed), I dropped the conditional clause.
So, it looks like that it's a case of the lesser of two evils :-(
Can this be reported as a bug and, if so, how?
Again, many thanks!
Steve
[Edited to add code tags; please read How to use the Forum].
AlexTP:
Before reporting, pls make tiny compilable example. (Attach in zip). I don't see that TColorDialog appears twice. Maybe you called .Execute twice.
AgriMensor:
Thanks Alextp!
I'm just testing RichMemo's capabilities and any potential flaws at the moment, so the relevant code is limited to that simple code already provided.
As far as I'm aware, I'm not calling ColorDialog twice. If you run the above code with just a ColorButton and a RichMemo on the form, you'll see that the RichMemo colour now changes just fine (as does the ColorButton) when you press the OK button on the ColorDialog, but the ColorDialog remains on screen (I believe it's actually a second instance) unless you press one of its buttons again. Interestingly, picking a different colour doesn't change the RichMemo colour again!
Steve
Navigation
[0] Message Index
[#] Next page