Solved

Assigning TRichedit.Lines to a TStrings variable

Posted on 2000-05-15
8
366 Views
Last Modified: 2010-04-04
Take a look at this code.
ChatWnd is a TRichEdit.

Var
  Server : TStrings;

Procedure DoIt;
Var
  P : Pointer;
Begin
 Server := TStringList.Create;
 P := @ChatWnd.Lines;
 TStrings(P^) := Server;
End;

This makes the "Server" text go into Both Server and ChatWnd.Lines but the
painting or something of ChatWnd seems to never occur anymore,
I am missing something essential.


Any ideas?


0
Comment
Question by:raidos
8 Comments
 
LVL 15

Expert Comment

by:simonet
Comment Utility
I don't get it. What do you want to do?

>I am missing something essential.

I think so. The ^ and @ operators are entirely unnecessary there, because all objects are pointers.

Assigning an object to an untyped pointer goes like this:

P := pointer(ChatWnd.lines);


What I don't get it:

in the second line, you are assigning a value to P. Then, on the second line, you again assign a new value to P, losing the previously assigned value.

What exactly are you trying to achieve?

If all you want is to copy ChatWnd.lines to Server, you can do:

Server := TStringList.create;
Server.assign(ChatWnd.lines);


That will do the job, if that's what you want.

Alex

0
 
LVL 1

Expert Comment

by:xsoft
Comment Utility
If Alex's answer is not what you are looking for, then please tell us what the problem is.
0
 
LVL 3

Author Comment

by:raidos
Comment Utility
Ok, This is what i want to do

I have an array of TStrings that will contain text,
when i have Activate one of the TStrings then The text previously sent and Sent while TStrings object is active should come up in The RichEdit

IE:
 Something like this:
 Server := TStringList.create;
 ChatWnd.Lines.assign(Server);

 With autoupdate of
   ChatWnd.Lines from Server

Sorry about the mess...
I have to little experience to try and do something like this.

Bahhh...
I hope this will clarify a few of my thoughts and intentions.
0
 
LVL 2

Accepted Solution

by:
EdHillmann earned 100 total points
Comment Utility
I think I'm tracking what you want to do.... something like this...

var
  //I've defined the array of as dynamic... do you plan on a fixed-size array, or have unlimited StringLists in the array?
  aTextArray: array of TStrings;

....

{
Procedure to populate the RichEdit control from the Stringlist in the array.  Use the parameter passed into the function as the position in the array.
}
procedure UseStringHistory(i: integer; pRichEdit: TRichEdit)
var
  vStringList: TStrings;
begin
  vStringList := aTextArray[i;

  pRichEdit.Lines.Assign(vStringList);
end;

{
Procedure to update the String Array from the RichEdit control.  Will also maintain the size of the array as well as ensure that a string list exists in the position...
}
procedure UpdateStringHistory(i: integer; pRichEdit: TRichEdit);
var
  vList: TStrings;
begin
  if (i >= Length(aTextArray)) then
    SetLength(aTextArray, i + i);

  vList := aTextArray[i];
  if not assigned(vList) then begin
    vList := TStringList.Create;
    aTextArray[i] := vList;
  end;

  vList.Assign(pRichEdit.Lines);
end;

You also want to make sure that the array of stringlists gets freed up at the appropriate time.  You could do it when the form is destroyed if they end up being private variables on the form (probably the safest route).  Or on the finalization of the unit containing the array. if it is to remain a implementation variable.  Wherever it sits, it can look like...

var
  i: integer;
begin
  for i := Length(aTextArray) - 1 do begin
    if Assigned(aTextArray[i]) then
      aTextArray[i].Free;
  end;
end;

Hope this helps,
Ed
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Expert Comment

by:LuK
Comment Utility
Just do it like you had descibed it in your first question, but use
TStrings(p^) := Server.STRINGS[0];
instead of
TStrings(p^) := Server;

0
 
LVL 3

Author Comment

by:raidos
Comment Utility
I have just returned from a trip, i will evaluate your comments tonight.

sorry about the delay(zzzzzzzZZZZzz);


//raidos
0
 
LVL 3

Author Comment

by:raidos
Comment Utility
Thank you for your comments,
I think i will have to go with Eds comment although it's not exactly what I asked for.

If any of you disagree with that, please respond before 10 AM(GMT) tomorrow.

Thanks again

//raidos

0
 
LVL 3

Author Comment

by:raidos
Comment Utility
Comment accepted as answer
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now