Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

TStringList - Compare, update and Save

Posted on 2002-03-30
5
Medium Priority
?
905 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 400 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline
Suggested Courses

610 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