Sign in Join

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

Mailing lists / fpc-pascal / 2006-11

Initializing record variables

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Marc Santhoff

Hi,

I have to translate a lot of assignements like this:

particle_t = record
		name: array [0..Pred(16)] of char;
		longi: integer;
		pressure: float;
		temperature: double;
		lati: integer;
	end;
ibuf: array [0..Pred(2)] of particle_t;
(* raw translation by automatic tool *)
ibuf:=(('zero'#0,0,0.0f,0.0,0),('zero'#0,0,0.0f,0.0,0));

from C to pascal. To make it easier I'd like to write something like:

ibuf: array [0..Pred(2)] of particle_t = ???

analoguous to

i: integer = 42;

Is there any syntax allowing to do so? If yes, it would be very easy to do instead of addressing each record field by name for any record in the target array.

TIA,
Marc

Unknown author
to Marc Santhoff
Show quoted text 12 lines
particle_t = record name: array [0..Pred(16)] of char; longi: integer; pressure: float; temperature: double; lati: integer; end; ibuf: array [0..Pred(2)] of particle_t; (* raw translation by automatic tool *) ibuf:=(('zero'#0,0,0.0f,0.0,0),('zero'#0,0,0.0f,0.0,0));

This should work:

type
  TRoleDetails = record
    Name, Descr: String;
  end;

const
cRoles: array[1..3] of TRoleDetails = (
(Name: 'zEditRole'; Descr: 'z Edit role descr'),
(Name: 'yEditRole'; Descr: 'y Edit role descr'),
(Name: 'xEditRole'; Descr: 'x Edit role descr')

    );

You need to name the elements, and they need to be in the order they're declared in the record.

Moz

Marco van de Voort
to Marc Santhoff: I have to translate a lot of assignements like this: particle_t = record name: array…
Show quoted text 26 lines
I have to translate a lot of assignements like this: particle_t = record name: array [0..Pred(16)] of char; longi: integer; pressure: float; temperature: double; lati: integer; end; ibuf: array [0..Pred(2)] of particle_t; (* raw translation by automatic tool *) ibuf:=(('zero'#0,0,0.0f,0.0,0),('zero'#0,0,0.0f,0.0,0)); from C to pascal. To make it easier I'd like to write something like: ibuf: array [0..Pred(2)] of particle_t = ??? analoguous to i: integer = 42; Is there any syntax allowing to do so? If yes, it would be very easy to do instead of addressing each record field by name for any record in the target array.

As a global constant: yes. Locally, no.

So

int func ()
{xarray i = ((arrayconst));

}

translates roughly to

var constant_func_1_array : xarray = ((1,4,2,2),(3,3,3,3));
function func:cint;
var i : xarray;
begin
  i:=constant_func_1_array;
end;

If you have your automatic tool in src, you might be able to hack it in.

Marc Santhoff
to Unknown author: This should work: type TRoleDetails = record Name, Descr: String; end; const cRoles:…

Am Donnerstag, den 09.11.2006, 19:52 -0700 schrieb

Show quoted text 29 lines
> particle_t = record > name: array [0..Pred(16)] of char; > longi: integer; > pressure: float; > temperature: double; > lati: integer; > end; > > ibuf: array [0..Pred(2)] of particle_t; > (* raw translation by automatic tool *) > ibuf:=(('zero'#0,0,0.0f,0.0,0),('zero'#0,0,0.0f,0.0,0)); This should work: type TRoleDetails = record Name, Descr: String; end; const cRoles: array[1..3] of TRoleDetails = ( (Name: 'zEditRole'; Descr: 'z Edit role descr'), (Name: 'yEditRole'; Descr: 'y Edit role descr'), (Name: 'xEditRole'; Descr: 'x Edit role descr') ); You need to name the elements, and they need to be in the order they're declared in the record.

I see. if other approaches fail this at least gives me some hook for applying regular expressions. That should help recucing the amount of work.

Thanks,
Marc

Marc Santhoff
to Marco van de Voort: As a global constant: yes. Locally, no. So int func () {xarray i = ((arrayconst)); }…
Marco van de Voort wrote 46 lines
> I have to translate a lot of assignements like this: > > particle_t = record > name: array [0..Pred(16)] of char; > longi: integer; > pressure: float; > temperature: double; > lati: integer; > end; > > ibuf: array [0..Pred(2)] of particle_t; > > (* raw translation by automatic tool *) > ibuf:=(('zero'#0,0,0.0f,0.0,0),('zero'#0,0,0.0f,0.0,0)); > > from C to pascal. To make it easier I'd like to write something like: > > ibuf: array [0..Pred(2)] of particle_t = ??? > > analoguous to > > i: integer = 42; > > Is there any syntax allowing to do so? If yes, it would be very easy to > do instead of addressing each record field by name for any record in the > target array. As a global constant: yes. Locally, no. So int func () {xarray i = ((arrayconst)); } translates roughly to var constant_func_1_array : xarray = ((1,4,2,2),(3,3,3,3)); function func:cint; var i : xarray; begin i:=constant_func_1_array; end;

Okay, I think most in most cases globally scoped constants will do. :)

If you have your automatic tool in src, you might be able to hack it in.

No, I've tried three variants of p2c converters and the one working best is closed source (IIRC, maybe a delphi source which would need translation or adaption itself).

But I think I get along with the two ways of solving this problem.

Thank you very much,
Marc