Results 1 to 10 of 10

Thread: Some doubts in pascal language..

  1. #1

    Some doubts in pascal language..

    Im advancing in pascal but i don't know some things like...

    - how use "for in" loops

    - a const of arrays

    - is there a way to do something like ->
    [pascal]var uuu : array [0..1] of integer;
    begin
    uuu := ((1),(2));[/pascal]
    From brazil (:

    Pascal pownz!

  2. #2

    Re: Some doubts in pascal language..

    Quote Originally Posted by arthurprs
    Im advancing in pascal but i don't know some things like...

    - how use "for in" loops

    - a const of arrays

    - is there a way to do something like ->
    [pascal]var uuu : array [0..1] of integer;
    begin
    uuu := ((1),(2));[/pascal]
    [pascal]
    const
    uuu : array[0..1] of integer = (1,2);
    [/pascal]

    What you see is what you do.
    <br />
    <br />Sorry, I'm not English well.

  3. #3

    Some doubts in pascal language..

    for in can be used to enumerate simple types and userdefined classes alike. Simple types can include chars for strings, elements in a simple array, and something else.. enums or sets I think and a normal TList+TStringlist

    For classes you have to override a function called GetEnumerator which should return a class which should inherit some enumerator. Just look at TList's implementation
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  4. #4

    Some doubts in pascal language..

    thx for the replys, for in look looks interesting when working with Tlist and other classes

    is there a way to do that ?
    Code:
    var
      lol &#58; array &#91;0..1&#93; of Integer;
    
    begin
      lol &#58;= &#40;3,2&#41;;
    From brazil (:

    Pascal pownz!

  5. #5

    Some doubts in pascal language..

    onme answer.. no

    you can't make multiple assignments to arrays in one statement without utilizing hacks
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  6. #6

    Some doubts in pascal language..

    Why hacks?
    Code:
    type TA = array&#91;0..5&#93; of Integer;
    
    function GetA&#40;const aa&#58; array of Integer&#41;&#58; TA;
    var i&#58; Integer;
    begin
      Assert&#40;High&#40;aa&#41; <= High&#40;TA&#41;, 'Too many parameters'&#41;;
      for i &#58;= 0 to High&#40;aa&#41; do Result&#91;i&#93; &#58;= aa&#91;i&#93;;
    end;
    
    var a&#58; TA;
    
    begin
      a &#58;= GetA&#40;&#91;5, 10, 20, 30, 40, 50&#93;&#41;;
    end.
    This will work even if TA - a dynamic array.

  7. #7

    Re: Some doubts in pascal language..

    Quote Originally Posted by arthurprs
    - how use "for in" loops
    Well, that is simple: don't.

    That is a pretty superficial extension, and the fact that older Delphi's and FPC don't support them is a good reason to avoid it like the plague.

    It has one nice application though, iterating over an anonymous set.

  8. #8

    Some doubts in pascal language..

    There are some pretty impressive hacks allowing to do this even on Delphi 7.

    Check this out

    http://andy.jgknet.de/dlang/

  9. #9

    Some doubts in pascal language..

    Quote Originally Posted by wodzu
    There are some pretty impressive hacks allowing to do this even on Delphi 7.

    Check this out

    http://andy.jgknet.de/dlang/
    really impresive
    From brazil (:

    Pascal pownz!

  10. #10

    Some doubts in pascal language..

    Code:
    // Free Pascal
    &#123;$assertions on&#125;
    
    procedure stuffints&#40; var a&#58; array of longint; const b&#58; array of longint&#41;;
    var i&#58; word;
    begin
      assert&#40;high&#40;b&#41;<=high&#40;a&#41;, 'Too many args to stuffints.' &#41;;
      for i &#58;= low&#40;b&#41; to high&#40;b&#41; do
        a&#91;i&#93; &#58;= b&#91;i&#93;;
    end;
    
    var
      a&#58; array&#91;1..5&#93; of longint;
      ad&#58; array of longint;
    
    begin
      stuffints&#40; a, &#91;11,22,33,44,55&#93; &#41;;
      setlength&#40; ad, 3 &#41;;
      stuffints&#40; ad, &#91;22,33,44&#93; &#41;;
    end.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •