Thanks guys!
I've been using Scott's method, but in this case I was trying to make my
code as generic as possible. In other words, I'm trying to write code that
will populate each form field with a corresponding database field, without
me knowing before hand that my database field offsets will be. So where I
have fields length and offset hard coded in the program, in reality I'd be
making a call to a function that will read the record and return the
appropriate offset and length at run-time. In fact, I won't even know before
run-time how many records or fields exist in the database. Hence I don't see
how I can stick with Scott's suggestion, even though it's worked very well
for me in the past.
Does anyone have any ideas on how I could use FldSetText to work around the
handle size? From Robert's explanation below, it seems like it's impossible
to do what I'm trying, but maybe there is a way...???
george r.
"Robert McKenzie" <[EMAIL PROTECTED]> wrote in message
news:56732@palm-dev-forum...
>
> Scott's method works fine.
>
> However, let me try to clear up some basic matters about
> FldSetTextHandle vs. FldSetText.
>
> A field deals with its contents without regard to how
> it got them. That is to say, if you call FldSetTextHandle, it
> will get the size of handle and use that to call FldSetText
> with a zero offset.
>
> i.e.
> FldSetTextHandle(fld, h);
> is equivalent to:
> FldSetText(fld, h, 0, MemHandleSize(h));
>
> A field is designed to allow dynamic changing of its
> text (indeed, that is its main reason for existing).
> It will resize the handle, leaving the area before
> the offset alone and shifting the area after the offset + size
> as needed as the text grows or shrinks. This can result
> in the handle becoming invalid, so you should always
> fetch it back from the field when you need it again.
>
> Only one field can be active in a form at a time. You
> can have multiple fields all pointing into the same handle.
> In this case, you should use the load data and save data
> callbacks to insure that everything stays coordinated.
> This is a complicated strategy, but it does work
> (see the address book example's edit view for an implementation).
> The complications involved in this strategy lead many to take
> Scott's approach. This burns some extra memory, but it
> also works just fine and many consider it to be more
> straightforward. You pays your money and you takes your chances...
>
> -bob mckenzie
>
> -----Original Message-----
> From: Scott Brooks [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 16, 2001 6:17 AM
> To: Palm Developer Forum
> Subject: Re: FldSetText Question
>
>
> I just use another variable and fill it with the text I want.
>
> Here, I grap a value I call "pCount":
>
> UInt16 YOUR_TEXT_LENGTH = 9, YOUR_OFFSET = 4;
>
> recHandle = DmGetRecord(testDB, CurrentItem);
> recText = MemHandleLock(recHandle);
>
> pCountHandle = MemHandleNew(YOUR_TEXT_LENGTH);
> pCountText = MemHandleLock(pCountHandle);
>
> // first initiallize it with an array of NULL's
> MemMove(pCountText, fillerNineLong, YOUR_TEXT_LENGTH);
> MemMove(pCountText, recText + YOUR_OFFSET, YOUR_TEXT_LENGTH);
> MemHandleUnlock(pCountHandle);
> fldIndex = FrmGetObjectIndex(frm, SPECIFIEDField);
> FldSetTextHandle(FrmGetObjectPtr(frm, fldIndex), pCountHandle);
>
> MemHandleUnlock(recHandle);
> DmReleaseRecord(CycleCountDB, CurrentItem, 0);
>
> Regards,
> Scott
>
>
>
> >From: "George R" <[EMAIL PROTECTED]>
> >Reply-To: "Palm Developer Forum" <[EMAIL PROTECTED]>
> >To: "Palm Developer Forum" <[EMAIL PROTECTED]>
> >Subject: FldSetText Question
> >Date: Mon, 16 Jul 2001 08:34:41 -0400
> >
> >I'm trying to use FldSetText to set a handle to a field. My handle is
> >actually a pointer to a record in my database. I want to set portions of
> >the
> >handle that correspond to database fields to different form fields. Thus
I
> >don't want to use FldSetTextHandle. While FldSetText is supposed to allow
> >you to set the number of bytes you wish to set, it doesn't appear to be
> >working right. Has anyone had any experience using FldSetText to set
subset
> >of a handle that's NOT a null terminated string (my database does not use
> >null terminated strings for each field)? When I try it, I get a debug
error
> >saying "Text Block Size smaller than Text", and the field is populated
with
> >more data than I request (eac field hsows data up to the NULL
termination,
> >regardless of the size I send).
> >
> >Also, does FldSetText allow you to edit the field or not? I've read
> >conflicting statements on this, but the latest Palm OS Reference says
> >FldSetText and FldSetTextHandle allow you to edit fields in place.
> >
> >Below are the relevant sections of my code:
> >// totalOffset holds the number of bytes at the ebginning of each record
> >used to store field offset sizes.
> >
> > record = cursor;
> > maxColumns = numColumns;
> > dataRecord = DmQueryRecord (dataDB, record);
> > precord = (Char*) MemHandleLock (dataRecord);
> > FrmDrawForm (form);
> > details = MemHandleNew (MemHandleSize (dataRecord) - totalOffset);
> > stringT = (Char*) MemHandleLock (details);
> > StrCopy (stringT, precord + totalOffset);
> > MemHandleUnlock (dataRecord);
> > MemHandleUnlock (details);
> > for (loopIndex = 0; loopIndex < numColumns; loopIndex++)
> > {
> > if (loopIndex == 0)
> > {
> > offset = 0;
> > fieldSize = 4;
> > }
> > else if (loopIndex == 1)
> > {
> > offset = 4;
> > fieldSize = 9;
> > }
> > else
> > {
> > offset = 12;
> > fieldSize = 9;
> > }
> > fieldIndex = FrmGetObjectIndex (form, fieldID);
> > fieldPtr = (FieldType*) FrmGetObjectPtr (form, fieldIndex);
> > FldSetText (fieldPtr, details, offset, fieldSize);
> > FldSetUsable (fieldPtr, true);
> > FldDrawField (fieldPtr);
> > fieldID++;
> > }
> >
> >--
> >George R
> >
> >
> >
> >
> >--
> >For information on using the Palm Developer Forums, or to unsubscribe,
> >please see http://www.palmos.com/dev/tech/support/forums/
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/tech/support/forums/
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/