Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delphi syntax 2

Status
Not open for further replies.

joeGrammar

Programmer
Jun 4, 2001
162
CA
Can anyone tell me why this is not ok and what I have to do to make this initialization work? I'm more of a C guy

type
TPart = record
name: String;
size: Integer;
dt: Integer;
end;

const
cpha30_11: array[0..2] of TPart = (
('A0101', 6, 0),
('A0203', 2, 0),
('A0303', 2, 1)
}
 
Joe,

you have to write

type
TPart = record
name: String;
size: Integer;
dt: Integer;
end;

const
cpha30_11: array[0..2] of TPart = (
(name:'A0101'; size:6; dt:0),
(name:'A0203'; size:2; dt:0),
(name:'A0303'; size:2; dt:1)
);


I personally don't understand why Delphi's compiler has been designed this way....

regards
Rod

 
Man that's a waste of my time, crappy delphi! Thanks!
 
ok wait, that doesn't work either... no I have two things that don't work:

type
TPart = record
name: String;
size: Integer;
dt: Integer;
end;

const
cpha30_11: array[0..2] of TPart = (
('A0101', 6, 0),
('A0203', 2, 0),
('A0303', 2, 1)
)
and

const
cpha30_11: array[0..2] of TPart = (
(name:'A0101'; size:6; dt:0),
(name:'A0203'; size:2; dt:0),
(name:'A0303'; size:2; dt:1)
);




 
Works for me!

Do you have a space between array and [ ?
Cheers,
Nico
 
OK, it doesn't work for me, here's my code


function TCPHADataModule.createXML(): boolean;

type
TPart = record
name: String;
size: Integer;
dt: Integer;
end;

const
arry: array[0..1] of TPart = (
(name:'test',size:4,dt:4), /*line 100*/
(name:'test',size:4,dt:4)
);

begin
end;

Here's the errors:

[Error] dataModuleCPHA.pas(100): ')' expected but ',' found
[Error] dataModuleCPHA.pas(100): ';' expected but ')' found
[Error] dataModuleCPHA.pas(101): '..' expected but ',' found
[Error] dataModuleCPHA.pas(101): '..' expected but ')' found
[Error] dataModuleCPHA.pas(102): Expression expected but ';' found
 
Rod says he doesn't understand why the Delphi compiler has been designed that way. Joegrammer suggests that Delphi is crappy and it is a waste of time.

The advantage of the syntax is that you don't have to specify all the fields. For example,
Code:
const
  cpha30_11: array[0..2] of TPart = (
      (name:'A0101'; dt:0),
      (name:'A0203'; size:2; dt:0),
      ()
      );
is valid. nulls and zeros are used as default strings and numbers respectively. So
Code:
cpha30_11[2].size
would contain a zero even though it has not been specified. This could be quite helpful in large arrays where there is little non zero or non null data.

Somtimes counting a large number of commas, null and zero values in a 'C' constant can be a pain and error prone.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top