Compiler undescisive... lazarus / 61-Beginners ---------------------------------------------------------------------- Birger52 · 2019-05-03 22:04 Creating a class for some data - deriving from TObject. A.o. I need to write the object(s) to a file. It can contain som danish characters, so I need it to be a unicodestring. 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 function ToString : unicodestring; override;compiler complains, that there is no ancestor ToString:unicodestring to override. Without the override 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 function ToString : unicodestring;compiler issues a warning :  An inherited method is hidden by "ToString:UnicodeString;" I don't need the TObject.ToString - dont think it actually does anything usefull. Is it OK to ignore, or how does one do, so the compiler stops complaining? ---------------------------------------------------------------------- lucamar · 2019-05-04 00:37 The problem is that ToString is defined as 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 function TObject.ToString: ansistring; virtual;and that is not the same as your ToString, which returns an UnicodeString. In consequence, you can't use override (nothing to override) and your method hides the one in TObject. Instead, try this (untested, may not work): 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 function ToString : unicodestring; overload; You could ignore it, but then any descendant class will be unable to use (or override) the original TObject.ToString. Note that since TObject.ToString is virtual you can override it with a version of your own converting the result of the overload unicode one to for example UTF8. ---------------------------------------------------------------------- ASerge · 2019-05-04 04:02 Quote from: Birger52 on May 04, 2019, 12:04:19 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function ToString : unicodestring; override;compiler complains, that there is no ancestor ToString:unicodestring to override. 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 function ToString: UnicodeString; reintroduce; ---------------------------------------------------------------------- lucamar · 2019-05-04 05:12 Yeah, reintroduce would work too. But note that using reintroduce will replace TObject.ToString by your own. Which now I think about it may well be what you want ---------------------------------------------------------------------- Thaddy · 2019-05-04 06:50 Quote from: lucamar on May 04, 2019, 07:12:31 amYeah, reintroduce would work too. But note that using reintroduce will replace TObject.ToString by your own. Which now I think about it may well be what you want No, it does not replace.... it just changes visibility order. The old one can still be called by using inherited...or cast. ExampleCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$H+}type  TMyAncestor = class  public     function ToString:String; // no specifiers  end;    TMyClass = class(TMyAncestor)  public    function ToString:String;reintroduce;  end;   function TMyAncestor.ToString:string;  begin    result :='a';  end;    function TMyClass.ToString:string;  begin    result := 'b';  end;var  a:TMyClass;  begin  a :=TMyClass.Create;  try    writeln(a.ToString);    writeln(TMyAncestor(a).ToString);  finally    a.free;  end;end.So nothing is replaced, just less visible... The funny thing is that the compiler still issues a warning when instructed to ignore it by reintroduce...... That's a - small - bug. Allen Bauer explains all here: https://stackoverflow.com/questions/741735/what-is-the-meaning-of-the- reintroduce-and-override-directives-in-delphi Via here: https://stackoverflow.com/questions/53806/reintroducing- functions-in-delphi?noredirect=1&lq=1 ---------------------------------------------------------------------- Birger52 · 2019-05-04 22:04 Thx for all the input and heads up. I found somewhere yesterday, a statement that said, that after ver 1.6 (Don't know if it is lazarus itself, or the FPC), most string handling is utf8 by default. I had created a new procedure (ToSaveString) to get past these problems - but decided to try wth the regular string handling, reverted to using standard string variables (and ToString from TObject overridden), and see where it goes, and take it from there. And it is working fine (apart from some troubles actually creating the datafile). Dansih charaters are as well saved as read as the dansih characters Opend the file in Notepad++ - and it reports the coding to be utf8. ---------------------------------------------------------------------- PascalDragon · 2019-05-06 07:12 Quote from: lucamar on May 04, 2019, 02:37:14 amInstead, try this (untested, may not work): 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 function ToString : unicodestring; overload;Overloads based on result type do not work (I think one can declare them, but the compiler won't pick them up correctly).