Recent

Author Topic: Set as parameter for procedure?  (Read 3910 times)

Elmug

  • Hero Member
  • *****
  • Posts: 849
Set as parameter for procedure?
« on: July 29, 2011, 02:20:53 am »
Good forum people,

If I have, say 4 T.Edit boxes, can I create a set of their .text values, and make a procedure, for example, to change the text value to be all lower case?

Meaning that I could use the procedure to do all 4 updates at the same time, and also that if I create another TEdit box that neads the same treatment, I could just add that component to the set?

If this is possible, can a brief, snipet of code skeleton by afforded as a guiding example?

Thanks!

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Set as parameter for procedure?
« Reply #1 on: July 29, 2011, 03:31:23 am »
Code: [Select]
for i := 0 to ComponentCount - 1 do
    if Components[i] is TEdit then
      (Components[i] as TEdit).Text :=  LowerCase((Components[i] as TEdit).Text); 
« Last Edit: July 29, 2011, 03:36:30 am by typo »

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Set as parameter for procedure?
« Reply #2 on: July 29, 2011, 06:30:51 am »
Code: [Select]
for i := 0 to ComponentCount - 1 do
    if Components[i] is TEdit then
      (Components[i] as TEdit).Text :=  LowerCase((Components[i] as TEdit).Text); 

Thanks Typo.

I am glad that this is possible as you show.

I do have these questions, though:

1. Is this handling a set or an array? I can't tell right now. Can you show the statement for the Components?

2. I suppose that the PROCEDURE is pretty much a standard one, nothing special.

3. I am not familiar with the word 'as', being familiar only with the old unextended Pascal. I looked for it in the documentation of all identifiers in this page:
http://www.freepascal.org/docs-html/rtl/index-8.html
and it is not listed.

4. Google search did not resolve me since 'as' is such a common word. So if you could provide a link to the use of the word 'as', please.

Thanks!

Zoran

  • Hero Member
  • *****
  • Posts: 1988
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Set as parameter for procedure?
« Reply #3 on: July 29, 2011, 09:07:01 am »
Delphi documentation about class operators ("is" and "as"): http://docwiki.embarcadero.com/RADStudio/en/Class_References#Class_Operators
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Set as parameter for procedure?
« Reply #4 on: July 29, 2011, 09:45:52 am »
Thank you, Zoran. I will study this topic.

 

TinyPortal © 2005-2018