[SOLVED]why can't use Memo1.Text.Length ? lazarus / 31-LCL ---------------------------------------------------------------------- tomitomy · 2017-11-08 12:31 Hi, I have a problem, when I use Memo1.Text, I can't use the methods of string, I don't know why. The following code can not be compiled: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  Caption := Memo1.Text.Length.ToString;end; Is this a bug? Lazarus: 1.8.0 RC4 GTK2 OS: Linux Mint Mate 64-bit ---------------------------------------------------------------------- howardpc · 2017-11-08 12:36 It's not a bug. Text is a property of TMemo, not a simple variable. If you copy Text to a local string variable, you can use any of the string helper functions on the local variable. ---------------------------------------------------------------------- tomitomy · 2017-11-08 12:41 I understand, Thank you howardpc! ---------------------------------------------------------------------- Noodly · 2017-11-08 12:58 This would also work: Code: [Select]procedure TForm1.FormCreate(Sender: TObject); begin   Caption := IntToStr(length(Memo1.Text)); end; ---------------------------------------------------------------------- tomitomy · 2017-11-08 13:03 Quote from: Noodly on November 08, 2017, 01:58:40 pmThis would also work: Code: [Select]procedure TForm1.FormCreate(Sender: TObject); begin   Caption := IntToStr(length(Memo1.Text)); end; Thank you Noodly , I have another way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  Caption := string(Memo1.Text).Length.ToString;end; ---------------------------------------------------------------------- ASerge · 2017-11-09 20:14 The types of TCaption and string are different. Operators from type helper for string are not applicable to type TCaption. ---------------------------------------------------------------------- tomitomy · 2017-11-10 04:54 Quote from: ASerge on November 09, 2017, 09:14:17 pmThe types of TCaption and string are different. Operators from type helper for string are not applicable to type TCaption. I don't understand, what's the difference? Can I use "string(Memo1.Text).Length.ToString" This usage? ---------------------------------------------------------------------- howardpc · 2017-11-10 08:46 As ASerge writes, it is a difference of type. Pascal is a very strongly typed language, so helpers defined for one type are not magically defined for another type, even if the types are simply aliases for each other. TCaption is an alias for TTranslateType, which is an alias for String. So the cast String(Memo1.Text) is quite safe, since fundamentally they are the "same" type. But to the compiler they are distinct types (notwithstanding their equivalence), and a helper defined for String is not thereby a helper for TCaption. ---------------------------------------------------------------------- tomitomy · 2017-11-10 10:38 Thank you howardpc, I understand. ---------------------------------------------------------------------- wp · 2017-11-10 10:43 Why are so many people up to the "modern" syntax "Memo1.Text.Length.ToString" and refuse to apply the "old-fashioned" Syntax "IntToStr(length(Memo1.Text))"? Having to type 4 brackets instead of 2 points? ---------------------------------------------------------------------- balazsszekely · 2017-11-10 10:48 @wp QuoteWhy are so many people up to the "modern" syntax "Memo1.Text.Length.ToString"Bad habit inherited from c#. ---------------------------------------------------------------------- tomitomy · 2017-11-10 12:06 I think it is more natural to read it this way, and there will be syntax prompt after entering the dot. I am unfamiliar with many function names, and I hope the syntax prompt can be a bit more powerful. like this: Code: [Select]Something.ABCD prompt->  ABCD           ABCD+++           A++B++C++D ---------------------------------------------------------------------- Thaddy · 2017-11-10 12:08 Quote from: GetMem on November 10, 2017, 11:48:00 am@wp QuoteWhy are so many people up to the "modern" syntax "Memo1.Text.Length.ToString"Bad habit inherited from c#. c#. Java... Imho not a bad habit, but a good thing... Aside, on topic, ToString should work, but is an AnsiString, not UTF8. There are no type helpers yet for UTF8. ---------------------------------------------------------------------- Mike.Cornflake · 2017-11-11 19:24 Quote from: wp on November 10, 2017, 11:43:37 amWhy are so many people up to the "modern" syntax "Memo1.Text.Length.ToString" and refuse to apply the "old-fashioned" Syntax "IntToStr(length(Memo1.Text))"? Having to type 4 brackets instead of 2 points? lol  As I get older, I find myself saying this about so many different things :-) But as for the string helpers themselves.  Wow, I had no idea we had those.  Coming back to the forum after a few years away is definitely making me feel my age :-)  I've already had more than a few double takes seeing code like s += 'This would never have worked in my day'; and I knew about the operator helpers...