I found some code like
procedure UpdateComp(Sender: TObject)
begin
if Sender = edtA then
begin
... //to something
end;
if Sender = edtB then
begin
... //to something
end;
if Sender = edtC then
begin
... //to something
end;
...
end;
The if/then in the code is for more than 50 statement Each time is the sender match with a component on the form ones. Is it then logic to change the code like:
procedure UpdateComp(Sender: TObject)
begin
if Sender = edtA then
begin
... //to something
end
else if Sender = edtB then
begin
... //to something
end
else if Sender = edtC then
begin
... //to something
end;
...
end;
Or I am not correct to change this way?
A piece of the code I find on the way:
procedure TContactController.UpdateComponent(Sender: TObject);
var
I: Integer;
begin
UpdateComponentActive := True;
If Sender = pnlBasicInformation
then begin
pnlBasicInformation.Caption := UpperCase(Trim(Format('%s %s', [CurrentContact.Name, CurrentContact.FirstName])));
If CurrentContact.HomeAddress.PostalCode.City.CityDescription[ApplicationManager.CurrentLanguageId] <> ''
then pnlBasicInformation.Caption := Format('%s - %s',
[pnlBasicInformation.Caption,
UpperCase(CurrentContact.HomeAddress.PostalCode.City.CityDescription[ApplicationManager.CurrentLanguageId])]);
pnlBasicInformation.Caption := StringReplace(pnlBasicInformation.Caption, '&', '&&', [rfReplaceAll]);
end;
If Sender = gbtnLock
then begin
If CurrentContact.Locked
then gbtnLock.ImageIndex := 7
else gbtnLock.ImageIndex := 19;
end;
If Sender = edtInternalReference
then edtInternalReference.Text := CurrentContact.InternalReference;
If Sender = edtExternalReference
then edtExternalReference.Text := CurrentContact.ExternalReference;
If Sender = edtFirstName
then edtFirstName.Text := CurrentContact.FirstName;
If Sender = edtName
then edtName.Text := CurrentContact.Name;
If Sender = edtSubName
then edtSubName.Text := CurrentContact.SubName;
If Sender = cbContactFunction
then begin
cbContactFunction.ItemIndex := -1;
For I := 0 to cbContactFunction.Items.Count-1 do
begin
If TContactFunction(cbContactFunction.Items.Objects[I]).Id = CurrentContact.ContactFunctionId
then begin
cbContactFunction.ItemIndex := I;
break;
end;
end;
end;
If Sender = cbLanguage
then begin
cbLanguage.ItemIndex := -1;
For I := 0 to cbLanguage.Items.Count-1 do
begin
If TLanguage(cbLanguage.Items.Objects[I]).Id = CurrentContact.LanguageId
then begin
cbLanguage.ItemIndex := I;
break;
end;
end;
end;
If Sender = cbSalutation
then begin
cbSalutation.ItemIndex := -1;
For I := 0 to cbSalutation.Items.Count-1 do
begin
If TSalutation(cbSalutation.Items.Objects[I]).Id = CurrentContact.SalutationId
then begin
cbSalutation.ItemIndex := I;
break;
end;
end;
end;
If Sender = edtCallingCodeMobilePhone
then edtCallingCodeMobilePhone.Text := CurrentContact.CallingCodeMobilePhone;
If Sender = edtMobilePhone
then begin
edtMobilePhone.Text := CurrentContact.MobilePhone;
edtMobilePhone.OnKeyPress := OnPhoneNumberKeyPress;
end;
If Sender = gbtnMobilePhone
then gbtnMobilePhone.Enabled := Trim(CurrentContact.MobilePhone) <> '';
If Sender = gbtnMobilePhoneSms
then gbtnMobilePhoneSms.Enabled := Trim(CurrentContact.MobilePhone) <> '';
If Sender = edtBirthDate
then edtBirthDate.Text := Format('dd/mm/yyyy', [CurrentContact.BirthDate]);
If Sender = rbGenderM
then rbGenderM.Checked := (CurrentContact.Gender = 0);
If Sender = rbGenderV
then rbGenderV.Checked := (CurrentContact.Gender = 1);
If Sender = edtIdentityCardNumber
then edtIdentityCardNumber.Text := CurrentContact.IdentityCardNumber;
If Sender = edtNationalNumber
then edtNationalNumber.Text := CurrentContact.NationalNumber;
If Sender = imgProfilePhoto
then imgProfilePhoto.Picture.Assign(ProfilePhoto.Picture.Graphic);
If Sender = gbtnRemovePhoto
then gbtnRemovePhoto.Enabled := PhotoManager.PhotoExists(pmContact, CurrentContact.Id);
If Sender = edtRemarks
then edtRemarks.Text := CurrentContact.Remarks;
If Sender = edtInfo
then edtInfo.Text := CurrentContact.Info;
If Sender = edtRowVersion
then edtRowVersion.Text := Format('dd/mm/yyyy', [CurrentContact.RowVersion]);
UpdateComponentActive := False;
end;
therefore I wanted to change the code with if / else as first changes