 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Aug 28, 2003 5:21 pm Post subject: Re: Problems with inserting/deleting controls at Runtime |
|
|
"Cristian Prevedello" <cristianDOTprevedello@ecoricercheDOTcomNOSPAM> wrote
in message news:3f4dc5c8 (AT) newsgroups (DOT) borland.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
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 ([url]http://www.grisoft.com)[/url].
Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/03
|
|
| Back to top |
|
 |
Cristian Prevedello Guest
|
Posted: Fri Aug 29, 2003 5:10 pm Post subject: Re: Problems with inserting/deleting controls at Runtime |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | "Cristian Prevedello" <cristianDOTprevedello@ecoricercheDOTcomNOSPAM> wrote
in message news:3f4dc5c8 (AT) newsgroups (DOT) borland.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_castClassInfo());
//...
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
--
Ecoricerche sicurezza srl
|
|
| Back to top |
|
 |
Alex Bakaev [TeamB] Guest
|
Posted: Fri Aug 29, 2003 5:32 pm Post subject: 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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|