Solved

manipulating components

Posted on 2010-08-26
12
444 Views
Last Modified: 2013-11-23
Hi
I am managing old Delphi 7 code
I have a form with many TEdit
I use the following code to clear values on my form
My problem is I cannot figure out how to stop certain values from clearing
Example
Edit1.text =’Main Information’
Edit2.text =’General Information’
Edit3.text =’General Information’
Edit4.text =’General Information’

When I use the my following procedure
I need to stop Edit1.text =’Main Information’ from clearing

procedure TForm1.Clear_values
var
j : Integer;
begin
for j := 0 to ComponentCount-1 do
begin
for j := 0 to ComponentCount-1 do
begin

if TEdit(Components[j]).Parent.Name = 'edit2' then showmessage('TEST');

   if (Components[j] is TEdit) then
     (Components[j] as TEdit).Text := '';
   if (Components[j] is Tcheckbox) then
     (Components[j] as Tcheckbox).checked := false;
   if (Components[j] is TRadioButton) then
     (Components[j] as TRadioButton).checked := false;
    if (Components[j] is TComboBox) then
     (Components[j] as TComboBox).Itemindex := -1;
    if (Components[j] is Tmemo) then
     (Components[j] as Tmemo).text := '';
end;

Thank you
0
Comment
Question by:SSSIAN
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 13

Accepted Solution

by:
aflarin earned 250 total points
ID: 33530002
procedure TForm1.Clear_values
var
  j : Integer;
begin
  for j := 0 to ComponentCount-1 do
  begin
    for j := 0 to ComponentCount-1 do
    begin

     if (Components[j] is TEdit) and (Components[i] <> Edit1) then
       (Components[j] as TEdit).Text := '';
     if (Components[j] is Tcheckbox) then
       (Components[j] as Tcheckbox).checked := false;
     if (Components[j] is TRadioButton) then
       (Components[j] as TRadioButton).checked := false;
     if (Components[j] is TComboBox) then
       (Components[j] as TComboBox).Itemindex := -1;
     if (Components[j] is Tmemo) then
       (Components[j] as Tmemo).text := '';
end;
0
 
LVL 13

Expert Comment

by:aflarin
ID: 33530018
or

procedure TForm1.Clear_values
var
  j : Integer;
begin
  for j := 0 to ComponentCount-1 do
  begin
    for j := 0 to ComponentCount-1 do
    begin

     if (Components[j] is TEdit) then
       if Components[i] <> Edit1 then
         (Components[j] as TEdit).Text := ''
       else
          Edit1.Text:= ’Main Information’;
     if (Components[j] is Tcheckbox) then
       (Components[j] as Tcheckbox).checked := false;
     if (Components[j] is TRadioButton) then
       (Components[j] as TRadioButton).checked := false;
     if (Components[j] is TComboBox) then
       (Components[j] as TComboBox).Itemindex := -1;
     if (Components[j] is Tmemo) then
       (Components[j] as Tmemo).text := '';
end;
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 33530041
one thing that strikes me as very odd ...
the dubble loop with the same j variable ???

why twice ?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SSSIAN
ID: 33530089
SORRY ALL

this is typing error
i was in in rush

the code should be someting
 am managing old Delphi 7 code
I have a form with many TEdit
I use the following code to clear values on my form
My problem is I cannot figure out how to stop certain values from clearing
Example
Edit1.text =’Main Information’
Edit2.text =’General Information’
Edit3.text =’General Information’
Edit4.text =’General Information’
When I use the my following procedure
I need to stop Edit1.text =’Main Information’ from clearing

procedure TForm1.Clear_values
var
j : Integer;
begin
for j := 0 to ComponentCount-1 do
// I need some if edit1.text then do not clear
   if (Components[j] is TEdit) then
     (Components[j] as TEdit).Text := '';
    if (Components[j] is Tmemo) then
     (Components[j] as Tmemo).text := '';
end;





0
 

Author Closing Comment

by:SSSIAN
ID: 33530093
Thank you for very quick response from all
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 33530942
As a passing comment, please tell me that you are not actually using components on your form with names like Edit1, Edit2, and Edit3 but are, instead, providing meaningfull names for each of them. ;-)
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 33531153
that's not all that bad
as long as they can remember what Edit34 is for on Form234 out of 654 forms

but don't ever ask me to come and personally help to debug
because i've had that nightmare in once place, and they are never ever seeing me back again !


0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 33531251
Geert,
I didn't know you ever worked in Memphis, TN, but you must have because I ran into that sort of nameing convention in several places there . . . none of which would I return to and all of which I raised my rates after seeing the code and before finalizing the contracts.  (I thought it was only a couple of spots in the code each time but figured out later that it was pervasive.)
0
 

Author Comment

by:SSSIAN
ID: 33531272
Hi 9080 driver
This was just example, I try and use meaningfull names for
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 33531327
SSSIAN,
Thank you . . . I will sleep easier tonight just knowing that there are more people out there with good sense. ;-)
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 33531837
>>8080_Diver
grrr, i don't do that.
I said I had a problem with debugging that.

After the umpteenth question
What was Edit34 for again ?
I forgot after you told me what Edit23, Edit26, Combobox45, Combobox45_2 and Edit45beta was for
I think I mixed it up with Edit43 ...
Was that for the first name or the last name of the vendor ?
What was Combobox45_2 again ?

Ow, can I ask a silly question ?
I don't completely follow why you use underscore 2, or underscore 3 in your code,
and then later you seem to use beta and gamma.
Not that it's any of my business but that's rather frustrating ...
It's a lot simpler just using the names given by Delphi ?

Ah no, we just had a new recruit and we told him to come up with a better naming convention.
What do you think about it ? I think it's rather good ...

Me: Ow god, what have I gotten myself into now ... Where is the beer ?







0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 33532580
Geert,
Where is the beer ?

I actually billed a client (one that had the rate raised per above ;-) for the after work brews one time . . . it was covered under the consultant will be reimbursed for all misc expenses clause. ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question