Solved

manipulating components

Posted on 2010-08-26
12
437 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
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 13

Accepted Solution

by:
aflarin earned 250 total points
Comment Utility
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
Comment Utility
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 36

Expert Comment

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

why twice ?
0
 

Author Comment

by:SSSIAN
Comment Utility
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
Comment Utility
Thank you for very quick response from all
0
 
LVL 22

Expert Comment

by:8080_Diver
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
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
Comment Utility
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
Comment Utility
Hi 9080 driver
This was just example, I try and use meaningfull names for
0
 
LVL 22

Expert Comment

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

Expert Comment

by:Geert Gruwez
Comment Utility
>>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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now