Board index » cppbuilder » Re: Problems with inserting/deleting controls at Runtime

Re: Problems with inserting/deleting controls at Runtime


2003-08-29 01:21:38 AM
cppbuilder110
"Cristian Prevedello" <cristianDOTprevedello@ecoricercheDOTcomNOSPAM>wrote
in message news: XXXX@XXXXX.COM ...
Quote
((TLabel *)Control)->Name=SQLQuery->FieldValues["ID"];
You don't need to set the Name for dynamically-created objects. The Name is
used at design-time, not run-time.
Quote
case 0: ((TLabel *)Control)->Caption=SQLQuery->FieldValues["CAPTION"];
As an alternative, rather than casting the Control to a specific data type
each time, you could use the RTTI system via the TypInfo.hpp header file
instead if you wanted to make the code generic, ie:
#include <TypInfo.hpp>
PTypeInfo pTypeInfo = reinterpret_cast<PTypeInfo>(Control->ClassInfo());
//...
case 0:
{
PPropInfo pPropInfo = GetPropInfo(pTypeInfo, "Caption", TTypeKinds()
<< tkString);
if( pPropInfo ) SetStrProp(Control, pPropInfo,
SQLQuery->FieldValues["CAPTION"]);
break;
}
case 1:
{
pPropInfo pPropInfo = GetPropInfo(pTypeInfo, "DataSource",
TTypeKinds() << tkInteger);
if( pPropInfo ) SetObjectProp(pTypeInfo, pPropInfo, DataSource);
pPropInfo = GetPropInfo(pTypeInfo, "DataField", TTypeKinds() <<
tkString);
if( pPropInfo ) SetStrProp(pTypeInfo, pPropInfo,
SQLQuery->FieldValues["NOMECAMPO"]);
break;
}
case 2:
{
pPropInfo pPropInfo = GetPropInfo(pTypeInfo, "Items", TTypeKinds()
<< tkInteger);
if( pPropInfo )
{
TStringList *StringList =
StringUtils::getPickList(SQLQuery->FieldValues["CAPTION"]);
try
{
try {
SetObjectProp(pTypeInfo, pPropInfo, StringList);
}
__finally {
delete StringList;
}
}
catch(Exception&) {
throw;
}
}
pPropInfo pPropInfo = GetPropInfo(pTypeInfo, "Style", TTypeKinds()
<< tkInteger);
if( pPropInfo ) SetOrdProp(pTypeInfo, pPropInfo,
reinterpret_cast<int>(Stdctrls::csDropDownList));
pPropInfo = GetPropInfo(pTypeInfo, "DataSource", TTypeKinds() <<
tkInteger);
if( pPropInfo ) SetObjectProp(pTypeInfo, pPropInfo, DataSource);
pPropInfo = GetPropInfo(pTypeInfo, "DataField", TTypeKinds() <<
tkString);
if( pPropInfo ) SetStrProp(pTypeInfo, pPropInfo,
SQLQuery->FieldValues["NOMECAMPO"]);
break;
}
//...
This way, you can do your property assignments based on whether given
properties actually exist regardless of knowing the actual component data
types used.
Quote
the removal function is the following:
You are looping in the wrong direction. Every time you free a component,
you will be effecting the loop counter, thus you will be skipping components
and will have to re-loop multiple times in order to free them all. ou
should be looping backwards, not forwards, ie:
for (int i = Parent->ControlCount; i>= 0; --i)
delete Parent->Controls[i];
If you're going to loop forwards, then you should use a while() loop
instead:
while( Parent->ControlCount>0 )
delete Parent->Controls[0];
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/03
 
 

Re:Re: Problems with inserting/deleting controls at Runtime

Remy Lebeau (TeamB) wrote:
Quote
"Cristian Prevedello" <cristianDOTprevedello@ecoricercheDOTcomNOSPAM>wrote
in message news: XXXX@XXXXX.COM ...


>((TLabel *)Control)->Name=SQLQuery->FieldValues["ID"];


You don't need to set the Name for dynamically-created objects. The Name is
used at design-time, not run-time.


>case 0: ((TLabel *)Control)->Caption=SQLQuery->FieldValues["CAPTION"];


As an alternative, rather than casting the Control to a specific data type
each time, you could use the RTTI system via the TypInfo.hpp header file
instead if you wanted to make the code generic, ie:

#include <TypInfo.hpp>

PTypeInfo pTypeInfo = reinterpret_cast<PTypeInfo>(Control->ClassInfo());
//...
case 0:
{
PPropInfo pPropInfo = GetPropInfo(pTypeInfo, "Caption", TTypeKinds()
<< tkString);
if( pPropInfo ) SetStrProp(Control, pPropInfo,
SQLQuery->FieldValues["CAPTION"]);
break;
}
case 1:
{
pPropInfo pPropInfo = GetPropInfo(pTypeInfo, "DataSource",
TTypeKinds() << tkInteger);
if( pPropInfo ) SetObjectProp(pTypeInfo, pPropInfo, DataSource);
pPropInfo = GetPropInfo(pTypeInfo, "DataField", TTypeKinds() <<
tkString);
if( pPropInfo ) SetStrProp(pTypeInfo, pPropInfo,
SQLQuery->FieldValues["NOMECAMPO"]);
break;
}
case 2:
{
pPropInfo pPropInfo = GetPropInfo(pTypeInfo, "Items", TTypeKinds()
<< tkInteger);
if( pPropInfo )
{
TStringList *StringList =
StringUtils::getPickList(SQLQuery->FieldValues["CAPTION"]);
try
{
try {
SetObjectProp(pTypeInfo, pPropInfo, StringList);
}
__finally {
delete StringList;
}
}
catch(Exception&) {
throw;
}
}

pPropInfo pPropInfo = GetPropInfo(pTypeInfo, "Style", TTypeKinds()
<< tkInteger);
if( pPropInfo ) SetOrdProp(pTypeInfo, pPropInfo,
reinterpret_cast<int>(Stdctrls::csDropDownList));
pPropInfo = GetPropInfo(pTypeInfo, "DataSource", TTypeKinds() <<
tkInteger);
if( pPropInfo ) SetObjectProp(pTypeInfo, pPropInfo, DataSource);
pPropInfo = GetPropInfo(pTypeInfo, "DataField", TTypeKinds() <<
tkString);
if( pPropInfo ) SetStrProp(pTypeInfo, pPropInfo,
SQLQuery->FieldValues["NOMECAMPO"]);
break;
}
//...

This way, you can do your property assignments based on whether given
properties actually exist regardless of knowing the actual component data
types used.


>the removal function is the following:


You are looping in the wrong direction. Every time you free a component,
you will be effecting the loop counter, thus you will be skipping components
and will have to re-loop multiple times in order to free them all. ou
should be looping backwards, not forwards, ie:

for (int i = Parent->ControlCount; i>= 0; --i)
delete Parent->Controls[i];

If you're going to loop forwards, then you should use a while() loop
instead:

while( Parent->ControlCount>0 )
delete Parent->Controls[0];
Thank You very much, i solved the problem and the stuff about properties
is very useful.
thanks
cris
 

Re:Re: Problems with inserting/deleting controls at Runtime

Cristian Prevedello wrote:
Quote


Thank You very much, i solved the problem and the stuff about properties
is very useful.

Please, quote in your replies appropriately.
Thanx,
Alex
 

{smallsort}