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;
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
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.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com