On 11/4/2018 5:24 PM, Sven Barth via fpc-devel wrote:
Am So., 4. Nov. 2018, 20:36 hat Gennady Agranov <gennadyagra...@gmail.com <mailto:gennadyagra...@gmail.com>> geschrieben:

    On 11/4/2018 11:24 AM, Sven Barth via fpc-devel wrote:
    Am So., 4. Nov. 2018, 12:23 hat Schindler Karl-Michael
    <karl-michael.schind...@web.de
    <mailto:karl-michael.schind...@web.de>> geschrieben:



        > Am 04.11.2018 um 12:00 schrieb Ben Grasset
        <operato...@gmail.com <mailto:operato...@gmail.com>>:
        >
        > From: Ben Grasset <operato...@gmail.com
        <mailto:operato...@gmail.com>>
        > To: FPC-Devel users discussions
        <fpc-devel@lists.freepascal.org
        <mailto:fpc-devel@lists.freepascal.org>>
        > Subject: Re: Array assignment operator
        > Message-ID:
        <cal4d7fjpfx-yst6z3--fhpr9pts-n47ksfn6m2phd7sunzw...@mail.gmail.com
        
<mailto:cal4d7fjpfx-yst6z3--fhpr9pts-n47ksfn6m2phd7sunzw...@mail.gmail.com>>
        > Content-Type: text/plain; charset="utf-8"
        >
        > On Sat, Nov 3, 2018 at 4:44 PM Gennady Agranov
        <gennadyagra...@gmail.com <mailto:gennadyagra...@gmail.com>>
        > wrote:
        >
        >> Hi,
        >>
        >> Leaving aside the reason why the MiSchi's solution doesn't
        work the main
        >> question is still not answered :)
        >>
        >> If you have integer dynamic array "MyArray" is there a way
        for the
        >> following statement to compile and work correctly:
        >>
        >> MyArray := 5;
        >>
        >
        > Uh, yes? That's what my example showed.

        In your example the length of the array was set to the number
        and the elements of the array assigned to their index,
        whereas my intention is to keep the length of the array and
        fill all elements to the same number.


    The operator always creates a new array and does not modify the
    existing one.
    You'd need to abuse a binary operator (e.g. >< or even <=) for this.

    Regards,
    Sven



    _______________________________________________
    fpc-devel maillist  -fpc-devel@lists.freepascal.org
    <mailto:fpc-devel@lists.freepascal.org>
    http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

    I was thinking that type helper might work - e.g.
    MyArray.SetValue(5) and with using properties MyArray.Value := 5

    But seems that even simple type helper is not working anymore?

    E.g. I was not able to compile example from
    http://wiki.freepascal.org/Helper_types :(

    TTypeHelper=  type  helperfor  Integer
       procedure  SetZero;
    end;

Did you add {$modeswitch typehelpers}?

If so, what is the error you get?

Regards,
Sven



_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

My error was caused by the fact that I was using delphi mode - when I used the mode switch it worked perfectly :)

The original problem is solved - at least the way I see it - in FPC you can add method to the array :)

Cool!

Thanks!

{$MODESWITCH TYPEHELPERS}

program arrayset;

type
  abc = array of integer;
  abc_helper = type helper for abc
  procedure SetValue(value: integer);
  procedure Print;
end;

procedure abc_helper.SetValue(value: integer);
var
  i: integer;
begin
  for i := Low(self) to High(self) do
    self[i] := value;
end;

procedure abc_helper.Print;
var
  i: integer;
begin
  for i := Low(self) to High(self) do
    Writeln('[',i,'] = ',self[i]);
end;

var
  a: abc;
begin
  SetLength(a,10);
  a.SetValue(5);
  a.Print;
end.

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to