Why the compiler generates a `”E2018 Record, object or class type required”` on typed types…
Posted by Для просмотра ссылки Войдиили Зарегистрируйся on 2020/05/21
Posted by Для просмотра ссылки Войди
[SHOWTOGROUPS=4,20]
Why the compiler generates a `”E2018 Record, object or class type required”` on typed types…
Posted by jpluimers on 2020/05/21
Why would the compiler generate a "E2018 Record, object or class type required" when I use a ToUpperInvariant (or any TStringsHelper call) on the Text property of a TEdit?
Full failing code is at [WayBack] Для просмотра ссылки Войдиили Зарегистрируйся
Failing line is this:
This fails as well:
Why would the compiler (in this case XE8) throw this error?
Note the workaround is simple:
My suspicion is that the Edit property is of type TCaption which is type string.
Could it be that simple?
To which [ David Heffernan ] responded:
Typed types are indeed different types. They have been there for a long time (to facilitate generating different type information so you can for instance hook up different property editors to TCaption (a typed string) or TColor (a typed integer).
It is explained at [WayBack] Для просмотра ссылки Войдиили Зарегистрируйся. and Для просмотра ссылки Войди или Зарегистрируйся
More on the implications is at [WayBack] pascal – Для просмотра ссылки Войдиили Зарегистрируйся.
–jeroen
[/SHOWTOGROUPS]
Why the compiler generates a `”E2018 Record, object or class type required”` on typed types…
Posted by jpluimers on 2020/05/21
Why would the compiler generate a "E2018 Record, object or class type required" when I use a ToUpperInvariant (or any TStringsHelper call) on the Text property of a TEdit?
Full failing code is at [WayBack] Для просмотра ссылки Войди
Failing line is this:
Код:
Edit1.Text := Edit1.Text.ToUpperInvariant;
// the above line generates this error:
// [dcc32 Error] MainFormUnit.pas(29): E2018 Record, object or class type required
This fails as well:
Код:
Edit1.Text := TStringHelper.ToUpperInvariant(Edit1.Text);
Why would the compiler (in this case XE8) throw this error?
Note the workaround is simple:
Код:
var
lText: string;
begin
lText := Edit1.Text;
Edit1.Text := lText.ToUpperInvariant;
My suspicion is that the Edit property is of type TCaption which is type string.
Could it be that simple?
To which [ David Heffernan ] responded:
Код:
Yup, the issue is TCaption has no helper. Pretty distressing.
Typed types are indeed different types. They have been there for a long time (to facilitate generating different type information so you can for instance hook up different property editors to TCaption (a typed string) or TColor (a typed integer).
It is explained at [WayBack] Для просмотра ссылки Войди
More on the implications is at [WayBack] pascal – Для просмотра ссылки Войди
–jeroen
Код:
unit MainFormUnit;
interface
uses
System.Classes,
Vcl.Controls,
Vcl.Forms,
Vcl.StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
procedure Edit1Change(Sender: TObject);
end;
var
Form1: TForm1;
implementation
uses
System.SysUtils;
{$R *.dfm}
procedure TForm1.Edit1Change(Sender: TObject);
begin
Edit1.Text := Edit1.Text.ToUpperInvariant;
// the above line generates this error:
// [dcc32 Error] MainFormUnit.pas(29): E2018 Record, object or class type required
end;
end.
[/SHOWTOGROUPS]