Solved

TStringList - Compare, update and Save

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

14 Experts available now in Live!

Get 1:1 Help Now