Board index » delphi » HELP! Optimization

HELP! Optimization

Hi,

I wonder if anybody could tell me how to make the following piece of
code shorter:

    SetupString.Strings[0] := Child.Edit1.Text;
    SetupString.Strings[1] := Child.Edit2.Text;
    SetupString.Strings[2] := Child.Edit3.Text;
    SetupString.Strings[3] := Child.Edit4.Text;
    SetupString.Strings[4] := Child.Edit5.Text;
    SetupString.Strings[5] := Child.Edit6.Text;
    SetupString.Strings[6] := Child.Edit7.Text;
    SetupString.Strings[7] := Child.Edit8.Text;

Can I use a for-loop? The problem are the Edit_, of course!

If you want to help me, please email me... Thanks!

bye...
Alexander

      [Replys Cc as email please!]

---
Alexander Lucke,
Email: <a...@next2.psychologie.hu-berlin.de>
WWW: <http://141.20.111.4/al/>

 

Re:HELP! Optimization


On Sun, 01 Sep 1996 17:14:54 GMT, a...@next2.psychologie.hu-berlin.de
(Alexander Lucke) you smacked the keyboard repeatedly to write:

Quote
>Hi,

>I wonder if anybody could tell me how to make the following piece of
>code shorter:

>    SetupString.Strings[0] := Child.Edit1.Text;
>    SetupString.Strings[1] := Child.Edit2.Text;
>    SetupString.Strings[2] := Child.Edit3.Text;
>    SetupString.Strings[3] := Child.Edit4.Text;
>    SetupString.Strings[4] := Child.Edit5.Text;
>    SetupString.Strings[5] := Child.Edit6.Text;
>    SetupString.Strings[6] := Child.Edit7.Text;
>    SetupString.Strings[7] := Child.Edit8.Text;

x := 1;
for i:= 0 to Child.ComponentCount -1 do
        begin
                if Child.Components[i] is TEdit then
                   begin
                          SetupString.Strings[x] := (Child.Components[i] as
TEdit).Text;
                          X := X + 1;
                   end;
        end;

Brien King
bk...@primenet.com

Re:HELP! Optimization


Quote
In article <322a9f19.2068734@news> bk...@primenet.com (Brien King) writes:
>>I wonder if anybody could tell me how to make the following piece of
>>code shorter:

>>    SetupString.Strings[0] := Child.Edit1.Text;
>>    SetupString.Strings[1] := Child.Edit2.Text;
>>    SetupString.Strings[2] := Child.Edit3.Text;
>>    SetupString.Strings[3] := Child.Edit4.Text;
>>    SetupString.Strings[4] := Child.Edit5.Text;
>>    SetupString.Strings[5] := Child.Edit6.Text;
>>    SetupString.Strings[6] := Child.Edit7.Text;
>>    SetupString.Strings[7] := Child.Edit8.Text;

>x := 1;
>for i:= 0 to Child.ComponentCount -1 do
>        begin
>                if Child.Components[i] is TEdit then
>                   begin
>                          SetupString.Strings[x] := (Child.Components[i] as
>TEdit).Text;
>                          X := X + 1;
>                   end;
>        end;

Absolutely true as noted ... but you know, that does not seem like a terribly
long piece of code to begin with.  Cut and Paste are your friends!  :-)

Seriously, though, Brien's code does assume that Edit1 thru Edit6 were added
to the form's Components list in sequence and might be adversely affected if
you removed and replaced any one of the edits.  Other than this, it is a very
useful example of how such code can be "tightened up."

/mr/

Re:HELP! Optimization


On 2 Sep 1996 10:48:03 -0700, i...@sundialservices.com (Sundial Services) wrote:

Quote
>In article <322a9f19.2068734@news> bk...@primenet.com (Brien King) writes:

>>>I wonder if anybody could tell me how to make the following piece of
>>>code shorter:

>>>    SetupString.Strings[0] := Child.Edit1.Text;
>>>    SetupString.Strings[1] := Child.Edit2.Text;
[snip]

>Seriously, though, Brien's code does assume that Edit1 thru Edit6 were added
>to the form's Components list in sequence and might be adversely affected if
>you removed and replaced any one of the edits.  Other than this, it is a very
>useful example of how such code can be "tightened up."

>/mr/

try with this code:

for I := 0 to MaxEdit do begin
   N := 'Edit' + IntToStr(I)
   for J := 0 to Child.ComponentCount - 1 do
      if (Child.Components[J] is TEdit) and (Child.Components[J].Name = 'N')
then begin
         SetUpString.Strings[I] := (Child.Components[J] as TEdit).Text;
         break;
      end;
end;

Bye |/
Bye |\ino

Other Threads