Solved

Assigning TRichedit.Lines to a TStrings variable

Posted on 2000-05-15
8
373 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
[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
8 Comments
 
LVL 15

Expert Comment

by:simonet
ID: 2812063
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
ID: 2812138
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
ID: 2812191
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
Industry Leaders: 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 2

Accepted Solution

by:
EdHillmann earned 100 total points
ID: 2812450
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
 

Expert Comment

by:LuK
ID: 2813891
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
ID: 2836596
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
ID: 2840571
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
ID: 2851589
Comment accepted as answer
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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 video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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