🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.database.multi-tier
2 messages
2 total messages Started by Terry Fryar Mon, 23 Jul 2001 18:49
TClientDataSet problem...
#555
Author: Terry Fryar
Date: Mon, 23 Jul 2001 18:49
7 lines
1309 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?
Re: TClientDataSet problem...
#563
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads