🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #4370

Re: AnsiString and Structure

#4370
From: mikec
Date: Wed, 16 Jan 2002 11:15
136 lines
4156 bytes
Firstly, even thought you have defined a structure within a structure, you
still only have one structure with which to hold information e.g. this means
only one table name can be held.  You need to create a dynamic array of you
structure at run-time based on the number of records returned
(Table1->RecordCount).  Also you need to call Table1>Next(); to move to the
next record.  Finally, as far as I know you can't assign the
Table1->FieldByName("Name")->Value directly to a char array, you need to use
something like wsprinf to convert it.  Also best to define what the database
values are i.e. AsString, AsInteger etc.

// Globally decared
struct Fiche
{
   int num;
   char nam[20];
};
struct Fiche *bil;

// Your function to read in data

if (Table1->Active)
{
    if (Table1->RecordCount > 0)
    {
        bil = new Fiche[Table1->RecordCount];
        Table1->First();
        int i=0;
        while(!Table1->Eof)
        {
            wsprintf(bil[i].nam, "%s",
Table1->FieldByName("Name")->AsString);
            bil[i].num = Table1->FieldByName("Number")->AsInteger;
            i++;
            Table1->Next();
        }
    }
}

"bastian.cyril" <bastian.cyril@cfa-arches.e-lorraine.com> wrote in message
news:3c454547_2@dnews...
> 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: <3c4561e0$1_1@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!128.230.129.106!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews
References: <3c454547_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,c1622375d17de995
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2002-01-16 03:29:04 PST
Reply-To: "mikec" <mikec@techtonik.com>
From: "mikec" <mikec@techtonik.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <3c454547_2@dnews>
Subject: Re: AnsiString and Structure
Date: Wed, 16 Jan 2002 11:15:56 -0000
Lines: 138
Organization: Techtonik
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
NNTP-Posting-Host: 217.23.232.66
Message-ID: <3c4561e0$1_1@dnews>
X-Trace: dnews 1011180000 217.23.232.66 (16 Jan 2002 03:20:00 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!128.230.129.106!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews