Home General

ppLabel.OnGetText

Delphi 10.4 & 11 & RB 22.3

The error code "Can not assign to a read only property " occurs in scenario 1. but not 2. The code is essentially the same, so my question is why does the error occur in scenerio1.

Scenerio 1.
procedure TformPtMeds.ppLabel16GetText(Sender: TObject; var Text: string);
begin
with FDTablePatients do
begin
if FieldByName('Address2').AsString = '' then
begin
Text := FieldByName('City').AsString + ', ' + FieldByName('State').AsString + ' ' + FieldByName('Zip').AsString;
ppLabel17.Text := '';
end;
end;
end;

Scenerio 2.
procedure TformPtMeds.ppLabel16GetText(Sender: TObject; var Text: string);
begin
if FDTablePatients.FieldByName('Address2').AsString = '' then
begin
Text := FDTablePatients.FieldByName('City').AsString + ', ' + FDTablePatients.FieldByName('State').AsString + ' ' +
FDTablePatients.FieldByName('Zip').AsString;
ppLabel17.Text := ''; end;
end;
end;

Comments

  • Addendum to the above question. The DB backend that I am using is Advantage. The referenced compiler error was not present when compiled with Delphi 8. With the advent of Delphi 10 and Windows 10 the Advantage DB connector no long worked and I had to switch the FireDac connector with the Advantage DB. This is where the compiler error came into play. The issue also exists with Delphi 11.3 and Windows 11.
  • Hi John,

    This is why we avoid every using "with" statements :). At best they are confusing, at worst... dangerous.

    The issue is that TFDTable contains a "Text" property which is read-only. When you try to assign the Text parameter in your code, the compiler thinks you are trying to assign the FDTablePatients.Text property.
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Thanks so much Nico. It has been a long time since we had a discussion. I hope all is well.
Sign In or Register to comment.