[fpc-pascal] Re: Class const of array of record.
kyan
alfasud.ti at gmail.com
Fri Feb 24 16:57:36 CET 2012
>> 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.
More information about the fpc-pascal
mailing list