[futurebasic] Re: [FB] [FB^3] Appearance Text Edit in FB^3

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2000 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Mon, 09 Oct 2000 12:55:40 +0200

Ken Shmidheiser wrote:

> This code is very rough-- no error checking and it crashes if the
> Text Edit Field string is too long-- but it does produce a genuine
> Appearance Manager Text Edit Field, in an Appearance-compliant color
> theme background, all within a standard FB^3 window.
>
> The most difficult part for me has been putting text into the Text
> Edit Field. Here is the C code snippet I tried to translate into FB^3
> to move a short text string:
>

<snip>

Hello Ken,

I found your buildTextEdit FN hard to follow, maybe you have complicated the code too much
and it is a bit confusing.
I think also that there are a few mistakes in it.
First, it is not a good idea to call editTextHandle a variable that you initialize as a
pointer.
In fact, I'm wondering where the info are stored when you write the following line:
editTextHandle&..str1$ = "Hello world! I am Appearance compliant."
Perhaps you made a typo or I failed to understand.
Moreover I think that when you request for a pointer or a handle via the appropriate Toolbox
calls you are also responsible of the disposing of the memory used. Therefore, you need to
have a DisposePtr call at the end of your FN otherwise it is guaranteed that you'll get a
memory leak in this demo.
I don't understand the use of the inner record. I believe you have defined it to get the size
of a string variable, so why not use the SIZEOF function instead?
A side note: I see in many snippets of code the following statements:
NewPtr _clear or NewHandle _clear
FB^3 has introduced two new Toolbox calls for that purpose:
NewPtrClear and NewHandleClear
I'm wondering why they are not so often used, is there any advantage in using the first form
except the compatibility with FBII?

I would suggest to you the following which seems to me easier to understand. With almost no
work you could pass any pascal string as a parameter, with a bit of work you could build a
function that accepts the address of a pascal string and/or a handle to a lengthy text:

CLEAR LOCAL MODE
LOCAL FN buildTextEdit
DIM err        AS LONG
DIM textEditH  AS HANDLE
DIM textH      AS HANDLE
DIM WndPtr     AS windowPtr
DIM theStr     AS STR255
DIM myRect     AS RECT


WndPtr = WINDOW(_wndPointer) : IF WndPtr = _nil THEN EXIT FN
textH  = FN NewHandle(0)    : IF textH = _nil  THEN EXIT FN

theStr = "Hello world! I am Appearance compliant."

LONG IF FN PtrAndHand(@theStr[1],textH,theStr[0]) = _noErr
err           = FN SetThemeWindowBackground(WndPtr,_kThemeActiveDialogBackgroundBrush,_true)
myRect.left   = 20
myRect.top    = 20
myRect.right  = 380
myRect.bottom = 180
textEditH     = FN NewControl(WndPtr,myRect,"",_true,0,0,0,_kControlEditTextProc,2)
err           = FN SetControlData(textEditH,0,_kControlEditTextTextTag,FN
GetHandleSize(textH),[textH])
END IF
DisposeHandle(textH)
END FN

Cheers

Alain