Mega Search
23.2 Million


Sign Up

Make a donation  
Question on anon methods and closures  
News Group: embarcadero.public.delphi.oodesign

Hey!
I have a question to generics / closures. I think it is clearly a lack of understanding on my side, hope that is the right

I have Delphi (XE5, Win32+Win64) client that does web service (http) calls to an application server. Due to very specific conditions on my clients network, some calls fail on the first try. If I wait a few seconds and do the same call again, everything works fine. So my solution was to make an interface class that encapsulates all the calls and contains a very simple re-do logic. All calls look like this

// business logic code module
procedure BusinessLogicClass.DoSomething;
begin
// get data from AppServer 
Data:=ApplicationserverIntf.GetSomeData(CustomerID,SessionID,LogInfo);

// do some user interaction
ApplicationserverIntf.StoreSomeData(CustomerName,CustomerAssets);
end;

And the implementation on my client-side interface unit looks like that.

// client interface module
function TAppServerMiKEIntf.GetSomeData(const CustomerID,SessionID : integer;const LogInfo : string) : TData;
begin
try
 Result:=AppServer.GetSomeData(CustomerID,SessionID,LogInfo);
except on e: Exception do
       begin
       // Timeout ?
       if Self.ExceptionIsTimeout(e.Message) then
          begin
          LogManager.LogMsg(m_sMsgErrorTimeout,[sMethodname]);
          Sleep(ciTIMEOUT_RETRYSLEEP);
          try
           Result:=AppServer.GetSomeData(CustomerID,SessionID,LogInfo);
           MyApp.LogManager.LogMsg(m_sMsgRetrySuccess);
          except on e: Exception do
                 begin
                 LogManager.LogMsg(m_sMsgRetryFailed,[sMethodname,e.Message]);
                 raise Exception.Create(e.Message);
                 end;
          end;
          end
       else
        // casual error
        begin
        LogManager.LogMsg(m_sMsgErrorDefault,[sMethodname,e.Message]);
        raise Exception.Create(e.Message);
        end;
       end;
end;
end;

There are about 300 such calls. So my Question is, can I simplify that using generics? Since all calls to the application have different parameters, I have no idea on how to generalize the re-try logic.

Thank you in advance.

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 28-Apr-2014, at 6:55 AM EST
From: Roman Ziehengraser