Sign in Join

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

Mailing lists / fpc-pascal / 2002-08

How to assign values to a record variable?

7 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

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

mili

Hello, Every one

  Could anybody tell me that how to assign all values to a record
typed variable? I mean that in C I can assign a struct variable
such as:
  struct aaa {
    x,y:int;
  };
  struct aaa a;
  a={1,0}; //Assign in single statement
  How to implement it? The following code seems not working:
  a:=(1,0);
  Help me!
  Thank you very much.
Jonas Maebe
to mili
mili wrote
Could anybody tell me that how to assign all values to a record typed variable? I mean that in C I can assign a struct variable

... and in Pascal you cannot. You can only initialize records when they are declared.

Jonas

Martyn Ranyard
to mili: Hello, Every one Could anybody tell me that how to assign all values to a record typed…
mili wrote
Hello, Every one

Hello.

Could anybody tell me that how to assign all values to a record typed variable? I mean that in C I can assign a struct variable such as:
type
   aaa = record
     x, y : Integer
   end;
var
   a : aaa;
begin
   with a do begin
      x := 1; y := 0
   end;
end.

Neat, simple, elegent. Unlike C.

Martyn Ranyard
Free Software Advocate

jabber -
icq - 122500800
irc - Joran on oftc
msn -
e -

Göran Andersson
to Martyn Ranyard

I fI remember correctly, this worked in TP, at least:

a={x:1;y:0};

/GreenGhost
--- www.guffa.com ---

Show quoted text 39 lines
>Hello, Every one Hello. >Could anybody tell me that how to assign all values to a record >typed variable? I mean that in C I can assign a struct variable >such as: type aaa = record x, y : Integer end; var a : aaa; begin with a do begin x := 1; y := 0 end; end. Neat, simple, elegent. Unlike C. Martyn Ranyard Free Software Advocate jabber - icq - 122500800 irc - Joran on oftc msn - e - _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Göran Andersson
to Jonas Maebe

Of course it won't. Silly me. :/
It should be ordinary parenthesises.

I remember now exactly how I did it in TP. I simply made a typed constant, then any variable of the same record type can be assigned the value of the constant.

The only real difference from the C implementation is that you have to give the value a name. I bet the final compiled code will look very similar...

/GreenGhost

Show quoted text 17 lines
On Thu, 1 Aug 2002, Göran Andersson wrote: > I fI remember correctly, this worked in TP, at least: > > a={x:1;y:0}; I'm quite sure that won't work, since { ... } is a comment :) Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal