Solved

Assigning TRichedit.Lines to a TStrings variable

Posted on 2000-05-15
8
370 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
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
code issue 8 129
Delphi Yen format 3 34
Installshield for Embarcadero EX 10.1 Berlin 4 40
Why  'Host Connection unavailable/Socket Error #113 No route to host' 6 41
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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