Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to disable/enable edits dynamically (by editname )

Status
Not open for further replies.

digimortal

Programmer
Oct 12, 2003
28
0
0
TR
I have 13 edits in my form if 5 is entered in the first edit , first 5 of the 12 remaining edits will be enabled, if 10 is entered in the first edit 10 edits will be enabled and 2 will be disabled...
Thanx
(names are edit1,edit2....,edit13)
I think it should look something like this:
for (i=2;i<Edit1->Text;i++)
{
AnsiString ed = &quot;Edit&quot;+i+&quot;->Enabled = True;&quot;;
exec ed //How To Do It
}
 
Using a TList to do it is easiest. But you can also do a loop through all components on the form, checking &quot;ClassNameIs&quot; and then checking (CurrentObjectUnderTest->Name == SomeAnsiStringCalculated)

Inside class definition:
TList *EditBoxList;

Your form's OnCreate event:
EditBoxList = new TList();
EditBoxList->Add(Edit2);
EditBoxList->Add(Edit3);
...
EditBoxList->Add(Edit13);

In your OnChange event handler for the Edit1 control:
int Count = Edit1->Text.ToInt();
if ((Count >= 0) && (Count < 13))
{
for (int x=0; x < Count; x++)
((TEdit*)EditBoxList->Items[x])->Enabled = true;
for (int x=Count; x < 12-Count; x++)
((TEdit*)EditBoxList->Items[x])->Enabled = false;
}

Chris
 
char e1 [] = &quot;Edit1&quot;
char input [20];
TEdit *Edit1;

TEdit *E;

if (!strcmp (input, e1))
E = Edit1;

tomcruz.net


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top