Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How can I create an structure like in C? Posted by tijoen on 30 Aug 2004 at 5:59 PM
This message was edited by tijoen at 2004-8-30 18:26:46

I would like to creat something like this:

struct New_Structure {
char *string_one;
integer *one;
blablabla
}

SO i could have this
var str array [0..1] of :New_Structure;
str[0].string_one := 'teste';
str[0].one_one := 0;
str[1].string_one := 'testtwo';
str[1].one_one := 1;

i don't want something editable
I would like this:
struct set_struct {
const char *cmd;
const char level;
const char pcnpc;
const char type;
} set_fields[] = {
{ "brief", 1, 2, 3 }, /* 0 */
{ "invstart", 2, 4, 6 }, /* 1 */
{ "\n", 0, 0, 0 }
};

Thanks
Jonathan


Report
Re: How can I create an structure like in C? Posted by zibadian on 30 Aug 2004 at 8:14 PM
: This message was edited by tijoen at 2004-8-30 18:26:46

: I would like to creat something like this:
:
: struct New_Structure {
: char *string_one;
: integer *one;
: blablabla
: }
:
: SO i could have this
: var str array [0..1] of :New_Structure;
: str[0].string_one := 'teste';
: str[0].one_one := 0;
: str[1].string_one := 'testtwo';
: str[1].one_one := 1;
:
: i don't want something editable
: I would like this:
: struct set_struct {
: const char *cmd;
: const char level;
: const char pcnpc;
: const char type;
: } set_fields[] = {
: { "brief", 1, 2, 3 }, /* 0 */
: { "invstart", 2, 4, 6 }, /* 1 */
: { "\n", 0, 0, 0 }
: };
:
: Thanks
: Jonathan
:
:
:
You need to use the word "record" for that. Here is a small example:
type
  TAddress = record
    FamilyName: string;
    Street: string;
    Number: integer;
    TelefoneNumber: double;
  end;


Report
Re: How can I create an structure like in C? Posted by tijoen on 31 Aug 2004 at 5:09 AM
Ok, got it, thanks
But is there a way to insert some data in those fields like in C?
struct set_struct {
const char *stringT;
const char intX;
} set_fields[] = {
{ "array zero", 1 }, /* 0 */
{ "array one", 2 }, /* 1 */
{ "\n", 0 }
};
this is a so easy way to get data that you just need to read
you would get them easy like this:
edit1.text := set_fields[0].stringT;// it would be "array zero"
I will explain why I need this, maybe it helps you hleping me hehe
There is an array called COLORS, like this: colors array [0..1] array [0..9] of string;(I am not seeing my project now)
then I would just need to read its data
when the server send the number 15 for example
I would read edit.text := colors[1][5];
I would like to do that without having to do this:
Colors[1][0] := 'test1';
Colors[1][1] := 'test2';
Colors[1][2] := 'test3';
Colors[1][3] := 'test4';
Colors[0][1] := 'test0';
on my forms oncreat...


: You need to use the word "record" for that. Here is a small example:
:
: type
:   TAddress = record
:     FamilyName: string;
:     Street: string;
:     Number: integer;
:     TelefoneNumber: double;
:   end;
: 

Report
Re: How can I create an structure like in C? Posted by zibadian on 31 Aug 2004 at 5:40 AM
: Ok, got it, thanks
: But is there a way to insert some data in those fields like in C?
: struct set_struct {
: const char *stringT;
: const char intX;
: } set_fields[] = {
: { "array zero", 1 }, /* 0 */
: { "array one", 2 }, /* 1 */
: { "\n", 0 }
: };
: this is a so easy way to get data that you just need to read
: you would get them easy like this:
: edit1.text := set_fields[0].stringT;// it would be "array zero"
: I will explain why I need this, maybe it helps you hleping me hehe
: There is an array called COLORS, like this: colors array [0..1] array [0..9] of string;(I am not seeing my project now)
: then I would just need to read its data
: when the server send the number 15 for example
: I would read edit.text := colors[1][5];
: I would like to do that without having to do this:
: Colors[1][0] := 'test1';
: Colors[1][1] := 'test2';
: Colors[1][2] := 'test3';
: Colors[1][3] := 'test4';
: Colors[0][1] := 'test0';
: on my forms oncreat...
:
:
: : You need to use the word "record" for that. Here is a small example:
: :
: : type
: :   TAddress = record
: :     FamilyName: string;
: :     Street: string;
: :     Number: integer;
: :     TelefoneNumber: double;
: :   end;
: : 

:
You can make an initialized array like this:
var
  Colors: array[0..1, 0..9] of string = (('Test1', 'Test2'), ('Test3', 'Test4'), ('Test5', 'Test6'), etc.

The number of elements must exactly match the number given in the declaration.



 

Recent Jobs