VSSPELL Spelling Component Experiences
Firstly, please let me thank so many of you for having downloaded the VSSPELL spelling component detailed in our newsletter from last week.
It seems that many of you have been waiting for such a compact and easy-to-use spell checking component, as there have been several hundred downloads. Now, as part of our commitment to supporting the ever-growing TX Text Control Community, we would like to ask you about your experience of VSSPELL and how far you have come with integrating it in your TX Text Control software product.
TX Top Tip: Dealing with Databases, Part 2
This weeks tip is not really a tip - we are just revisiting the example of the last week. It showed how to load data from a database into the TX without using it as a bound control. As I am sure that you remember, the trick was to use the LoadFromMemory and SaveToMemory methods to load a byte array that contains formatted data (or unformatted such as a simple string) into TX or save the contents to such a byte array.
VB provides a simple method to do the conversion from a string to a byte array and vice versa, but Delphi users or VC++ users have to deal with the Variant data type and most users don't know how to do that. So, let's take a look at how you so this:
procedure TForm1.Button1Click(Sender: TObject);
strData := 'Test text';
nLen := Length(strData);
// copy text into byte array
vData := VarArrayCreate([0, nLen], varByte);
pPtr := VarArrayLock(vData);
TXTextControl1.LoadFromMemory(vData, 1, False);
VarClear(vData); // release data
CString csTemp = "Test text";
VARIANT var1, var2, var3;
// create array
bound.lLbound = 0;
bound.cElements = csTemp.GetLength() + 1; // inclusive '\0'
var1.parray = SafeArrayCreate(VT_UI1, 1, &bound);
var1.vt = VT_UI1 | VT_ARRAY;
// copy data into array
CopyMemory(lpData, (LPCTSTR) csTemp, bound.cElements);
var2.intVal = 5; // RTF format
var2.vt = VT_I4;
var3.boolVal = true; // replace selection
var3.vt = VT_BOOL;
m_TxTranslate.LoadFromMemory(var1, var2, var3);
The examples above load the string "Test text" directly into the TX. We could equally use a text format that supports formatting here, such as HTML and RTF. The only thing you need to change is the format parameter of the LoadFromMemory method.
In Delphi you can use the VarArrayCreate method to create the Variant. Then the Variant needs to be locked. This returns a pointer to the internal byte array and then StrCopy can be used to copy the string to the array. The second and third parameter of the LoadFromMemory are also prototyped as Variants, but you can simply treat them as normal variables and Delphi performs the conversion for you.
In VC++ the procedure is similar. First of all, the Variant has to be initialized. Then the array is created with SafeArrayCreate. Afterwards, the Variant is locked with SafeArrayAccessData and the string is copied to the array with CopyMemory. VC++ expects the second and third parameter to be Variants as well. This means you must not forget to set up two more Variants.
After you are done with the Variants, you need to free the allocated memory. This is done with VarClear(Delphi) resp. VariantClear(VC++).
Now it should be fairly easy to use the LoadFromMemory method with a database in your preferred language.d language.
Free Advertising For Your TX Text Control Application
For you long-time TX users, I guess you are getting fed up of reading about this, but as there are more than 1000 new TX Text Control Newsletters readers per month, I do have to repeat this about once a month. Please do not despair!
So, to all you new to TX Text Control: We would like to give you the opportunity of free advertising for your TX Text Control product on our web site.
All we ask is that you send us your text, as well as a few screenshots detailing how TX Text Control was part of the solution and within about two days of receiving this material, we will add your story, along with your logo and your name to our sample application pages.
So far we have had a terrific response to our request for sample TX Text Control applications from the hard core TX users, but I am know there are thousands of other TX apps out there - all of which should be added to the sample application page. Just send me a short text, explaining how you used TX Text Control to implement your application and you get free advertising for this product on our web site. You've got nothing to lose!
The Newsletter Team