Why `TRVStyleTemplate(nil).ApplyToTextStyle` works??

General TRichView support forum. Please post your questions here
Post Reply
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Why `TRVStyleTemplate(nil).ApplyToTextStyle` works??

Post by edwinyzh »

I've found many occurrences of

Code: Select all

TRVStyleTemplate(nil).ApplyToTextStyle
in the TRichView codebase, but it puzzles me - why casting nil as TRVStyleTemplate works??

Anyone can tell me? Thanks.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Why `TRVStyleTemplate(nil).ApplyToTextStyle` works??

Post by Sergey Tkachenko »

TRVStyleTemplate.ApplyToTextStyle was designed to work correctly if called for nil objects.
The code inside this method checks if Self = nil, and if True, it unassigns the text style (from the parameter) from a text style template.
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

Re: Why `TRVStyleTemplate(nil).ApplyToTextStyle` works??

Post by edwinyzh »

Oh I see, thanks!
Post Reply