🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.multi-tier
Article #563

Re: TClientDataSet problem...

#563
From: Harold Howe (TeamB)
Date: Sun, 05 Aug 2001 22:40
64 lines
3053 bytes
> I am inserting records into a TClientDataSet using AppendRecord().
> LogChanges has been set to false.  I have a string field (ftString) that
> 
> I am inserting spaces into.  However, when I look at the inserted
> records, the space filled string field has a NULL value.  Is there an
> auto-trimming of spaces done for an ftString fieldtype in a
> TClientDataSet?  Why are the spaces being removed by the clientdataset?

I can reproduce this. It looks like a bug in midas.dll. I will report a bug on it. In
the meantime, here is a work around. 


// use this function instead of setting AsString.
void SetFieldAsString(TField *f, const AnsiString &s)
{
    AnsiString temp (AnsiString::StringOfChar(' ', s.Length()));
    if(s != temp)
        f->AsString = s;
    else // else: the string is nothing bug spaces,
    {    // we must do some hacking to get it in.

        // set the last char to a # character. Remember that
        // AnsiString's are indexed from Zero
        temp[temp.Length()] = '#';

        // assign the temp string to the field.
        f->AsString = temp;

        // find where the string is stored in the dataset
        // this is equal to ActiveBuffer() + some offset (the offset has
        // to be calculated)
        char *buf = f->DataSet->ActiveBuffer();
        int offset = 0;
        int index = 1;
        while(index < f->FieldNo)
        {
            offset += f->DataSet->Fields->Fields[index-1]->DataSize;
            ++index;
        }
        buf += offset;

        // buf not points to the string we just assigned.
        // go back in and set the last character to a space
        // note that buf is a char *, so we are back to C
        // style, 0 based arrays.
        buf[temp.Length() -1] = ' ';

    }
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    ClientDataSet1->Append();
    AnsiString s = "          ";
    SetFieldAsString(ClientDataSet1foo, s);
    ClientDataSet1->Post();

    if(ClientDataSet1foo -> AsString !=  s)
        ShowMessage("whoa");

}

Harold Howe [TeamB]
http://www.bcbdev.com
Technical Details
Message-ID: <3B6DCB62.23877570@bcbdev.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!216.218.192.242!news.he.net!news-hog.berkeley.edu!ucberkeley!enews.sgi.com!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews
References: <3B5C71C7.B8F6B398@williamsonco.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fcd2b,622910680d2a541e
X-Google-Attributes: gidfcd2b,public
X-Google-ArrivalTime: 2001-08-05 16:06:59 PST
Message-ID: <3B6DCB62.23877570@bcbdev.com>
Date: Sun, 05 Aug 2001 17:40:34 -0500
From: "Harold Howe (TeamB)" <hhowe@bcbdev.com>
X-Mailer: Mozilla 4.03 [en] (WinNT; I)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.database.multi-tier
Subject: Re: TClientDataSet problem...
References: <3B5C71C7.B8F6B398@williamsonco.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 24.22.227.236
X-Trace: dnews 997051254 24.22.227.236 (5 Aug 2001 15:40:54 -0700)
Lines: 64
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!216.218.192.242!news.he.net!news-hog.berkeley.edu!ucberkeley!enews.sgi.com!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews