You are correct, Leo.
I do not like doing it this way but we pass this as a parms to the TList
Sort method. I wish the TList Sort would pass a TList pointer like
TStringList Sort does. I could then Create a descendant of TList and stick
the sort parmaters inside of it and be able to access it from the TList Sort
Method.
The assembler instructions in TSortGrid::ColumnIsDuplicate are loading a
different address for the SortGridConfig variable then the one that the
TSortGrid::TSortGrid uses when it creates and instance of TSortGridConfig
and assigns it to SortGridConfig.
This is only happening when we have "Use runtime packages" checked in the
.exe file that uses the code shown below ( which is in a package type
project ).
Here is the code:
################# .h header ###########################
//------------------------------------------------------------------------------
class TSortGridConfig : public TObject
{
public:
__fastcall TSortGridConfig();
__fastcall ~TSortGridConfig();
long KeyDepth;
TObjectList* SortParametersList;
TList* OriginalPositions;
TObjectList* SortKeyOLs;
};
################ .cpp body ####################
TSortGridConfig* SortGridConfig = 0;
##########
__fastcall TSortGridConfig::TSortGridConfig()
{
KeyDepth = 0;
OriginalPositions = new TList;
SortKeyOLs = new TObjectList;
SortParametersList = new TObjectList;
}
//------------------------------------------------------------------------------
__fastcall TSortGridConfig::~TSortGridConfig()
{
delete OriginalPositions;
delete SortKeyOLs;
delete SortParametersList;
}
###########
//------------------------------------------------------------------------------
__fastcall TSortGrid::TSortGrid( TStringGrid* _StringGrid )
{
SortGridConfig = new TSortGridConfig;
FStringGrid = _StringGrid;
}
//------------------------------------------------------------------------------
__fastcall TSortGrid::~TSortGrid()
{
delete SortGridConfig;
SortGridConfig = 0;
}
//------------------------------------------------------------------------------
bool __fastcall TSortGrid::ColumnIsDuplicate( long _Col, TGridSortType
_GridSortType )
{
bool Result = false;
for( int ix = 0; ix < SortGridConfig->SortParametersList->Count; ix++ )
{
TSortParameters* SortParameters =
(TSortParameters*)SortGridConfig->SortParametersList->Items[ix];
if( SortParameters->Column == _Col )
{
Result = true;
// It is ok to use the same column if keys from the grid are
String and Object
if( ( _GridSortType == stTInteger || _GridSortType ==
stTString ) &&
( SortParameters->GridSortType == stString ||
SortParameters->GridSortType == stNumeric || SortParameters->GridSortType ==
stDate )
)
{
Result = false;
}
}
}
return Result;
}
//------------------------------------------------------------------------------
void __fastcall TSortGrid::AddCol( long _Col, TGridSortType
_GridSortType, TSortDirection _SortDirection, String _DateMask )
{
// Save sort parameters
if( ColumnIsDuplicate( _Col, _GridSortType ) )
{
return;
}
if ( _Col >= FStringGrid->FixedCols && _Col < FStringGrid->ColCount )
{
TSortParameters* SortParameters = new TSortParameters;
SortParameters->Column = _Col ;
SortParameters->GridSortType = _GridSortType ;
SortParameters->SortDirection = _SortDirection ;
SortGridConfig->SortParametersList->Add( SortParameters );
BuildKeys( _Col, _GridSortType, _DateMask );
}
}
Post by Leo SiefertPost by Larry GriffithsTSomeClass::TSomeClass( TStringGrid* _StringGrid )
{
GlobalVariable = new TSomeClass;
}
Huh? So what does the default constructor for TSomeClass do? I hope it
doesn't also assign GlobalVariable to another new instance...
At any rate, it appears clear that TSomeClass is not a singleton, yet
it assigns a default constructed new TSomeClass to GlobalVariable
every time a TSomeClass is constructed from a TStringGrid* (including
any time a TStringGrid* is assigned to a TSomeClass* variable.
Pretty easy to see how the value of GlobalVariable can be changed by
seemingly innocent looking code. Almost impossible to find with a
grep.
- Leo