Helene,

the compilation fails because you try StrCopy to a const char*. This is 
not allowed. At the other hand you haven't allocated the space for your 
string. So if the compiler hasn't complain you would have run into a big 
memory trash. So you either use the way as the structure is initialized 
in the example or (much better) you allocate the space you need for the 
strings with MemPtrNew() and change the type of the strings to char* 
without const. Another way would be to declare the structure with 
character arrays instead of character pointers, like char name[32]. But 
then you have to be careful not to overwrite this buffer.

Henk

[EMAIL PROTECTED] wrote:

> Hello,
> 
> I have to make a Palm database, I use the example of the O'REILLY book to help me.
> 
> It works fine but I don't know how to enter my own record in the database.
> 
> Here is the record structure :
> 
> typedef struct PackedCustomer{
>    UInt16 customerID;
>    Char  name[1]; // actually may be longer than 1
> } PackedCustomer;
> 
> typedef struct Customer{
>    UInt16      customerID;
>    const Char *name;
>    const Char *address;
>    const Char *city;
>    const Char *phone;
> } Customer;
> 
> 
> The autors use this to initialyse the database :
> 
> static void InitializeCustomers(void)
> {
>    Customer c1 = {1, "Joe's toys-1", "123 Main St." ,"Anytown", 
>       "(123) 456-7890"};
>    Customer c2 = {2, "Bucket of Toys-2", "" ,"", ""};
>    Customer c3 = {3, "Toys we be-3", "" ,"", ""};
>    Customer c4 = {4, "a", "" ,"", ""};
>    Customer c5 = {5, "b", "" ,"", ""};
>    Customer c6 = {6, "c", "" ,"", ""};
>    Customer c7 = {7, "d", "" ,"", ""};
>    Customer *customers[7];
>    UInt16  numCustomers = sizeof(customers) / sizeof(customers[0]);
>    UInt16  i;
>    MemHandle h;
>    UInt16 index;
>    Customer c1;   
>    customers[0] = &c1;
>    customers[1] = &c2;
>    customers[2] = &c3;
>    customers[3] = &c4;
>    customers[4] = &c5;
>    customers[5] = &c6;
>    customers[6] = &c7;
>    
> 
> 
>    for (i = 0; i < numCustomers; i++) 
>    {   
>       index = dmMaxRecordIndex;
>       h = DmNewRecord(gDBC, &index, 1);
>       if (h) {
>          PackCustomer(customers[i], h);
>          DmReleaseRecord(gDBC, index, true);
>       }
>    }
> }
> 
> 
> But I would like to fill my database on my own, I don't want this :  "  Customer c1 
>= {1, "Joe's toys-1", "123 Main St." ,"Anytown", 
>       "(123) 456-7890"}; "
> 
> I have tried this :   
> c1.customerID = 1;
> StrCopy(c1.name,"test");
> 
> But on StrCopy, the compilation failed.
> 
> Is someone have an idea it would be extremely helpful.
> 
> Thanks in advance
> 
> Helene
> ------------------------------------------
> 
> Faites un voeu et puis Voila ! www.voila.fr 
> 
> 
> 
> 


-- 
-------------------------------------------------------------------------
[EMAIL PROTECTED]                                       www.metaviewsoft.de

<A HREF="http://www.handango.com/PlatformTopSoftware.jsp?authorId=95946";>
<IMG SRC="http://user.cs.tu-berlin.de/~jonash/werbung.jpg";></A>
-------------------------------------------------------------------------


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to