Doesn't work this code doesn't compile: type { TRec } TRec = record Nome: String; class function Create(aNome: String): TRec; static; inline; end;
procedure ShowTRec(rec: TRec); implementation {$R *.lfm} procedure ShowTRec(rec: TRec); begin ShowMessage(rec.Nome); end; { TRec } class function TRec.Create(aNome: String): TRec; begin Result.Nome := aNome; end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin ShowTRec(TRec.Create('Pascal')); end; 2012/2/24 kyan <alfasud...@gmail.com> > >> Is there any how to do it? > > You can use advanced record syntax and do something like this: > > type > TRec = record > Numero: Integer; > Nome: String; > class function Create(ANumero: Integer; const ANome: string): > TRec; static; inline; > end; > > ... > > class function TRec.Create(ANumero: Integer; const ANome: string): TRec; > begin > with Result do > begin > Numero := ANumero; > Nome := ANome; > end; > end; > > ... > > procedure TForm1.Button1Click(Sender: TObject); > begin > ShowTRec(TRec.Create(1, 'Pascal')); > end; > > PS: In Delphi advanced records can have constructors but not yet in > FPC. A static class function can easily replace them. > _______________________________________________ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > -- Everton Vieira.
_______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal