Article View: borland.public.cppbuilder.database.ado
Article #4369AnsiString and Structure
From: bastian.cyril
Date: Wed, 16 Jan 2002 08:46
Date: Wed, 16 Jan 2002 08:46
93 lines
2584 bytes
2584 bytes
Hello,
I have a Table with two fields : number and name (20 characters)I built
under Paradox.
In my code, I use 2 struct :
**************************************************
struct Fiche{
int num;
char nam[20];
}*f1;
struct bilan {
struct Fiche *f1;
....
}bil;
**************************************************
I want to get name in my table Table1 and to put them in my structures.
I run :
Table1->First();
int i=0;
While(!Table1->Eof)
{
bil->f1[i].num=Table1->FieldByName("Number")->Value;
bil->f1[i].nam=Table1->FieldByName("Name")->Value; <---
i++;
|
}
|
|
|
And I get a compilation error there-----------------------------
So I changed my code :
***************************************************************
struct Fiche{
int num;
AnsiString nam;
}*f1;
struct bilan {
struct Fiche *f1;
....
}bil;
Table1->First();
int i=0;
While(!Table1->Eof)
{
bil->f1[i].num=Table1->FieldByName("Number")->Value;
AnsiString s1(Table1->FieldByName("Name")->Value),s2;
s2=SubString(1, s1.Length());
bil->f1[i].nam=s2.c_str();
i++; |
} |
file://I save all in a file
File *fin=fopen("data.dat", wb);
for(int j=0; j<i;j++)
{
fwrite(&bil->f1[j], sizeof(bil->f1[j]),1,fin);
}
file://All is ok!
BUT WHEN I LOADED IT AFTER, I use:
File *fout=fopen("data.dat", rb);
for(int j=0; j<10;j++) // I knew I had 10 records !!//
{
fwrite(&bil->f1[j], sizeof(bil->f1[j]),1,fin);
}
Label1->Caption=bil->f1[2].nam;
********************************************************************
I had this character : | instead of "John".
Why? And Somebody can explain me and give me a solution?
Technical Details
Message-ID:
<3c454547_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,c1622375d17de995,start X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2002-01-16 01:31:47 PST From: "bastian.cyril" <bastian.cyril@cfa-arches.e-lorraine.com> Newsgroups: borland.public.cppbuilder.database.ado Subject: AnsiString and Structure Date: Wed, 16 Jan 2002 09:46:41 +0100 Lines: 96 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2314.1300 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 NNTP-Posting-Host: 213.56.180.185 Message-ID: <3c454547_2@dnews> X-Trace: dnews 1011172679 213.56.180.185 (16 Jan 2002 01:17:59 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews