Solved

TStrings.. How ?

Posted on 1998-04-30
6
429 Views
Last Modified: 2010-04-06
I want to create a TString object. How do I do that ?
0
Comment
Question by:Raptor062197
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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