Solved

TStringList - Compare, update and Save

Posted on 2002-03-30
5
900 Views
Last Modified: 2009-07-29
I have a procedure that will return 3 Strings in the form of:

FunctionName.Returns(Parameter1.Lines, Parameter2.lines, Parameter3.lines);

I am placing these strings in a TMemo for Display on a timer fire event. However, if the strings are identical they still update. I dont want to update my TMemo until they are different regardless of the timer event.

So, I am looking for some code that will take these original three parameters, compare them to the previous 3 Strings, and if they are unique add them to a TMemo so that I have a history of all the parameters in the Memo for saving or printing.
(Parameters 1 and 2 can be NIl, so the test should also accomidate a nil return.)
0
Comment
Question by:quantum2
[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
  • 3
5 Comments
 

Expert Comment

by:juliusrai
ID: 6910030
{in the following coding i am assuming that 'one' and 'two' values are already in the memo list and the four is the new one.}

{this procedure checks if the passed string is unique in the list and adds it}
procedure TForm1.Replacestring(str: string);
var
  int: integer;
  found: boolean;
begin

  {loop untill it reaches to the last line of the memo}
  for int := 0 to memo1.Lines.Count do
  begin
    {match string}
    if memo1.Lines[int] = str then
      {if match}
      begin
      found:= true;
      {come out from the loop}
      exit;
      end
    else
      found:= False
  end;
  {if new string then add}
  if not found then
    memo1.Lines.Add(str);

end;

{passing values}
procedure TForm1.Button2Click(Sender: TObject);
begin
  checkstring('one', 'two', 'four');
end;

{spliting variables and passing one by one}
procedure TForm1.checkstring(str1: string; str2: string; str3: string);
begin
  if str1 <> '' then
    Replacestring(str1);
  if str1 <> '' then
    Replacestring(str2);
  if str1 <> '' then
    Replacestring(str3);

end;
0
 

Expert Comment

by:juliusrai
ID: 6910033
good luck
julius
0
 

Expert Comment

by:juliusrai
ID: 6910080
good luck
julius
0
 

Accepted Solution

by:
jonnyfive earned 100 total points
ID: 6915520
Hi quantum2...

I would suggest a slightly more ellegant method. Derive your own StringList from TStringList and add a public property "IsDirty" of type boolean. Now you override every method that can potentialy change the value of the StringList (i.e. Add, SetText, LoadFromFile, etc.) and set the IsDirty "flag" to true before calling the inherited methods. If you now check the IsDirty flag, you reset it to false.

This way you don't need to go through the whole StringList for every test.

Hope it helps, Jonny...
0
 
LVL 1

Author Comment

by:quantum2
ID: 6942352
Thanks everyone. I really apprecaite the help. I am going to give this one a shot and see what I come up with.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 127
Working with hours 3 75
Is anyone willing to have a look through this code and help debug? 25 93
Delphi Seattle StructureView color 1 22
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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

696 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