Posts: 6
Threads: 2
Joined: Aug 2019
Reputation:
0
Location: Italy
I have a TIWText component called MyText.
I do
-- Any ASYNC event (for example OnAsyncClick of a TIWButton)
MyText.Text := 'My awesome text';
-- End of Any ASYNC event
The first time I see rendered the text 'My awesome text'.
If I run again the ASYNC event (I click again on the button), the TIWText does render nothing. Empty HTML.
If I use this workaround
-- Any ASYNC event (for example OnAsyncClick of a TIWButton)
MyText.Lines.Clear;
MyText.Lines.Add('My very beautiful text');
-- End of Any ASYNC event
Then everything work great.
Tried in 15.2.56 (D11.2), no other versions.
Thanks,
Eddy
Posts: 142
Threads: 28
Joined: May 2018
Reputation:
12
Location: Netherlands
Hi Eddy,
I assume you use IW15.2.65, the current latest version?
I tested this with IW15.2.65 and it works as expected. The second time you press the button nothing changes to the text property. The text stays the same. That's why no rendering event for the browser is needed. If you need it to render even if the text stays the same, you can also use MyText.Invalidate. In the end the effect is the same.
Posts: 142
Threads: 28
Joined: May 2018
Reputation:
12
Location: Netherlands
09-30-2022, 04:00 PM
(This post was last modified: 09-30-2022, 04:01 PM by jeroen.rottink.)
Hi Eddy,
That is because first you clear the lines resulting in Text = ''. After that you assign it the new text.
The same would be
begin
MyText.Text := '';
MyText.Text := 'My awesome text';
end;
When you write a 'Setter' for a property it is good practice to do:
procedure TMyClass.SetText(const AValue: string);
begin
if (FText <> AValue)
then begin
FText := AValue;
DoSomeChangeAction;
end;
end;
Hope this makes sense.
Posts: 2,257
Threads: 195
Joined: Mar 2018
Reputation:
86
Location: Auckland, New Zealand
If you need it to force refresh, call Invalidate method after changing the text.
Anyway... I believe the correct behavior should be: render whenever text changes, and don't render otherwise.
Posts: 6
Threads: 2
Joined: Aug 2019
Reputation:
0
Location: Italy
Sorry for the late.
Maybe I didn't explain well the issue.
If I set for the second time the "Text" property of MyText with same text, in an async mode, on the HTML I see the text that disappear.
If I do the same with "Lines" (even without "clear") the behaviour is correct.
I think that even if I set again the same text in a TIWText, then it must not be "cleaned" in HTML.
That's it.
Thanks