Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

manipulating components

Posted on 2010-08-26
12
Medium Priority
?
447 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

824 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