Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How can I create an structure like in C?

tijoentijoen Posts: 141Member
[b][red]This message was edited by tijoen at 2004-8-30 18:26:46[/red][/b][hr]
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 */
{ "
", 0, 0, 0 }
};

Thanks
Jonathan


Comments

  • zibadianzibadian Posts: 6,349Member
    : [b][red]This message was edited by tijoen at 2004-8-30 18:26:46[/red][/b][hr]
    : 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 */
    : { "
    ", 0, 0, 0 }
    : };
    :
    : Thanks
    : Jonathan
    :
    :
    :
    You need to use the word "record" for that. Here is a small example:
    [code]
    type
    TAddress = record
    FamilyName: string;
    Street: string;
    Number: integer;
    TelefoneNumber: double;
    end;
    [/code]

  • tijoentijoen Posts: 141Member
    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 */
    { "
    ", 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:
    : [code]
    : type
    : TAddress = record
    : FamilyName: string;
    : Street: string;
    : Number: integer;
    : TelefoneNumber: double;
    : end;
    : [/code]
  • zibadianzibadian Posts: 6,349Member
    : 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 */
    : { "
    ", 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:
    : : [code]
    : : type
    : : TAddress = record
    : : FamilyName: string;
    : : Street: string;
    : : Number: integer;
    : : TelefoneNumber: double;
    : : end;
    : : [/code]
    :
    You can make an initialized array like this:
    [code]
    var
    Colors: array[0..1, 0..9] of string = (('Test1', 'Test2'), ('Test3', 'Test4'), ('Test5', 'Test6'), etc.
    [/code]
    The number of elements must exactly match the number given in the declaration.
Sign In or Register to comment.