Solved

TStringList - Compare, update and Save

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

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