Based on the comments urging me towards using an inline
function, and given my specific requirements, I have ended up doing the following.
- This is my
struct
object whose definition can't be changed:
typedef struct tagPublicTalkInfo
{
CString strAwayCong1;
CString strAwayCong2;
CString strAwayBrother1;
CString strAwayBrother2;
CString strAwayTalkNumber1; // AJT v20.1.9
CString strAwayTalkNumber2; // AJT v20.1.9
CString strChairman;
CString strCong;
CString strHosp;
CString strReader;
CString strBrother;
CString strTheme;
CString strWTConductor; // AJT v10.7.2
CString strInterpreter; // AJT v16.2.1
CString strMisc; // AJT v16.2.1
CString strWatchtowerStudyTheme; // AJT v17.0.5
CString strServiceTalkTheme; // AJT v17.0.7
CString strBibleVersesReader; // AJT v20.0.1
CString strVideoHost; // AJT v20.1.4
CString strVideoCohost; // AJT v20.1.4
CString strOpeningPrayer; // AJT v20.1.6
CString strClosingPrayer; // AJT v20.1.6
int iSongStart; // AJT v20.0.1
int iSongMiddle; // AJT v20.0.1
int iSongEnd; // AJT v20.0.1
int iThemeNumber; // AJT v20.1.6
} S_TALK_INFO;
- I added this new
inline
method:
void SetValue(CString& rStrCurrentValue, CString strNewValue)
{
if (strNewValue != _T("") && strNewValue != _T(" "))
rStrCurrentValue = strNewValue;
}
- Finally, I adjusted my
SetWeekendMeetingInfo
method, so that it now looks like:
void CWeekendMeetingDlg::SetWeekendMeetingInfo(S_TALK_INFO &rsTalkInfo)
{
//m_sWMInfo = rsTalkInfo;
SetValue(m_sWMInfo.strAwayCong1, rsTalkInfo.strAwayCong1);
SetValue(m_sWMInfo.strAwayCong2, rsTalkInfo.strAwayCong2);
SetValue(m_sWMInfo.strAwayBrother1, rsTalkInfo.strAwayBrother1);
SetValue(m_sWMInfo.strAwayBrother2, rsTalkInfo.strAwayBrother2);
SetValue(m_sWMInfo.strAwayTalkNumber1, rsTalkInfo.strAwayTalkNumber1);
SetValue(m_sWMInfo.strAwayTalkNumber2, rsTalkInfo.strAwayTalkNumber2);
SetValue(m_sWMInfo.strChairman, rsTalkInfo.strChairman);
SetValue(m_sWMInfo.strCong, rsTalkInfo.strCong);
SetValue(m_sWMInfo.strHosp, rsTalkInfo.strHosp);
SetValue(m_sWMInfo.strReader, rsTalkInfo.strReader);
SetValue(m_sWMInfo.strBrother, rsTalkInfo.strBrother);
SetValue(m_sWMInfo.strTheme, rsTalkInfo.strTheme);
SetValue(m_sWMInfo.strWTConductor, rsTalkInfo.strWTConductor);
SetValue(m_sWMInfo.strInterpreter, rsTalkInfo.strInterpreter);
SetValue(m_sWMInfo.strMisc, rsTalkInfo.strMisc);
SetValue(m_sWMInfo.strWatchtowerStudyTheme, rsTalkInfo.strWatchtowerStudyTheme);
SetValue(m_sWMInfo.strServiceTalkTheme, rsTalkInfo.strServiceTalkTheme);
SetValue(m_sWMInfo.strBibleVersesReader, rsTalkInfo.strBibleVersesReader);
SetValue(m_sWMInfo.strVideoHost, rsTalkInfo.strVideoHost);
SetValue(m_sWMInfo.strVideoCohost, rsTalkInfo.strVideoCohost);
SetValue(m_sWMInfo.strOpeningPrayer, rsTalkInfo.strOpeningPrayer);
SetValue(m_sWMInfo.strClosingPrayer, rsTalkInfo.strClosingPrayer);
m_sWMInfo.iSongStart = rsTalkInfo.iSongStart;
m_sWMInfo.iSongMiddle = rsTalkInfo.iSongMiddle;
m_sWMInfo.iSongEnd = rsTalkInfo.iSongEnd;
m_sWMInfo.iThemeNumber = rsTalkInfo.iThemeNumber;
}
It appears to work function correctly. As I say, I can't change the definition of my struct
object but if you think this approach can be improved then please inform me.