ThWatcher
12 years agoOccasional Contributor
Proper Way to Copy String?
Hello and thank for any help anyone can give me.
A couple of weeks back, I added code to my main test routines to save the data file generated by the program under test. It went like this:
-----------------
DM_dbPathFileName = Aliases.DataModelServer.HwndSource_MainWindow.MainWindow.DockPanel.Grid.mDMGroup.DockPanel.Grid.mMDMControlsPanel.WPFObject("StackPanel", "", 1).WPFObject("Border", "", 1).WPFObject("mDBFileLabel").get_Text();
---------------
The value being copied was of the format (C:\Documents and Settings\username\My Documents\DataModel Projects\20130319-110144.dm')
without the parenthisis.
This worked fine except that at the end of the test run, when it came time to copy the data file to a new location, the variable 'DM_dbPathFileName' was blank.
I finally figured out that what was actually stored in 'DM_dbPathFileName' was a reference to the text in the window and not the actual text. When the window went away, so did the text(path/filename) that I needed.
I couldn't leave the window open because the window has to be closed to close the file. Can't copy the file till it is closed.
I fixed it by creating a routine to force the copying of the actual text rather than a reference to the text.
----------------
function GetActualText( Reference )
{
ref = "'" + Reference + "'";
return aqString.SubString( ref, 1, GetLength( ref ) - 2 );
}
--------------
My question is: Is there a proper, or at least better, way to do this?
Again, thanks for any help anyone can give.
ThWatcher
A couple of weeks back, I added code to my main test routines to save the data file generated by the program under test. It went like this:
-----------------
DM_dbPathFileName = Aliases.DataModelServer.HwndSource_MainWindow.MainWindow.DockPanel.Grid.mDMGroup.DockPanel.Grid.mMDMControlsPanel.WPFObject("StackPanel", "", 1).WPFObject("Border", "", 1).WPFObject("mDBFileLabel").get_Text();
---------------
The value being copied was of the format (C:\Documents and Settings\username\My Documents\DataModel Projects\20130319-110144.dm')
without the parenthisis.
This worked fine except that at the end of the test run, when it came time to copy the data file to a new location, the variable 'DM_dbPathFileName' was blank.
I finally figured out that what was actually stored in 'DM_dbPathFileName' was a reference to the text in the window and not the actual text. When the window went away, so did the text(path/filename) that I needed.
I couldn't leave the window open because the window has to be closed to close the file. Can't copy the file till it is closed.
I fixed it by creating a routine to force the copying of the actual text rather than a reference to the text.
----------------
function GetActualText( Reference )
{
ref = "'" + Reference + "'";
return aqString.SubString( ref, 1, GetLength( ref ) - 2 );
}
--------------
My question is: Is there a proper, or at least better, way to do this?
Again, thanks for any help anyone can give.
ThWatcher