Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-02

Class const of array of record.

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Everton Vieira

I was trying to make this construction:

type
  TRec = record
    Numero: Integer;
    Nome: String;
  end;
function mTRec(Numero: Integer; Nome: String): TRec;
type
  TTest = class
    const Nomes: array[0..2] of TRec = (mTRec(1, 'everton'), mTRec(2,
'murilo'), mTRec(3, 'vieira'));
  end;
implementation
{$R *.lfm}
function mTRec(Numero: Integer; Nome: String): TRec;
begin
  Result.Numero := Numero;
  Result.Nome := Nome;
end;

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
  i1: Integer;
begin
  for i1 := 0 to Length(TTest.Nome) -1 do
    ShowMessage(TTest.Nomes[i1].Nome);
end;

Is there any how to do it?

Everton Vieira. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120224/a8540e33/attachment.html>
Hans-Peter Diettrich
to Everton Vieira
Show quoted text 15 lines
I was trying to make this construction: type TRec = record Numero: Integer; Nome: String; end; function mTRec(Numero: Integer; Nome: String): TRec; type TTest = class const Nomes: array[0..2] of TRec = (mTRec(1, 'everton'), mTRec(2, 'murilo'), mTRec(3, 'vieira')); end;

[...]

Is there any how to do it?

Do what?

Above declaration looks to me as if you define a constant array, that exists only once in memory. You can move the "const..." out of the class, with the same effect.

DoDi

Adrian Veith
to Everton Vieira: I was trying to make this construction: type TRec = record Numero: Integer; Nome: String;…
try
((Numero:1;  Nome'everton'), (Numero:2; Nome: 'murilo'), (Numero:3;
Nome:'vieira'));
Everton Vieira wrote 35 lines
I was trying to make this construction: type TRec = record Numero: Integer; Nome: String; end; function mTRec(Numero: Integer; Nome: String): TRec; type TTest = class const Nomes: array[0..2] of TRec = (mTRec(1, 'everton'), mTRec(2, 'murilo'), mTRec(3, 'vieira')); end; implementation {$R *.lfm} function mTRec(Numero: Integer; Nome: String): TRec; begin Result.Numero := Numero; Result.Nome := Nome; end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); var i1: Integer; begin for i1 := 0 to Length(TTest.Nome) -1 do ShowMessage(TTest.Nomes[i1].Nome); end; Is there any how to do it? -- Everton Vieira. This body part will be downloaded on demand.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120224/3f2f8f97/attachment.html>

Everton Vieira
to Adrian Veith

Worked, even better than i thought.

Many thanks!
2012/2/24 Adrian Veith

Show quoted text 58 lines
try ((Numero:1; Nome'everton'), (Numero:2; Nome: 'murilo'), (Numero:3; Nome:'vieira')); Am 24.02.2012 14:28, schrieb Everton Vieira: I was trying to make this construction: type TRec = record Numero: Integer; Nome: String; end; function mTRec(Numero: Integer; Nome: String): TRec; type TTest = class const Nomes: array[0..2] of TRec = (mTRec(1, 'everton'), mTRec(2, 'murilo'), mTRec(3, 'vieira')); end; implementation {$R *.lfm} function mTRec(Numero: Integer; Nome: String): TRec; begin Result.Numero := Numero; Result.Nome := Nome; end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); var i1: Integer; begin for i1 := 0 to Length(TTest.Nome) -1 do ShowMessage(TTest.Nomes[i1].Nome); end; Is there any how to do it? -- Everton Vieira. This body part will be downloaded on demand. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Everton Vieira. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120224/86db54df/attachment.html>
Everton Vieira
to Everton Vieira: I was trying to make this construction: type TRec = record Numero: Integer; Nome: String;…

Is contructions like this that aren't available:

type
  TRec = record
    Numero: Integer;
    Nome: String;
  end;
implementation
{$R *.lfm}
procedure ShowTRec(rec: TRec);
begin
  ShowMessage(rec.Nome);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowTRec((Numero: 1; Nome: 'Pascal'));
end;

In this constructions is that today is nice to use a function to create the TRec.

2012/2/24 Everton Vieira

Show quoted text 41 lines
I was trying to make this construction: type TRec = record Numero: Integer; Nome: String; end; function mTRec(Numero: Integer; Nome: String): TRec; type TTest = class const Nomes: array[0..2] of TRec = (mTRec(1, 'everton'), mTRec(2, 'murilo'), mTRec(3, 'vieira')); end; implementation {$R *.lfm} function mTRec(Numero: Integer; Nome: String): TRec; begin Result.Numero := Numero; Result.Nome := Nome; end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); var i1: Integer; begin for i1 := 0 to Length(TTest.Nome) -1 do ShowMessage(TTest.Nomes[i1].Nome); end; Is there any how to do it? -- Everton Vieira.
Everton Vieira. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120224/75385758/attachment-0001.html>
Everton Vieira

static; should be a keyword, doesn't?

2012/2/24 Everton Vieira

Show quoted text 28 lines
Is true, with {$modeswitch advancedrecords} worked. But i dont see much sense in put a diretive for enable a new feature. 2012/2/24 Jonas Maebe > > On 24 Feb 2012, at 17:50, kyan wrote: > > Sorry, I forgot to mention that advanced record syntax works in Delphi > mode only. To compile it you must change {$mode objfpc} to {$mode > Delphi}. > > > Or add {$modeswitch advancedrecords} after {$mode objfpc} > > > Jonas > > _______________________________________________ > fpc-pascal maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > -- Everton Vieira.
Everton Vieira. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120224/0960576c/attachment.html>