Solved

TStringList - Compare, update and Save

Posted on 2002-03-30
5
896 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

861 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

23 Experts available now in Live!

Get 1:1 Help Now