Sign in Join

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

Mailing lists / fpc-pascal / 2004-02

Defining Records on the fly:

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Jon D. Sawyer
If I have this type:
Type tMyRec = Record X, Y: Integer; End;

and can do this:

Const ARec : tMyRec = (X:12; Y:25);

why can't I do this?

var
  AnotherRec: tMyRec;
begin
  AnotherRec := (X:12; Y:25);
end.

** Feel free to smack me around.

Shawn Tan Ser Ngiap
to Jon D. Sawyer

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jon D. Sawyer wrote 8 lines
Const ARec : tMyRec = (X:12; Y:25); why can't I do this? var AnotherRec: tMyRec; begin AnotherRec := (X:12; Y:25);

It's just the way the language is... you could do this...

AnotherRec.X := 12;
AnotherRec.Y := 25;

or this, if i'm not mistaken...

with AnotherRec do begin
	X := 12;
	Y := 25;
end;

with metta,
Shawn Tan.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAMJGK9KUEj/m6O5oRAgFLAJ9P8GoTc62l310Zq99F1g6RujOuwgCgsdc7 liXNcgoLQIPREr7BbN0lG6c=
=u2G5
-----END PGP SIGNATURE-----

Jon D. Sawyer
to Shawn Tan Ser Ngiap
Here is why I was wondering why you couldn't, say I have this type:
Type tMyRec = Record X, Y : Real; End;

And I have this function:

Function CheckPoint(aPoint: tMyRec): Boolean;
Begin
  {Does something here..}
end;
begin
  CheckPoint((X:1.2;Y:2.2));
end.

In short I think it would be a nifty feature.. but hey.. I was just wondering.

Shawn Tan Ser Ngiap wrote 40 lines
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Monday 16 February 2004 00:40, Jon D. Sawyer wrote: > Const ARec : tMyRec = (X:12; Y:25); > > why can't I do this? > > var > AnotherRec: tMyRec; > begin > AnotherRec := (X:12; Y:25); It's just the way the language is... you could do this... AnotherRec.X := 12; AnotherRec.Y := 25; or this, if i'm not mistaken... with AnotherRec do begin X := 12; Y := 25; end; with metta, Shawn Tan. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQFAMJGK9KUEj/m6O5oRAgFLAJ9P8GoTc62l310Zq99F1g6RujOuwgCgsdc7 liXNcgoLQIPREr7BbN0lG6c= =u2G5 -----END PGP SIGNATURE----- _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Jeff Pohlmeyer

Since Free Pascal supports function overloading,
you could do something like this:

Function CheckPoint(X, Y:real): Boolean;
Begin
  {Does something here..}
end;
Function CheckPoint(aPoint: tMyRec): Boolean;
Begin
  Result:=CheckPoint(aPoint.X, aPoint.Y);
end;
// So you can use it either way:
var
  MyRec:tMyRec;
begin
  if CheckPoint(MyRec) then {do stuff};
  if CheckPoint(1.2, 2.2) then {do more stuff};
end;
Show quoted text 13 lines
Here is why I was wondering why you couldn't, say I have this type: Type tMyRec = Record X, Y : Real; End; And I have this function: Function CheckPoint(aPoint: tMyRec): Boolean; Begin {Does something here..} end; begin CheckPoint((X:1.2;Y:2.2)); end.

__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want. http://antispam.yahoo.com/tools

Jon D. Sawyer
to Adam Victor Nazareth Brandizzi: You can also define a function that returns the record you need: function NewMyRec( X, Y…

^_^ Thats how its working at the moment and I've known that FPC doesn't do that kinda definition on the fly. My real question was why not?

Adam Victor Nazareth Brandizzi wrote 74 lines
You can also define a function that returns the record you need: function NewMyRec( X, Y : double ) : TMyRec; begin NewMyRec.x := X; NewMyRec.y := Y; end; I think it's really better than declare a new variable and initialize it by the code. if CheckPoint(NewMyRec(1.2, 2.2)) then ... Be well... Jeff Pohlmeyer wrote: >Since Free Pascal supports function overloading, >you could do something like this: > > >Function CheckPoint(X, Y:real): Boolean; >Begin > {Does something here..} >end; > > >Function CheckPoint(aPoint: tMyRec): Boolean; >Begin > Result:=CheckPoint(aPoint.X, aPoint.Y); >end; > > >// So you can use it either way: > >var > MyRec:tMyRec; >begin > if CheckPoint(MyRec) then {do stuff}; > if CheckPoint(1.2, 2.2) then {do more stuff}; >end; > > > > >>Here is why I was wondering why you couldn't, say I have this type: >>Type tMyRec = Record X, Y : Real; End; >> >>And I have this function: >> >>Function CheckPoint(aPoint: tMyRec): Boolean; >>Begin >> {Does something here..} >>end; >> >>begin >> CheckPoint((X:1.2;Y:2.2)); >>end. >> >> > > >__________________________________ >Do you Yahoo!? >Yahoo! Mail SpamGuard - Read only the mail you want. >http://antispam.yahoo.com/tools > >_______________________________________________ >fpc-pascal maillist - >http://lists.freepascal.org/mailman/listinfo/fpc-pascal > > >
Adam Victor Nazareth Brandizzi
to Jeff Pohlmeyer: Since Free Pascal supports function overloading, you could do something like this:…

You can also define a function that returns the record you need:

function NewMyRec( X, Y : double ) : TMyRec;
begin
   NewMyRec.x := X;
   NewMyRec.y := Y;
end;

I think it's really better than declare a new variable and initialize it by the code.

if CheckPoint(NewMyRec(1.2, 2.2)) then ...

Be well...

Jeff Pohlmeyer wrote 56 lines
Since Free Pascal supports function overloading, you could do something like this: Function CheckPoint(X, Y:real): Boolean; Begin {Does something here..} end; Function CheckPoint(aPoint: tMyRec): Boolean; Begin Result:=CheckPoint(aPoint.X, aPoint.Y); end; // So you can use it either way: var MyRec:tMyRec; begin if CheckPoint(MyRec) then {do stuff}; if CheckPoint(1.2, 2.2) then {do more stuff}; end; >Here is why I was wondering why you couldn't, say I have this type: >Type tMyRec = Record X, Y : Real; End; > >And I have this function: > >Function CheckPoint(aPoint: tMyRec): Boolean; >Begin > {Does something here..} >end; > >begin > CheckPoint((X:1.2;Y:2.2)); >end. > > __________________________________ Do you Yahoo!? Yahoo! Mail SpamGuard - Read only the mail you want. http://antispam.yahoo.com/tools _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Adam Victor Nazareth Brandizzi Estudante de Ciência da Computação - UnB e-mails: , ICQ: 168537710 Jaber: bardo0 (users.jabber.org)