Solved

TStrings.. How ?

Posted on 1998-04-30
6
431 Views
Last Modified: 2010-04-06
I want to create a TString object. How do I do that ?
0
Comment
Question by:Raptor062197
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
pjdb earned 10 total points
ID: 1340001
TString? I assume you mean a list of string so that's a TStringList.

Use the following :

Procedure MyTest;
Var
  MyStrings:TStringList;
procedure TForm1.Button3Click(Sender: TObject);
Begin
  MyStrings:=TStringList.Create;  {Create the TStrings object}
{Do your job}
{for example :}
  MyStrings.Clear;
  MyStrings.add('test');

  MyStrings.Free; {destroy the TStrings object and free memory}
End;

JDB
0
 
LVL 1

Expert Comment

by:Greedy
ID: 1340002
I will assume by TString you really mean TStingList???
useing a string is as simple as doing
Var
  MyString : string

MyString := 'My Big Ass String';

To use a String List you need to do a bit more

Var
  MyStringList : TStringList;

To Assign a value do this

MyString := TStringList.Create;
MyString.Add('My Big Ass String');

Then When you are done with it do a
MyString.Free;

Hope this is what you needed.



0
 

Author Comment

by:Raptor062197
ID: 1340003
I mean TStrings. (I want to make a text for a RichEdit dynamically and store it to the RichEdit.Lines property)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:pjdb
ID: 1340004
As far as i know, you need to use a TStringList and when you want to put the strings to the TRichEdit, then use RichEdit1.Strings:=MyStrings;
You can't use a TStrings object directly (In Delphi help it is written : "To maintain a list of strings outside of a control, use a string list object (TStringList).")

JDB
0
 
LVL 1

Expert Comment

by:Greedy
ID: 1340005
what I think you really mean it a TStringStream this is what one normaly uses to get the Rich text proporties out of a RTFEdit.  This is because if you say
var
 MyFattyString : string
begin
  MyFattyString := RTFEdit1.Text
end

MyFattyString is just a string of text with none of the formating stuff in it.

so I think you want to do something like this

var
  MyStream : TStringStream;
begin
  MyStream := TStringStream.Create('');
  RtfTextEdit.SaveToStream(MyStream);
  MyDB.FieldByName('CPNote').AsString := MyStream.DataString;
  MyStream.Free;
end;

then when you want the text to go back to the RTF you can use it as a plane old string then
    RtfTextEdit.Text := MyDB.FieldByName('CPNote').AsString;


Hope this is what you need because you'll have to put the points to 100 before I come back in here :)

0
 

Author Comment

by:Raptor062197
ID: 1340006
var T : TStringList;

  T:= TStringlist.Create;
  T.clear;
  T.add('Hallo');
  T.add('Test');
  Form1.RichEdit1.text:= T.text;

That worked for me. I wanted to create some text and let it display in a RichEdit.
The error I was getting was because I did the above stuff in the onCreate handler of Form2.
Now that I put it into Form, it works
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question