TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
Adding Strings to Memo Variables
 
   
 Posted: 12 June 2003
 
   
 
 Applies to: Paradox 5.0 and later
 
   
 
Audience: Beginner
 
       
   

Question: I have a Memo variable. How do I add string (text) values to it?

Typecast the string value as a Memo and then append it to your variable, as shown in the following code sample:

var
   MyMemo  Memo
endVar

method pushButton(var eventInfo Event)
var
   str  String
endVar

   ; Example only; don't use view() in production apps.
   str.View( "Add Item to Memo" )

   if not MyMemo.isAssigned() then
      MyMemo = Memo( str )
   else
      MyMemo = MyMemo + Memo( str )
   endIf

   ; fldMemo is an unbound field object on the form
   fldMemo.Value = MyMemo

endMethod

As you review this code, please keep the following points in mind:

  • The code assumes you've created a form containing a button and an unbound field object named fldMemo.

  • The MyMemo variable is declared as a static variable; that it, MyMemo retains its value after the pushButton() event ends. This can be a very useful technique for creating counters, iterators, and so on.

  • The isAssigned() test is needed because MyMemo is not assigned a value until the button is clicked at least once. You can leave this out if you're certain your Memo variable contains a value before you add values to it.

    Note:  In our applications, we prefer to use sanity checks like this to reduce the number of unusual errors presented to our users. While checks like this aren't entirely necessary, we have noticed that such attention to detail reduces the number of support calls we field. (As always, your mileage may vary.)

  • The "trick" in this example comes lies in the use of Memo( str ), which typecasts (converts) the String value to a Memo value. Once you have a memo value, you can assign or append it to Memo variables, as with any other variable type.

  • While this example uses the view() method, we strongly discourage this in production applications.

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 14 June 2003

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]