Jump to content
Ian Branch

Help with Refactoring.. - Resolved..

Recommended Posts

Hi Team,

I thought I would try refactoring some code that is used 5 times in the Unit.  Seemed a good idea.

Win 11, D11.2, EurekaLog.

I have the following as a private function for the form..

'There is no Corporate Email Address recorded in the Company data!'

In the calling code I have..

  //
  var MailSender := TELMailSMTPClientSender.Create;
  //
  try
    //
    MailSender.Options := CurrentEurekaLogOptions;
    //
    MailSender := SetSvcOrCorpSender(MailSender);
    //

And the refactored code is..

function TJobTicketsForm.SetSvcOrCorpSender(var MailSender: TELMailSMTPBaseSender): TELMailSMTPBaseSender;
begin
  //
  // Set Sender
  while True do
  begin
    //
    case tdSvcorCorpSend.Execute of
      100:
        begin
          if Trim(ACD.ServiceEmail) = '' then
          begin
            Showmessage('There is no Service Email Address recorded in the Company data!');
            Continue;
          end;
          //
          MailSender.Options.SendSMTPClientFrom := Trim(ACD.ServiceEmail);
          if Trim(ACD.ServiceEmailName) = '' then
            MailSender.Options.OverrideUserFullName := StrTokenAt(Trim(ACD.ServiceEmail), '@', 1)
          else
            MailSender.Options.OverrideUserFullName := Trim(ACD.ServiceEmailName);
          Break;
        end;
      200:
        begin
          if Trim(ACD.CorporateEmail) = '' then
          begin
            Showmessage('There is no Corporate Email Address recorded in the Company data!');
            Continue;
          end;
          //
          MailSender.Options.SendSMTPClientFrom := Trim(ACD.CorporateEmail);
          break;
        end;
    end;
    //
  end;
  //;
  Result := MailSender;
  //
end;

Trouble is that delphi tells me that the types and formal var parameters must be identical.

Ummm.    Arent they?

 

Resolved.  IT seems I missed a step during my In-Line variables conversion..

    //
    var MailSender: TELMailSMTPBaseSender;             //  <<<<<<<<<<<<<<<<<<<<<<<
    //
    MailSender := TELMailSMTPClientSender.Create;
    //

 

Regards & TIA,

Ian

Edited by Ian Branch

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×