<div>Doesn't work this code doesn't compile:</div><div> </div><div>type</div><div> { TRec }</div><div> TRec = record<br> Nome: String;<br> class function Create(aNome: String): TRec; static; inline;<br> end;</div>
<div> </div><div>procedure ShowTRec(rec: TRec);</div><div> </div><div>implementation</div><div> </div><div>{$R *.lfm}</div><div> </div><div>procedure ShowTRec(rec: TRec);<br>begin<br> ShowMessage(rec.Nome);<br>end;</div>
<div> </div><div>{ TRec }</div><div> </div><div>class function TRec.Create(aNome: String): TRec;<br>begin<br> Result.Nome := aNome;<br>end;</div><div> </div><div>{ TForm1 }</div><div> </div><div>procedure TForm1.Button1Click(Sender: TObject);<br>
begin<br> ShowTRec(TRec.Create('Pascal'));<br>end; <br><br></div><div class="gmail_quote">2012/2/24 kyan <span dir="ltr"><<a href="mailto:alfasud.ti@gmail.com">alfasud.ti@gmail.com</a>></span><br><blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">
<div class="im">>> Is there any how to do it?<br>
<br>
</div>You can use advanced record syntax and do something like this:<br>
<div class="im"><br>
type<br>
TRec = record<br>
Numero: Integer;<br>
Nome: String;<br>
</div> class function Create(ANumero: Integer; const ANome: string):<br>
TRec; static; inline;<br>
end;<br>
<br>
...<br>
<br>
class function TRec.Create(ANumero: Integer; const ANome: string): TRec;<br>
begin<br>
with Result do<br>
begin<br>
Numero := ANumero;<br>
Nome := ANome;<br>
end;<br>
end;<br>
<br>
...<br>
<br>
procedure TForm1.Button1Click(Sender: TObject);<br>
begin<br>
ShowTRec(TRec.Create(1, 'Pascal'));<br>
end;<br>
<br>
PS: In Delphi advanced records can have constructors but not yet in<br>
FPC. A static class function can easily replace them.<br>
_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Everton Vieira.<br>