?
Solved

manipulating components

Posted on 2010-08-26
12
Medium Priority
?
446 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 1000 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 38

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
Technology Partners: 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 38

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 38

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

719 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