Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Find duplicates in Inifile

Posted on 2009-04-26
3
Medium Priority
?
364 Views
Last Modified: 2012-05-06
I got a inifile with this sections :

[Main]
Width = 2390
Hight = 2154

[Panel1]
left=50
right=45
width=690
height=1000

[Panel2]
left=785
right=45
width=1550
height=1000

[Panel3]
left=50
right=1105
width=690
height=1000

[Panel4]
left=785
right=1105
width=1550
height=1000

Is there a (fast) way to find out that section panel1 and panel3 got the same width and height and section  panel2 and panel4 got the same width and height and if so, then do something? The number of panels can differs from 1 to 20 or more. Only [Main] is unique and need to be read as well. The key values must be retrieved and used.

Thanks from a Newy
0
Comment
Question by:2meathome
3 Comments
 

Author Comment

by:2meathome
ID: 24235343
Points added
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 2000 total points
ID: 24238973
well to read them is easy, something like this should do what you need.


procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
  left_, right_, width_, height_: integer;
begin
  with TINIFile.Create('myfile.ini') do
  try
// read the "main" 
    width_ := ReadInteger('Main', 'width', -1);
    height_ := ReadInteger('Main', 'height', -1);
    // do something with the main width and height now...
 
// loop through and read the other panels
    i := 1;
    left_ := ReadInteger('Panel' + IntToStr(i), 'left', -1);
    while (left_ <> -1) do // use -1 as a flag for "no more panels..."
    begin
      right_ := ReadInteger('Panel' + IntToStr(i), 'right', -1);
      width_ := ReadInteger('Panel' + IntToStr(i), 'width', -1);
      height_ := ReadInteger('Panel' + IntToStr(i), 'height', -1);
      // check if another panel has the same width and height
      j := AnotherPanelHasSameValues(i, width_, height_);
      if (j <> -1) then
      begin
        // do something with panels "i" and "j"
      end
      else
      begin
        // do something with left, right, width and height now...
      end;
// get the next panel
      i := i _+ 1;
      left_ := ReadInteger('Panel' + IntToStr(i), 'left', -1);
    end;
  finally
    free; // the ini file
  end;  
 
 
function TForm1.AnotherPanelHasSameValues(OriginalPanelNumber, width_, height_: integer);
var
  i: integer;
  left_: integer;
begin
  result := -1
// loop through and read the other panels
  i := 1;    
  left_ := ReadInteger('Panel' + IntToStr(i), 'left', -1);
  while (result = -1) and (left_ <> -1) do // use -1 as a flag for "no more panels..."
  begin
    if (i <> OriginalPanelNumber) then
    begin // ignore the same panel number
      if (ReadInteger('Panel' + IntToStr(i), 'width', -1) = width_) and (ReadInteger('Panel' + IntToStr(i), 'height', -1) = height_) then
        result := i;
    end;
// get the next panel
    i := i _+ 1;
    left_ := ReadInteger('Panel' + IntToStr(i), 'left', -1);
  end;
end;

Open in new window

0
 
LVL 46

Expert Comment

by:aikimark
ID: 24263463
I would approach this by combining the width and height (integer) values to a floating point data type.  That way we can compare the floating point values for each of the panel sections with a nested loop.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

578 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