Link to home
Start Free TrialLog in
Avatar of Jai Sewell
Jai Sewell

asked on

Is anyone willing to have a look through this code and help debug?

Been meaning to share this for a few years and ask for help with it, i know for certain there are a couple bugs in it, so any help would be advantageous...

procedure TMain.DoIt;
var X, Y, Z: integer;
Tmp, Cpy: ansistring;
pRange: xRange;
Canc: boolean;
 function GetIndex(start: boolean): integer;
 var L: integer;
 Math: Extended;
 begin
 L := 0;
 result := 0;
 Math := 0;
 while (L <= Notes.Lines.Count -1) and (nCanc) do
  begin
   Math := Math +Length(Notes.Lines.Strings[L]) +2;
   if Math < 0 then Math := 0;
   if start then
    begin
     if Math >= Notes.SelStart then
      begin
       if Notes.SelStart = Math then L := L+1;
       result := L;
       L := Notes.Lines.Count +2;
      end
    end
   else
    begin
     if Math >= Notes.SelStart +Notes.SelLength then
      begin
       result := L;
       L := Notes.Lines.Count +2;
      end
    end;
    Inc(L);
  end
 end;
begin
with nOpts do
 begin
  X := 0;
  Tmp := '';
  nCanc := true;
  if Opt1.Checked then // add characters to beginning
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := AddChar1.Text +Notes.Lines.Strings[X];
        if Chk1.Checked then
         begin
          if Chk2.Checked then Tmp := Tmp +ReverseString(AddChar1.Text)
          else Tmp := Tmp +AddChar1.Text;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := AddChar1.Text +Notes.Lines.Strings[X];
        if Chk1.Checked then
         begin
          if Chk2.Checked then Tmp := Tmp +ReverseString(AddChar1.Text)
          else Tmp := Tmp +AddChar1.Text;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt2.Checked then // add characters to end
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X] +AddChar2.Text;
        if Chk3.Checked then
         begin
          if Chk4.Checked then Tmp := ReverseString(AddChar2.Text) +Tmp
          else Tmp := AddChar2.Text +Tmp;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X] +AddChar2.Text;
        if Chk3.Checked then
         begin
          if Chk4.Checked then Tmp := ReverseString(AddChar2.Text) +Tmp
          else Tmp := AddChar2.Text +Tmp;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt3.Checked then //add spaces to beginning of lines
   begin
    if Notes.SelLength < 1 then
     begin
      for X := 1 to AddVal.Value do Tmp := Tmp + ' ';
      X := 0;
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Notes.Lines.Strings[X] := Tmp +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := X;
        Application.ProcessMessages;
       end
     end
    else
     begin
      for X := 1 to AddVal.Value do Tmp := Tmp + ' ';
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Notes.Lines.Strings[X] := Tmp +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
   end
  else if Opt4.Checked then // remove spaces from beginning of line
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk5.Checked then Delete(Tmp, 1, TakeVal1.Value)
        else
         begin
          if trim(Copy(Tmp, 1, TakeVal1.Value)) = '' then Delete(Tmp, 1, TakeVal1.Value)
          else
           begin
            while Copy(Tmp, 1, 1) = ' ' do Delete(Tmp, 1, 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk5.Checked then Delete(Tmp, 1, TakeVal1.Value)
        else
         begin
          if trim(Copy(Tmp, 1, TakeVal1.Value)) = '' then Delete(Tmp, 1, TakeVal1.Value)
          else
           begin
            while Copy(Tmp, 1, 1) = ' ' do Delete(Tmp, 1, 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt5.Checked then // remove spaces from end of lines
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk6.Checked then Tmp := Copy(Tmp, 1, Length(Tmp) -TakeVal2.Value)
        else
         begin
          if trim(Copy(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)) = '' then Delete(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)
          else
           begin
            while Copy(Tmp, Length(Tmp), 1) = ' ' do Delete(Tmp, Length(Tmp), 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk6.Checked then Tmp := Copy(Tmp, 1, Length(Tmp) -TakeVal2.Value)
        else
         begin
          if trim(Copy(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)) = '' then Delete(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)
          else
           begin
            while Copy(Tmp, Length(Tmp), 1) = ' ' do Delete(Tmp, Length(Tmp), 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt6.Checked then // convert all too...
   begin
    if Conv.ItemIndex = 0 then // lowercase
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := LowerCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := LowerCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 1 then //uppercase
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UpperCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UpperCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 2 then /ASCII values
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Y := 1;
          Cpy := '';
          Tmp := Notes.Lines.Strings[X];
          while (Y <= Length(Tmp)) and (nCanc) do
           begin
            Cpy := Cpy +IntToStr(Ord(Tmp[Y])) + ', ';
            Inc(Y);
           end;
           Cpy := trim(Cpy);
           if Copy(Cpy, Length(Cpy), 1) = ',' then Delete(Cpy, Length(Cpy), 1);
           Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := X;
           Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Z := 1;
          Cpy := '';
          Tmp := Notes.Lines.Strings[X];
          while (Z <= Length(Tmp)) and (nCanc) do
           begin
            Cpy := Cpy +IntToStr(Ord(Tmp[Z])) + ', ';
            Inc(Z);
           end;
           Cpy := trim(Cpy);
           if Copy(Cpy, Length(Cpy), 1) = ',' then Delete(Cpy, Length(Cpy), 1);
           Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 3 then //hexadecimal
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Tmp := Hex2Bin(Notes.Lines.Strings[X]);
          Tmp := Bin2Hex(Tmp);
          Notes.Lines.Strings[X] := Tmp;
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end;
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Tmp := Hex2Bin(Notes.Lines.Strings[X]);
          Tmp := Bin2Hex(Tmp);
          Notes.Lines.Strings[X] := Tmp;
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 4 then //Binary
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := Hex2Bin(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := Hex2Bin(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 5 then //Javascript escape
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlEncode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlEncode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 6 then //Javascript unescape
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlDecode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlDecode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else //String (clear text characters)
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        Cpy := '';
        if Notes.Lines.Count > 0 then pBar.MaxValue := Length(Notes.Lines.Text);
        while (X <= pBar.MaxValue) and (nCanc) do
         begin
          Tmp := Notes.Lines.Strings[X];
          if IsBinary(Tmp) then
           begin
            Tmp := Bin2Hex(Tmp);
            Cpy := StringOfChar('0', Length(Tmp) div 2);
            HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
           end
          else
           begin
            Canc := true;
            Cpy := '';
            Z := 0;
            while (Length(Tmp) > 0) and (nCanc) do
             begin
              if Pos(',', Tmp) > 0 then
               begin
                if isint(Copy(Tmp, 1, Pos(',', Tmp) -1), false, false) then
                 begin
                  if (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) < 256) and (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) > 0) then
                   begin
                    Cpy := Cpy +Chr(StrToInt(Copy(Tmp, 1, Pos(',', Tmp) -1)));
                    Canc := false;
                    Z := 1;
                   end
                  else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                 end
                else
                 begin
                  MessageDlg('Data is not numerical and is not an ASCII code!.', mtWarning, [mbok], 0);
                  nCanc := not nCanc;
                 end;
                 Delete(Tmp, 1, Pos(',', Tmp) +1);
               end
              else
               begin
                if isint(Tmp, false, false) then
                 begin
                  if (StrToFloat(Tmp) < 100) and (Canc) then
                   begin
                    if MessageDlg('Unable to determine data type!, is the data ASCII?', mtConfirmation, [mbyes, mbno], 0) = mryes then Z := 1;
                   end
                  else Z := 1;
                  if StrToFloat(Tmp) > 255 then Z := 0;
                  if Z = 0 then // hexadecimal
                   begin
                    Cpy := StringOfChar('0', Length(Tmp) div 2);
                    HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                   end
                  else // ASCII
                   begin
                    if (StrToFloat(Tmp) < 256) and (StrToFloat(Tmp) > 0) then Cpy := Cpy +Chr(StrToInt(Tmp))
                    else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                   end
                 end
                else
                 begin
                  Cpy := StringOfChar('0', Length(Tmp) div 2);
                  HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                 end;
                 Tmp := '';
               end
             end
           end;
           if nCanc = true then Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := X;
           Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Tmp := Notes.Lines.Strings[X];
          if IsBinary(Tmp) then
           begin
            Tmp := Bin2Hex(Tmp);
            Cpy := StringOfChar('0', Length(Tmp) div 2);
            HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
           end
          else
           begin
            Canc := true;
            Cpy := '';
            Z := 0;
            while (Length(Tmp) > 0) and (nCanc) do
             begin
              if Pos(',', Tmp) > 0 then
               begin
                if isint(Copy(Tmp, 1, Pos(',', Tmp) -1), false, false) then
                 begin
                  if (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) < 256) and (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) > 0) then
                   begin
                    Cpy := Cpy +Chr(StrToInt(Copy(Tmp, 1, Pos(',', Tmp) -1)));
                    Canc := false;
                    Z := 1;
                   end
                  else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                 end
                else MessageDlg('Data is not numerical and is not an ASCII code!.', mtWarning, [mbok], 0);
                Delete(Tmp, 1, Pos(',', Tmp) +1);
               end
              else
               begin
                if isint(Tmp, false, false) then
                 begin
                  if (StrToFloat(Tmp) < 100) and (Canc) then
                   begin
                    if MessageDlg('Unable to determine data type!, is the data ASCII?', mtConfirmation, [mbyes, mbno], 0) = mryes then Z := 1;
                   end
                  else Z := 1;
                  if StrToFloat(Tmp) > 255 then Z := 0;
                  if Z = 0 then // hexadecimal
                   begin
                    Cpy := StringOfChar('0', Length(Tmp) div 2);
                    HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                   end
                  else // ASCII
                   begin
                    if (StrToFloat(Tmp) < 256) and (StrToFloat(Tmp) > 0) then Cpy := Cpy +Chr(StrToInt(Tmp))
                    else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                   end
                 end
                else
                 begin
                  Cpy := StringOfChar('0', Length(Tmp) div 2);
                  HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                 end;
                 Tmp := '';
               end
             end
           end;
           Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end
       end
     end
   end
  else if Opt7.Checked then //generate random characters
   begin
    pRange[0] := 1;
    pRange[1] := 255;
    pBar.MaxValue := Seed.Value -1;
    for X := 1 to Seed.Value do
     begin
      Tmp := Tmp +Chr(iRandom(pRange));
      pBar.Progress := pBar.Progress +1;
     end;
     if Chk7.Checked then Notes.Lines.Add(Tmp)
     else Notes.Lines.Text := Notes.Lines.Text +Tmp;
   end
  else if Opt8.Checked then // split/break line after n (number of) characters
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if trim(Notes.Lines.Strings[X]) <> '' then
         begin
          with Notes.Lines do Strings[X] := Copy(Strings[X], 1, SplitVal.Value) + #13#10 + Copy(Strings[X], SplitVal.Value +1, Length(Strings[X]));
         end;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end;
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if trim(Notes.Lines.Strings[X]) <> '' then
         begin
          with Notes.Lines do Strings[X] := Copy(Strings[X], 1, SplitVal.Value) + #13#10 + Copy(Strings[X], SplitVal.Value +1, Length(Strings[X]));
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt9.Checked then // remove only blank lines
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if trim(Notes.Lines.Strings[X]) = '' then
         begin
          Notes.Lines.Delete(X);
          if X < Notes.Lines.Count -1 then Dec(X)
          else nCanc := false
         end;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end;
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if trim(Notes.Lines.Strings[X]) = '' then
         begin
          Dec(Y);
          Notes.Lines.Delete(X);
          if X < Notes.Lines.Count -1 then Dec(X)
          else nCanc := false
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt10.Checked then // add lines to beginning
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := AddLines.Value;
      while (X <= AddLines.Value -1) and (nCanc) do
       begin
        Notes.Lines.Insert(0, '');
        Inc(X);
        pBar.Progress := X;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := 0;
      Y := GetIndex(true);
      pBar.MaxValue := AddLines.Value;
      while (X <= AddLines.Value -1) and (nCanc) do
       begin
        Notes.Lines.Insert(Y, '');
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end 
   end
  else if Opt11.Checked then // remove lines from beginning 
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := RmvLines.Value;
      while (X <= RmvLines.Value -1) and (nCanc) do
       begin
        if Chk8.Checked then Notes.Lines.Delete(0)
        else if Notes.Lines.Strings[0] = '' then Notes.Lines.Delete(0);
        Inc(X);
        pBar.Progress := X;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := 0;
      Y := GetIndex(true);
      pBar.MaxValue := RmvLines.Value;
      while (X <= RmvLines.Value -1) and (nCanc) do
       begin
        if Chk8.Checked then Notes.Lines.Delete(Y -1)
        else
         begin
          if Y > 0 then
           begin
            if Notes.Lines.Strings[Y -1] = '' then Notes.Lines.Delete(Y -1)
            else
             begin
              if Y > 1 then Z := Y -1
              else Z := 0;
              while (Notes.Lines.Strings[Z] <> '') and (Z > 0) do Dec(Z);
              if Z > 0 then Notes.Lines.Delete(Z);
             end
           end
         end;
         Dec(Y);
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt12.Checked then // find and replace
   begin
    if Notes.SelLength < 1 then
     begin
      Y := 0;
      while (Y >= 0) and (nCanc) do
       begin
        if (Chk9.Checked) and (not Chk10.Checked) then Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, [stMatchCase])
        else if (Chk9.Checked) and (Chk10.Checked) then Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, [stMatchCase, stWholeWord])
        else if (not Chk9.Checked) and (Chk10.Checked) then Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, [stWholeWord])
        else Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, []);
        if Y >= 0 then
         begin
          Notes.SelStart := Y;
          Notes.SelLength := FndText.GetTextLen;
          Notes.SelText := RplText.Text;
         end
       end
     end
    else
     begin
      X := GetIndex(true);
      if X > 0 then Y := Length(Notes.Lines.Strings[X -1])
      else Y := 0;
      X := 0;
      Z := GetIndex(false);
      while (X >= 0) and (nCanc) do
       begin
        if (Chk9.Checked) and (not Chk10.Checked) then X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, [stMatchCase])
        else if (Chk9.Checked) and (Chk10.Checked) then X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, [stMatchCase, stWholeWord])
        else if (not Chk9.Checked) and (Chk10.Checked) then X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, [stWholeWord])
        else X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, []);
        if X >= 0 then
         begin
          Notes.SelStart := X;
          Notes.SelLength := FndText.GetTextLen;
          if GetIndex(true) > Z then X := -1
          else Notes.SelText := RplText.Text;
         end;
         Y := X;
       end
     end
   end
  else if Opt13.Checked then // split lines after characters
   begin
    if Notes.SelLength < 1 then
     begin
      Y := 1;
      X := Notes.FindText(SpltTxt.Text, Y, Notes.GetTextLen, [stMatchCase]);
      while X > 0 do
       begin
        if Chk12.Checked then
         begin
          if (X > 0) and (Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, 1) <> #13) then Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
         end
        else Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
        Y := X +SpltTxt.GetTextLen;
        X := Notes.FindText(SpltTxt.Text, Y, Notes.GetTextLen -X, [stMatchCase]);
        Application.ProcessMessages;
        if nCanc = false then X := -1;
       end
     end
    else
     begin
      Y := Notes.SelStart;
      Z := Notes.SelLength;
      Tmp := IntToStr(Y +Z);
      X := Notes.FindText(SpltTxt.Text, Y, Z, [stMatchCase]);
      Cpy := '0';
      while X > 0 do
       begin
         if Y >= StrToInt(Tmp) then X := -1
         else X := Notes.FindText(SpltTxt.Text, Y, Z, [stMatchCase]);
         if X > 0 then
          begin
           if Chk12.Checked then
            begin
             if Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, 1) <> #13 then
              begin
               Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
               Z := Z +Length(#13#10);
               Tmp := IntToStr(StrToInt(Tmp) +Length(#13#10));
              end
            end
           else
            begin
             Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
             Z := Z +Length(#13#10);
             Tmp := IntToStr(StrToInt(Tmp) +Length(#13#10));
            end;
            while trim(Notes.Lines.Text[(X + StrToInt(Cpy)) +(SpltTxt.GetTextLen +Length(#13#10))]) = '' do Cpy := IntToStr(StrToInt(Cpy) +1);
            Y := (X + StrToInt(Cpy)) +(SpltTxt.GetTextLen +Length(#13#10));
          end;
          if nCanc = false then X := -1;
          Application.ProcessMessages;
       end
     end
   end
  else if Opt14.Checked then // split lines before characters
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      Y := 0;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Inc(Y);
        if Chk11.Checked then Notes.Lines.Strings[X] := LeadChars.Text + IntToStr(Y) +Notes.Lines.Strings[X]
        else Notes.Lines.Strings[X] := IntToStr(Y) +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
    else
     begin
      Y := 0;
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        Inc(Y);
        if Chk11.Checked then Notes.Lines.Strings[X] := LeadChars.Text + IntToStr(Y) +Notes.Lines.Strings[X]
        else Notes.Lines.Strings[X] := IntToStr(Y) +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
   end
  else if Opt15.Checked then // incremental number insertion (line count)
   begin
    if Notes.SelLength < 1 then
     begin
      Y := 1;
      X := Notes.FindText(SpltTxt2.Text, Y, Notes.GetTextLen, [stMatchCase]);
      while X > 0 do
       begin
        Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X) + #13#10 + Copy(Notes.Lines.Text, X +1, Notes.GetTextLen -(X +1));
        Y := X +(SpltTxt2.GetTextLen +2);
        X := Notes.FindText(SpltTxt2.Text, Y, Notes.GetTextLen -X, [stMatchCase]);
        Application.ProcessMessages;
        if nCanc = false then X := -1;
       end
     end
    else
     begin
      Y := Notes.SelStart;
      Z := Notes.SelLength;
      Tmp := IntToStr(Y +Z);
      X := Notes.FindText(SpltTxt2.Text, Y, Z, [stMatchCase]);
      Cpy := '0';
      while X > 0 do
       begin
         if Y >= StrToInt(Tmp) then X := -1
         else X := Notes.FindText(SpltTxt2.Text, Y, Z, [stMatchCase]);
         if X > 0 then
          begin
           Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X) + #13#10 + Copy(Notes.Lines.Text, X +1, Notes.GetTextLen -(X +1));
           Z := Z +Length(#13#10);
           Tmp := IntToStr(StrToInt(Tmp) +Length(#13#10));
           while trim(Notes.Lines.Text[(X + StrToInt(Cpy)) +((SpltTxt2.GetTextLen +1) +Length(#13#10))]) = '' do Cpy := IntToStr(StrToInt(Cpy) +1);
           Y := (X + StrToInt(Cpy)) +((SpltTxt2.GetTextLen +2) +Length(#13#10));
          end;
          if nCanc = false then X := -1;
          Application.ProcessMessages;
       end
     end
   end
  else if Opt16.Checked then // remove every second line
   begin
    if Notes.SelLength < 1 then
     begin
      X := 1; // counter
      Y := 0; // loop index
      pBar.MaxValue := Notes.Lines.Count -1;
      while (Y <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if X = LineCount.Value then
         begin
          X := 1;
          Notes.Lines.Delete(Y);
          pBar.MaxValue := Notes.Lines.Count -1;
         end;
         Inc(X);
         Inc(Y);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := 1; // counter
      Y := GetIndex(true); // LOOP INDEX
      Z := GetIndex(false); // end loop
      pBar.MaxValue := Z;
      while (Y <= Z) and (nCanc) do
       begin
        if X = LineCount.Value then
         begin
          X := 1;
          Notes.Lines.Delete(Y);
          Z := Z -1;
          pBar.MaxValue := Notes.Lines.Count -1;
         end;
         Inc(X);
         Inc(Y);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt17.Checked then // remove lines that do not contain characters
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if Pos(KeepChars.Text, Notes.Lines.Strings[X]) <= 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        if Pos(KeepChars.Text, Notes.Lines.Strings[X]) <= 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
          Z := Z -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
       end
     end
   end
  else if Opt18.Checked then // remove lines that contain characters
   begin
    if Notes.SelLength < 1 then
     begin
      X := 1;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if Pos(RmvChars.Text, Notes.Lines.Strings[X]) > 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        if Pos(RmvChars.Text, Notes.Lines.Strings[X]) > 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
   end
  else if Opt19.Checked then  // remove duplicate lines
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := (Notes.Lines.Count -1) *2;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := X +1;
        while (Y <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Cpy := Notes.Lines.Strings[Y];
          if trim(Cpy) = trim(Tmp) then
           begin
            Notes.Lines.Delete(Y);
            pBar.MaxValue := Notes.Lines.Count -1;
            Y := Y -1;
           end;
           Inc(Y);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z *2;
      while (X <= Z) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := X +1;
        while (Y <= Z) and (nCanc) do
         begin
          Cpy := Notes.Lines.Strings[Y];
          if Cpy = Tmp then
           begin
            Notes.Lines.Delete(Y);
            pBar.MaxValue := Notes.Lines.Count -1;
            Y := Y -1;
           end;
           Inc(Y);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
   end
  else if Opt20.Checked then  // remove all characters on line up to "character"
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := Pos(RmvCharsToChars.Text, Tmp);
        if Y > 0 then
         begin
          Tmp := Copy(Tmp, Y +Length(RmvCharsToChars.Text), Length(Tmp));
          Notes.Lines.Strings[X] := Tmp;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := Pos(RmvCharsToChars.Text, Tmp);
        if Y > 0 then
         begin
          Tmp := Copy(Tmp, Y +Length(RmvCharsToChars.Text), Length(Tmp));
          Notes.Lines.Strings[X] := Tmp;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
   end
  else if Opt21.Checked then  // remove all line breaks
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      Cpy := Notes.Lines.Strings[0];
      while X < Notes.Lines.Count -1 do
       begin
        Cpy := Cpy + Notes.Lines.Strings[X +1];
        Inc(X);
        if nCanc = false then X := -1;
        Application.ProcessMessages;
       end;
       Notes.Lines.Text := Cpy;
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      Y := X;
      Tmp := '';
      while (X <= Z) and (nCanc) do
       begin
        Tmp := Tmp + Notes.Lines.Strings[Y +1];
        Inc(X);
        if X >= Z then nCanc := false
        else Notes.Lines.Delete(Y +1);
        if nCanc = false then X := Z +2;
        Application.ProcessMessages;
        pBar.Progress := pBar.Progress +1;
       end;
       Notes.Lines.Strings[Y +1] := Tmp;
     end
   end

  else if Opt22.Checked then  // break before/after line if all characters are uppercase/lowercase
   begin
    if Notes.SelLength < 1 then
     begin
      X := 1;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := trim(Notes.Lines.Strings[X]);
        if brklnchr.ItemIndex = 0 then
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end
        else
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end;
         Inc(X);
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        Tmp := trim(Notes.Lines.Strings[X]);
        if brklnchr.ItemIndex = 0 then
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end
        else
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end;
         Inc(X);
       end
     end
   end

  else MessageDlg('No options have been choosen!.', mtWarning, [mbok], 0);
  nCanc := not nCanc;
  ToolButton17.Tag := 0;
  ToolButton17.ImageIndex := 11;
  Notes.ReadOnly := false;
  pBar.Progress := 0;
  Main.Caption := Capt + 'Done ! ;-)';
 end
end;

Open in new window

Avatar of Mike McCracken
Mike McCracken

It would be helpful to explain what the code is supposed to do and why you believe there are bugs?

mlmcc
Avatar of Jai Sewell

ASKER

The code does 30 different types of operations, each option is commented on what it should do...
The application is merely a tiny notepad (with a RichEdit control) and you have options like "Add 'x' characters to the beginning of each line", "Split line after 'n' characters", "Add 'n' spaces to the beginning of each line", "Split line after 'x' character/s", "Split line before 'x' character/s", "Remove lines that contain the characters 'x'", "Remove lines that do not contain the characters 'x'", etc, etc...

The code will either work on the entire contents of the RichEdit or if you select just a portion (like a line or a couple of lines) then only the selected portion is worked upon, there is also a progress bar in the application and i am pretty sure the maths for that is a bit buggy in some of the options.

Another bug is the contents of the RichEdit it will sometimes simply change to a number of 0's (zero's), i am now trying to replicate this and figure out exactly at which point this occurs but it is difficult.
well, i tried and it doesn't compile
actually, i didn't have to compile, i saw it wouldn't compile, just by looking at the code

the abundant use of Application.ProcessMessages; doesn't bode well

just to indicate ambiguity:
Main.Caption := Capt + 'Done ! ;-)';

is main a label or the instance of the main form ?
if it's the instance ... use self.caption

it doesn't compile because we can't see the dfm ...
and ... what components are needed ?
Main is the main form (hence procedure TMain.DoIt;) which has on it a RichEdit (that is hyperlink aware) with the name of "Notes", a TGauge component with the name of "pBar" and a TStatusBar with the name of "Stat" and of course the button which calls the "DoIt" procedure.

Opt1 to Opt22 are TRadioButtons and Chk1 to Chk13 are TCheckbox components that are on another form (named "nOpts") that contains all of the settings for the "DoIt" procedure posted above in the question...

I will post the contents of the Option (nOpt) form *.dfm

object nOpts: TnOpts
  Left = 288
  Top = 80
  BorderIcons = [biSystemMenu]
  BorderStyle = bsSingle
  Caption = 'Notepad Options'
  ClientHeight = 515
  ClientWidth = 490
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poScreenCenter
  OnMouseWheelDown = FormMouseWheelDown
  OnMouseWheelUp = FormMouseWheelUp
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 465
    Height = 969
    BevelOuter = bvNone
    TabOrder = 0
    object Label1: TLabel
      Left = 184
      Top = 8
      Width = 134
      Height = 13
      Caption = 'to the begining of each line!.'
      Enabled = False
    end
    object Label2: TLabel
      Left = 16
      Top = 80
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label3: TLabel
      Left = 184
      Top = 96
      Width = 112
      Height = 13
      Caption = 'to the end of each line!.'
      Enabled = False
    end
    object Label4: TLabel
      Left = 16
      Top = 168
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label5: TLabel
      Left = 144
      Top = 184
      Width = 171
      Height = 13
      Caption = 'spaces to the begining of each line!.'
    end
    object Label6: TLabel
      Left = 16
      Top = 208
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label7: TLabel
      Left = 144
      Top = 224
      Width = 34
      Height = 13
      Caption = 'spaces'
      Enabled = False
    end
    object Label8: TLabel
      Left = 283
      Top = 224
      Width = 145
      Height = 13
      Caption = 'from the begining of each line!.'
      Enabled = False
    end
    object Label9: TLabel
      Left = 16
      Top = 288
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label10: TLabel
      Left = 16
      Top = 328
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label11: TLabel
      Left = 168
      Top = 344
      Width = 85
      Height = 13
      Caption = 'random charactes'
      Enabled = False
    end
    object Label12: TLabel
      Left = 16
      Top = 248
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label13: TLabel
      Left = 144
      Top = 264
      Width = 34
      Height = 13
      Caption = 'spaces'
      Enabled = False
    end
    object Label14: TLabel
      Left = 283
      Top = 264
      Width = 123
      Height = 13
      Caption = 'from the end of each line!.'
      Enabled = False
    end
    object Label15: TLabel
      Left = 16
      Top = 368
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object splitLabel: TLabel
      Left = 182
      Top = 384
      Width = 113
      Height = 13
      Caption = 'characters in each line!.'
    end
    object Label16: TLabel
      Left = 16
      Top = 408
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label17: TLabel
      Left = 16
      Top = 448
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label18: TLabel
      Left = 144
      Top = 464
      Width = 106
      Height = 13
      Caption = 'lines to the begining!...'
      Enabled = False
    end
    object Label19: TLabel
      Left = 16
      Top = 488
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label20: TLabel
      Left = 160
      Top = 505
      Width = 21
      Height = 13
      Caption = 'lines'
      Enabled = False
    end
    object Label21: TLabel
      Left = 16
      Top = 528
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label22: TLabel
      Left = 368
      Top = 545
      Width = 9
      Height = 13
      Caption = 'to'
      Enabled = False
    end
    object Label23: TLabel
      Left = 16
      Top = 568
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label24: TLabel
      Left = 16
      Top = 648
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label25: TLabel
      Left = 336
      Top = 664
      Width = 106
      Height = 13
      Caption = 'leading each insertion.'
      Enabled = False
    end
    object Label26: TLabel
      Left = 16
      Top = 608
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label27: TLabel
      Left = 16
      Top = 688
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label28: TLabel
      Left = 168
      Top = 706
      Width = 31
      Height = 13
      Caption = 'nd line'
    end
    object Label29: TLabel
      Left = 16
      Top = 728
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label30: TLabel
      Left = 16
      Top = 768
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label31: TLabel
      Left = 16
      Top = 808
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label32: TLabel
      Left = 16
      Top = 848
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label33: TLabel
      Left = 16
      Top = 888
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label34: TLabel
      Left = 16
      Top = 928
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label35: TLabel
      Left = 120
      Top = 945
      Width = 111
      Height = 13
      Caption = 'line if all characters are '
    end
    object Opt1: TRadioButton
      Left = 8
      Top = 8
      Width = 41
      Height = 17
      Caption = 'Add'
      TabOrder = 0
      OnClick = Opt1Click
    end
    object AddChar1: TEdit
      Left = 56
      Top = 5
      Width = 121
      Height = 21
      Enabled = False
      TabOrder = 1
      Text = '//'
      OnChange = AddChar1Change
    end
    object Chk1: TCheckBox
      Left = 24
      Top = 32
      Width = 153
      Height = 17
      Caption = 'and to the end of each line!.'
      Enabled = False
      TabOrder = 2
      OnClick = Chk1Click
    end
    object Chk2: TCheckBox
      Left = 24
      Top = 56
      Width = 289
      Height = 17
      Caption = 'Reverse string before adding to end of line!. (a bc = cb a)'
      Enabled = False
      TabOrder = 3
      OnClick = Chk2Click
    end
    object Opt2: TRadioButton
      Left = 8
      Top = 96
      Width = 41
      Height = 17
      Caption = 'Add'
      TabOrder = 4
      OnClick = Opt2Click
    end
    object AddChar2: TEdit
      Left = 56
      Top = 93
      Width = 121
      Height = 21
      Enabled = False
      TabOrder = 5
      Text = '//'
      OnChange = AddChar2Change
    end
    object Chk3: TCheckBox
      Left = 24
      Top = 120
      Width = 177
      Height = 17
      Caption = 'and to the begining of each line!.'
      Enabled = False
      TabOrder = 6
      OnClick = Chk3Click
    end
    object Chk4: TCheckBox
      Left = 24
      Top = 144
      Width = 313
      Height = 17
      Caption = 'Reverse string before adding to begining of line!. (a bc = cb a)'
      Enabled = False
      TabOrder = 7
      OnClick = Chk4Click
    end
    object Opt3: TRadioButton
      Left = 8
      Top = 184
      Width = 41
      Height = 17
      Caption = 'Add'
      Checked = True
      TabOrder = 8
      TabStop = True
      OnClick = Opt3Click
    end
    object AddVal: TSpinEdit
      Left = 56
      Top = 181
      Width = 81
      Height = 22
      MaxValue = 255
      MinValue = 1
      TabOrder = 9
      Value = 1
      OnChange = AddValChange
    end
    object Opt4: TRadioButton
      Left = 8
      Top = 224
      Width = 49
      Height = 17
      Caption = 'Take'
      TabOrder = 10
      OnClick = Opt4Click
    end
    object TakeVal1: TSpinEdit
      Left = 56
      Top = 220
      Width = 81
      Height = 22
      Enabled = False
      MaxValue = 255
      MinValue = 1
      TabOrder = 11
      Value = 1
      OnChange = TakeVal1Change
    end
    object Chk5: TCheckBox
      Left = 184
      Top = 223
      Width = 97
      Height = 17
      Caption = '(and characters)'
      Enabled = False
      TabOrder = 12
      OnClick = Chk5Click
    end
    object Opt6: TRadioButton
      Left = 8
      Top = 304
      Width = 81
      Height = 17
      Caption = 'Convert all to'
      TabOrder = 13
      OnClick = Opt6Click
    end
    object Conv: TComboBox
      Left = 96
      Top = 301
      Width = 145
      Height = 21
      Enabled = False
      ItemHeight = 13
      ItemIndex = 0
      TabOrder = 14
      Text = 'Lowercase!.'
      OnChange = ConvChange
      OnClick = ConvClick
      Items.Strings = (
        'Lowercase!.'
        'Uppercase!.'
        'ASCII'
        'Hexadecimal!.'
        'Binary!.'
        'HTML/Javascript Escape!.'
        'HTML/Javascript Unescape!.'
        'String!.')
    end
    object Opt7: TRadioButton
      Left = 8
      Top = 344
      Width = 65
      Height = 17
      Caption = 'Generate'
      TabOrder = 15
      OnClick = Opt7Click
    end
    object Seed: TSpinEdit
      Left = 80
      Top = 341
      Width = 81
      Height = 22
      Enabled = False
      MaxValue = 255
      MinValue = 1
      TabOrder = 16
      Value = 32
      OnChange = SeedChange
    end
    object Chk7: TCheckBox
      Left = 256
      Top = 343
      Width = 89
      Height = 17
      Caption = 'on a new line!.'
      Enabled = False
      TabOrder = 17
      OnClick = Chk7Click
    end
    object Opt5: TRadioButton
      Left = 8
      Top = 264
      Width = 49
      Height = 17
      Caption = 'Take'
      TabOrder = 18
      OnClick = Opt5Click
    end
    object TakeVal2: TSpinEdit
      Left = 56
      Top = 261
      Width = 81
      Height = 22
      Enabled = False
      MaxValue = 255
      MinValue = 1
      TabOrder = 19
      Value = 1
      OnChange = TakeVal2Change
    end
    object Chk6: TCheckBox
      Left = 184
      Top = 263
      Width = 97
      Height = 17
      Caption = '(and characters)'
      Enabled = False
      TabOrder = 20
      OnClick = Chk6Click
    end
    object Opt9: TRadioButton
      Left = 8
      Top = 424
      Width = 177
      Height = 17
      Caption = 'Remove only blank (empty) lines!.'
      TabOrder = 21
      OnClick = Opt9Click
    end
    object Opt8: TRadioButton
      Left = 8
      Top = 384
      Width = 81
      Height = 17
      Caption = 'Split line after'
      TabOrder = 22
      OnClick = Opt8Click
    end
    object SplitVal: TSpinEdit
      Left = 97
      Top = 381
      Width = 81
      Height = 22
      MaxValue = 5000
      MinValue = 1
      TabOrder = 23
      Value = 64
      OnChange = SplitValChange
    end
    object Opt10: TRadioButton
      Left = 8
      Top = 463
      Width = 41
      Height = 17
      Caption = 'Add'
      TabOrder = 24
      OnClick = Opt10Click
    end
    object AddLines: TSpinEdit
      Left = 54
      Top = 461
      Width = 81
      Height = 22
      Enabled = False
      MaxValue = 255
      MinValue = 1
      TabOrder = 25
      Value = 1
      OnChange = AddLinesChange
    end
    object Opt11: TRadioButton
      Left = 8
      Top = 504
      Width = 65
      Height = 17
      Caption = 'Remove'
      TabOrder = 26
      OnClick = Opt11Click
    end
    object RmvLines: TSpinEdit
      Left = 72
      Top = 501
      Width = 81
      Height = 22
      Enabled = False
      MaxValue = 255
      MinValue = 1
      TabOrder = 27
      Value = 1
      OnChange = RmvLinesChange
    end
    object Chk8: TCheckBox
      Left = 187
      Top = 504
      Width = 190
      Height = 17
      Caption = '(and characters) from the begining!...'
      Enabled = False
      TabOrder = 28
      OnClick = Chk8Click
    end
    object Opt12: TRadioButton
      Left = 8
      Top = 544
      Width = 73
      Height = 17
      Caption = 'Convert all'
      TabOrder = 29
      OnClick = Opt12Click
    end
    object FndText: TEdit
      Left = 179
      Top = 541
      Width = 78
      Height = 21
      Enabled = False
      TabOrder = 30
      OnChange = FndTextChange
    end
    object RplText: TEdit
      Left = 384
      Top = 541
      Width = 81
      Height = 21
      Enabled = False
      TabOrder = 31
      OnChange = RplTextChange
    end
    object Chk9: TCheckBox
      Left = 81
      Top = 544
      Width = 97
      Height = 17
      Caption = '(matching case)'
      Checked = True
      Enabled = False
      State = cbChecked
      TabOrder = 32
      OnClick = Chk9Click
    end
    object Chk10: TCheckBox
      Left = 264
      Top = 544
      Width = 97
      Height = 17
      Caption = '(as whole words)'
      Enabled = False
      TabOrder = 33
      OnClick = Chk10Click
    end
    object Opt13: TRadioButton
      Left = 8
      Top = 584
      Width = 169
      Height = 17
      Caption = 'Split line/s after the characters '
      TabOrder = 34
      OnClick = Opt13Click
    end
    object SpltTxt: TEdit
      Left = 176
      Top = 581
      Width = 49
      Height = 21
      Enabled = False
      TabOrder = 35
      OnChange = SpltTxtChange
    end
    object Opt14: TRadioButton
      Left = 8
      Top = 664
      Width = 153
      Height = 17
      Caption = 'Incremental number insertion'
      TabOrder = 36
      OnClick = Opt14Click
    end
    object Chk11: TCheckBox
      Left = 168
      Top = 664
      Width = 137
      Height = 17
      Caption = 'and with the character/s'
      Enabled = False
      TabOrder = 37
      OnClick = Chk11Click
    end
    object LeadChars: TEdit
      Left = 307
      Top = 661
      Width = 25
      Height = 21
      Enabled = False
      MaxLength = 1
      TabOrder = 38
      Text = 'C0'
      OnChange = LeadCharsChange
    end
    object Chk12: TCheckBox
      Left = 228
      Top = 584
      Width = 237
      Height = 17
      Caption = 'only if more characters exist after split position'
      Checked = True
      Enabled = False
      State = cbChecked
      TabOrder = 39
      OnClick = Chk12Click
    end
    object Opt15: TRadioButton
      Left = 8
      Top = 624
      Width = 177
      Height = 17
      Caption = 'Split line/s before the characters'
      TabOrder = 40
      OnClick = Opt15Click
    end
    object SpltTxt2: TEdit
      Left = 184
      Top = 623
      Width = 49
      Height = 21
      Enabled = False
      TabOrder = 41
      OnChange = SpltTxt2Change
    end
    object Opt16: TRadioButton
      Left = 8
      Top = 704
      Width = 89
      Height = 17
      Caption = 'Remove every'
      TabOrder = 42
      OnClick = Opt16Click
    end
    object LineCount: TSpinEdit
      Left = 104
      Top = 704
      Width = 65
      Height = 22
      Enabled = False
      MaxValue = 0
      MinValue = 0
      TabOrder = 43
      Value = 2
      OnChange = LineCountChange
      OnClick = LineCountClick
      OnEnter = LineCountEnter
    end
    object Opt17: TRadioButton
      Left = 8
      Top = 744
      Width = 257
      Height = 17
      Caption = 'Remove line/s that do not contain the characters'
      TabOrder = 44
      OnClick = Opt17Click
    end
    object KeepChars: TEdit
      Left = 264
      Top = 742
      Width = 121
      Height = 21
      Enabled = False
      TabOrder = 45
      OnChange = KeepCharsChange
    end
    object Opt18: TRadioButton
      Left = 8
      Top = 784
      Width = 217
      Height = 17
      Caption = 'Remove line/s that contain the characters'
      TabOrder = 46
      OnClick = Opt18Click
    end
    object RmvChars: TEdit
      Left = 232
      Top = 782
      Width = 121
      Height = 21
      TabOrder = 47
      OnChange = RmvCharsChange
    end
    object Opt19: TRadioButton
      Left = 8
      Top = 824
      Width = 129
      Height = 17
      Caption = 'Remove duplicate lines'
      TabOrder = 48
      OnClick = Opt19Click
    end
    object Opt20: TRadioButton
      Left = 8
      Top = 864
      Width = 201
      Height = 17
      Caption = 'Remove all characters on line/s up to'
      TabOrder = 49
      OnClick = Opt20Click
    end
    object RmvCharsToChars: TEdit
      Left = 208
      Top = 864
      Width = 121
      Height = 21
      Enabled = False
      TabOrder = 50
      OnChange = RmvCharsToCharsChange
    end
    object Opt21: TRadioButton
      Left = 8
      Top = 904
      Width = 129
      Height = 17
      Caption = 'Remove all line breaks'
      TabOrder = 51
    end
    object Opt22: TRadioButton
      Left = 8
      Top = 944
      Width = 49
      Height = 17
      Caption = 'Break'
      TabOrder = 52
    end
    object brklnchr: TComboBox
      Left = 232
      Top = 941
      Width = 81
      Height = 21
      ItemHeight = 13
      ItemIndex = 0
      TabOrder = 53
      Text = 'Uppercase'
      Items.Strings = (
        'Uppercase'
        'Lowercase')
    end
    object Chk13: TCheckBox
      Left = 320
      Top = 944
      Width = 137
      Height = 17
      Caption = 'and including numerals.'
      TabOrder = 54
    end
    object BrkPos: TComboBox
      Left = 59
      Top = 941
      Width = 57
      Height = 21
      ItemHeight = 13
      ItemIndex = 0
      TabOrder = 55
      Text = 'Before'
      Items.Strings = (
        'Before'
        'After')
    end
  end
  object sBar: TScrollBar
    Left = 472
    Top = 0
    Width = 17
    Height = 257
    Kind = sbVertical
    Max = 457
    PageSize = 0
    TabOrder = 1
    OnChange = sBarChange
  end
end

Open in new window

giving bits and pieces ?

to give you an idea of what you are asking
here is a windshield, a steering wheel and the car door ...
what's wrong with my car ?

the answer: it's in bits and pieces
You're right Geert i should have posted enough code to have a working modal instead of just a procedure...
Here is the entire code to make the above mentioned procedure function with a TRichEdit and required controls.

Unit1.pas
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Gauges, ComCtrls, Menus, StdCtrls, StrUtils;

type
  TMain = class(TForm)
    Notes: TRichEdit;
    Menu: TMainMenu;
    Menu1: TMenuItem;
    Stat: TStatusBar;
    pBar: TGauge;
    Menu2: TMenuItem;
    procedure FormResize(Sender: TObject);
    procedure Menu2Click(Sender: TObject);
    procedure Menu1Click(Sender: TObject);
  private
    { Private declarations }
    procedure DoIt;
  public
    { Public declarations }
  end;

var
  Main: TMain;
  nCanc: boolean;

const Capt: string = 'Notepad tool    ';

implementation

uses Unit2, BinConv, Global, intutil;

{$R *.dfm}

procedure TMain.DoIt;
var X, Y, Z: integer;
Tmp, Cpy: ansistring;
pRange: xRange;
Canc: boolean;
 function GetIndex(start: boolean): integer;
 var L: integer;
 Math: Extended;
 begin
 L := 0;
 result := 0;
 Math := 0;
 while (L <= Notes.Lines.Count -1) and (nCanc) do
  begin
   Math := Math +Length(Notes.Lines.Strings[L]) +2;
   if Math < 0 then Math := 0;
   if start then
    begin
     if Math >= Notes.SelStart then
      begin
       if Notes.SelStart = Math then L := L+1;
       result := L;
       L := Notes.Lines.Count +2;
      end
    end
   else
    begin
     if Math >= Notes.SelStart +Notes.SelLength then
      begin
       result := L;
       L := Notes.Lines.Count +2;
      end
    end;
    Inc(L);
  end
 end;
begin
with nOpts do
 begin
  X := 0;
  Tmp := '';
  nCanc := true;
  if Opt1.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := AddChar1.Text +Notes.Lines.Strings[X];
        if Chk1.Checked then
         begin
          if Chk2.Checked then Tmp := Tmp +ReverseString(AddChar1.Text)
          else Tmp := Tmp +AddChar1.Text;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := AddChar1.Text +Notes.Lines.Strings[X];
        if Chk1.Checked then
         begin
          if Chk2.Checked then Tmp := Tmp +ReverseString(AddChar1.Text)
          else Tmp := Tmp +AddChar1.Text;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt2.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X] +AddChar2.Text;
        if Chk3.Checked then
         begin
          if Chk4.Checked then Tmp := ReverseString(AddChar2.Text) +Tmp
          else Tmp := AddChar2.Text +Tmp;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X] +AddChar2.Text;
        if Chk3.Checked then
         begin
          if Chk4.Checked then Tmp := ReverseString(AddChar2.Text) +Tmp
          else Tmp := AddChar2.Text +Tmp;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt3.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      for X := 1 to AddVal.Value do Tmp := Tmp + ' ';
      X := 0;
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Notes.Lines.Strings[X] := Tmp +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := X;
        Application.ProcessMessages;
       end
     end
    else
     begin
      for X := 1 to AddVal.Value do Tmp := Tmp + ' ';
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Notes.Lines.Strings[X] := Tmp +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
   end
  else if Opt4.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk5.Checked then Delete(Tmp, 1, TakeVal1.Value)
        else
         begin
          if trim(Copy(Tmp, 1, TakeVal1.Value)) = '' then Delete(Tmp, 1, TakeVal1.Value)
          else
           begin
            while Copy(Tmp, 1, 1) = ' ' do Delete(Tmp, 1, 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk5.Checked then Delete(Tmp, 1, TakeVal1.Value)
        else
         begin
          if trim(Copy(Tmp, 1, TakeVal1.Value)) = '' then Delete(Tmp, 1, TakeVal1.Value)
          else
           begin
            while Copy(Tmp, 1, 1) = ' ' do Delete(Tmp, 1, 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt5.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk6.Checked then Tmp := Copy(Tmp, 1, Length(Tmp) -TakeVal2.Value)
        else
         begin
          if trim(Copy(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)) = '' then Delete(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)
          else
           begin
            while Copy(Tmp, Length(Tmp), 1) = ' ' do Delete(Tmp, Length(Tmp), 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk6.Checked then Tmp := Copy(Tmp, 1, Length(Tmp) -TakeVal2.Value)
        else
         begin
          if trim(Copy(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)) = '' then Delete(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)
          else
           begin
            while Copy(Tmp, Length(Tmp), 1) = ' ' do Delete(Tmp, Length(Tmp), 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt6.Checked then
   begin
    if Conv.ItemIndex = 0 then
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := LowerCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := LowerCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 1 then
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UpperCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UpperCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 2 then
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Y := 1;
          Cpy := '';
          Tmp := Notes.Lines.Strings[X];
          while (Y <= Length(Tmp)) and (nCanc) do
           begin
            Cpy := Cpy +IntToStr(Ord(Tmp[Y])) + ', ';
            Inc(Y);
           end;
           Cpy := trim(Cpy);
           if Copy(Cpy, Length(Cpy), 1) = ',' then Delete(Cpy, Length(Cpy), 1);
           Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := X;
           Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Z := 1;
          Cpy := '';
          Tmp := Notes.Lines.Strings[X];
          while (Z <= Length(Tmp)) and (nCanc) do
           begin
            Cpy := Cpy +IntToStr(Ord(Tmp[Z])) + ', ';
            Inc(Z);
           end;
           Cpy := trim(Cpy);
           if Copy(Cpy, Length(Cpy), 1) = ',' then Delete(Cpy, Length(Cpy), 1);
           Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 3 then
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Tmp := Hex2Bin(Notes.Lines.Strings[X]);
          Tmp := Bin2Hex(Tmp);
          Notes.Lines.Strings[X] := Tmp;
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end;
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Tmp := Hex2Bin(Notes.Lines.Strings[X]);
          Tmp := Bin2Hex(Tmp);
          Notes.Lines.Strings[X] := Tmp;
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 4 then
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := Hex2Bin(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := Hex2Bin(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 5 then
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlEncode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlEncode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 6 then
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlDecode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlDecode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        Cpy := '';
        if Notes.Lines.Count > 0 then pBar.MaxValue := Length(Notes.Lines.Text);
        while (X <= pBar.MaxValue) and (nCanc) do
         begin
          Tmp := Notes.Lines.Strings[X];
          if IsBinary(Tmp) then
           begin
            Tmp := Bin2Hex(Tmp);
            Cpy := StringOfChar('0', Length(Tmp) div 2);
            HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
           end
          else
           begin
            Canc := true;
            Cpy := '';
            Z := 0;
            while (Length(Tmp) > 0) and (nCanc) do
             begin
              if Pos(',', Tmp) > 0 then
               begin
                if isint(Copy(Tmp, 1, Pos(',', Tmp) -1), false, false) then
                 begin
                  if (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) < 256) and (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) > 0) then
                   begin
                    Cpy := Cpy +Chr(StrToInt(Copy(Tmp, 1, Pos(',', Tmp) -1)));
                    Canc := false;
                    Z := 1;
                   end
                  else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                 end
                else
                 begin
                  MessageDlg('Data is not numerical and is not an ASCII code!.', mtWarning, [mbok], 0);
                  nCanc := not nCanc;
                 end;
                 Delete(Tmp, 1, Pos(',', Tmp) +1);
               end
              else
               begin
                if isint(Tmp, false, false) then
                 begin
                  if (StrToFloat(Tmp) < 100) and (Canc) then
                   begin
                    if MessageDlg('Unable to determine data type!, is the data ASCII?', mtConfirmation, [mbyes, mbno], 0) = mryes then Z := 1;
                   end
                  else Z := 1;
                  if StrToFloat(Tmp) > 255 then Z := 0;
                  if Z = 0 then // hexadecimal
                   begin
                    Cpy := StringOfChar('0', Length(Tmp) div 2);
                    HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                   end
                  else // ASCII
                   begin
                    if (StrToFloat(Tmp) < 256) and (StrToFloat(Tmp) > 0) then Cpy := Cpy +Chr(StrToInt(Tmp))
                    else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                   end
                 end
                else
                 begin
                  Cpy := StringOfChar('0', Length(Tmp) div 2);
                  HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                 end;
                 Tmp := '';
               end
             end
           end;
           if nCanc = true then Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := X;
           Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Tmp := Notes.Lines.Strings[X];
          if IsBinary(Tmp) then
           begin
            Tmp := Bin2Hex(Tmp);
            Cpy := StringOfChar('0', Length(Tmp) div 2);
            HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
           end
          else
           begin
            Canc := true;
            Cpy := '';
            Z := 0;
            while (Length(Tmp) > 0) and (nCanc) do
             begin
              if Pos(',', Tmp) > 0 then
               begin
                if isint(Copy(Tmp, 1, Pos(',', Tmp) -1), false, false) then
                 begin
                  if (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) < 256) and (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) > 0) then
                   begin
                    Cpy := Cpy +Chr(StrToInt(Copy(Tmp, 1, Pos(',', Tmp) -1)));
                    Canc := false;
                    Z := 1;
                   end
                  else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                 end
                else MessageDlg('Data is not numerical and is not an ASCII code!.', mtWarning, [mbok], 0);
                Delete(Tmp, 1, Pos(',', Tmp) +1);
               end
              else
               begin
                if isint(Tmp, false, false) then
                 begin
                  if (StrToFloat(Tmp) < 100) and (Canc) then
                   begin
                    if MessageDlg('Unable to determine data type!, is the data ASCII?', mtConfirmation, [mbyes, mbno], 0) = mryes then Z := 1;
                   end
                  else Z := 1;
                  if StrToFloat(Tmp) > 255 then Z := 0;
                  if Z = 0 then // hexadecimal
                   begin
                    Cpy := StringOfChar('0', Length(Tmp) div 2);
                    HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                   end
                  else // ASCII
                   begin
                    if (StrToFloat(Tmp) < 256) and (StrToFloat(Tmp) > 0) then Cpy := Cpy +Chr(StrToInt(Tmp))
                    else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                   end
                 end
                else
                 begin
                  Cpy := StringOfChar('0', Length(Tmp) div 2);
                  HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                 end;
                 Tmp := '';
               end
             end
           end;
           Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end
       end
     end
   end
  else if Opt7.Checked then
   begin
    pRange[0] := 1;
    pRange[1] := 255;
    pBar.MaxValue := Seed.Value -1;
    for X := 1 to Seed.Value do
     begin
      Tmp := Tmp +Chr(iRandom(pRange));
      pBar.Progress := pBar.Progress +1;
     end;
     if Chk7.Checked then Notes.Lines.Add(Tmp)
     else Notes.Lines.Text := Notes.Lines.Text +Tmp;
   end
  else if Opt8.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if trim(Notes.Lines.Strings[X]) <> '' then
         begin
          with Notes.Lines do Strings[X] := Copy(Strings[X], 1, SplitVal.Value) + #13#10 + Copy(Strings[X], SplitVal.Value +1, Length(Strings[X]));
         end;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end;
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if trim(Notes.Lines.Strings[X]) <> '' then
         begin
          with Notes.Lines do Strings[X] := Copy(Strings[X], 1, SplitVal.Value) + #13#10 + Copy(Strings[X], SplitVal.Value +1, Length(Strings[X]));
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt9.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if trim(Notes.Lines.Strings[X]) = '' then
         begin
          Notes.Lines.Delete(X);
          if X < Notes.Lines.Count -1 then Dec(X)
          else nCanc := false
         end;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end;
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if trim(Notes.Lines.Strings[X]) = '' then
         begin
          Dec(Y);
          Notes.Lines.Delete(X);
          if X < Notes.Lines.Count -1 then Dec(X)
          else nCanc := false
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt10.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := AddLines.Value;
      while (X <= AddLines.Value -1) and (nCanc) do
       begin
        Notes.Lines.Insert(0, '');
        Inc(X);
        pBar.Progress := X;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := 0;
      Y := GetIndex(true);
      pBar.MaxValue := AddLines.Value;
      while (X <= AddLines.Value -1) and (nCanc) do
       begin
        Notes.Lines.Insert(Y, '');
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end 
   end
  else if Opt11.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := RmvLines.Value;
      while (X <= RmvLines.Value -1) and (nCanc) do
       begin
        if Chk8.Checked then Notes.Lines.Delete(0)
        else if Notes.Lines.Strings[0] = '' then Notes.Lines.Delete(0);
        Inc(X);
        pBar.Progress := X;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := 0;
      Y := GetIndex(true);
      pBar.MaxValue := RmvLines.Value;
      while (X <= RmvLines.Value -1) and (nCanc) do
       begin
        if Chk8.Checked then Notes.Lines.Delete(Y -1)
        else
         begin
          if Y > 0 then
           begin
            if Notes.Lines.Strings[Y -1] = '' then Notes.Lines.Delete(Y -1)
            else
             begin
              if Y > 1 then Z := Y -1
              else Z := 0;
              while (Notes.Lines.Strings[Z] <> '') and (Z > 0) do Dec(Z);
              if Z > 0 then Notes.Lines.Delete(Z);
             end
           end
         end;
         Dec(Y);
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt12.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      Y := 0;
      while (Y >= 0) and (nCanc) do
       begin
        if (Chk9.Checked) and (not Chk10.Checked) then Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, [stMatchCase])
        else if (Chk9.Checked) and (Chk10.Checked) then Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, [stMatchCase, stWholeWord])
        else if (not Chk9.Checked) and (Chk10.Checked) then Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, [stWholeWord])
        else Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, []);
        if Y >= 0 then
         begin
          Notes.SelStart := Y;
          Notes.SelLength := FndText.GetTextLen;
          Notes.SelText := RplText.Text;
         end
       end
     end
    else
     begin
      X := GetIndex(true);
      if X > 0 then Y := Length(Notes.Lines.Strings[X -1])
      else Y := 0;
      X := 0;
      Z := GetIndex(false);
      while (X >= 0) and (nCanc) do
       begin
        if (Chk9.Checked) and (not Chk10.Checked) then X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, [stMatchCase])
        else if (Chk9.Checked) and (Chk10.Checked) then X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, [stMatchCase, stWholeWord])
        else if (not Chk9.Checked) and (Chk10.Checked) then X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, [stWholeWord])
        else X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, []);
        if X >= 0 then
         begin
          Notes.SelStart := X;
          Notes.SelLength := FndText.GetTextLen;
          if GetIndex(true) > Z then X := -1
          else Notes.SelText := RplText.Text;
         end;
         Y := X;
       end
     end
   end
  else if Opt13.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      Y := 1;
      X := Notes.FindText(SpltTxt.Text, Y, Notes.GetTextLen, [stMatchCase]);
      while X > 0 do
       begin
        if Chk12.Checked then
         begin
          if (X > 0) and (Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, 1) <> #13) then Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
         end
        else Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
        Y := X +SpltTxt.GetTextLen;
        X := Notes.FindText(SpltTxt.Text, Y, Notes.GetTextLen -X, [stMatchCase]);
        Application.ProcessMessages;
        if nCanc = false then X := -1;
       end
     end
    else
     begin
      Y := Notes.SelStart;
      Z := Notes.SelLength;
      Tmp := IntToStr(Y +Z);
      X := Notes.FindText(SpltTxt.Text, Y, Z, [stMatchCase]);
      Cpy := '0';
      while X > 0 do
       begin
         if Y >= StrToInt(Tmp) then X := -1
         else X := Notes.FindText(SpltTxt.Text, Y, Z, [stMatchCase]);
         if X > 0 then
          begin
           if Chk12.Checked then
            begin
             if Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, 1) <> #13 then
              begin
               Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
               Z := Z +Length(#13#10);
               Tmp := IntToStr(StrToInt(Tmp) +Length(#13#10));
              end
            end
           else
            begin
             Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
             Z := Z +Length(#13#10);
             Tmp := IntToStr(StrToInt(Tmp) +Length(#13#10));
            end;
            while trim(Notes.Lines.Text[(X + StrToInt(Cpy)) +(SpltTxt.GetTextLen +Length(#13#10))]) = '' do Cpy := IntToStr(StrToInt(Cpy) +1);
            Y := (X + StrToInt(Cpy)) +(SpltTxt.GetTextLen +Length(#13#10));
          end;
          if nCanc = false then X := -1;
          Application.ProcessMessages;
       end
     end
   end
  else if Opt14.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      Y := 0;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Inc(Y);
        if Chk11.Checked then Notes.Lines.Strings[X] := LeadChars.Text + IntToStr(Y) +Notes.Lines.Strings[X]
        else Notes.Lines.Strings[X] := IntToStr(Y) +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
    else
     begin
      Y := 0;
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        Inc(Y);
        if Chk11.Checked then Notes.Lines.Strings[X] := LeadChars.Text + IntToStr(Y) +Notes.Lines.Strings[X]
        else Notes.Lines.Strings[X] := IntToStr(Y) +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
   end
  else if Opt15.Checked then // split before, add pbar count
   begin
    if Notes.SelLength < 1 then
     begin
      Y := 1;
      X := Notes.FindText(SpltTxt2.Text, Y, Notes.GetTextLen, [stMatchCase]);
      while X > 0 do
       begin
        Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X) + #13#10 + Copy(Notes.Lines.Text, X +1, Notes.GetTextLen -(X +1));
        Y := X +(SpltTxt2.GetTextLen +2);
        X := Notes.FindText(SpltTxt2.Text, Y, Notes.GetTextLen -X, [stMatchCase]);
        Application.ProcessMessages;
        if nCanc = false then X := -1;
       end
     end
    else
     begin
      Y := Notes.SelStart;
      Z := Notes.SelLength;
      Tmp := IntToStr(Y +Z);
      X := Notes.FindText(SpltTxt2.Text, Y, Z, [stMatchCase]);
      Cpy := '0';
      while X > 0 do
       begin
         if Y >= StrToInt(Tmp) then X := -1
         else X := Notes.FindText(SpltTxt2.Text, Y, Z, [stMatchCase]);
         if X > 0 then
          begin
           Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X) + #13#10 + Copy(Notes.Lines.Text, X +1, Notes.GetTextLen -(X +1));
           Z := Z +Length(#13#10);
           Tmp := IntToStr(StrToInt(Tmp) +Length(#13#10));
           while trim(Notes.Lines.Text[(X + StrToInt(Cpy)) +((SpltTxt2.GetTextLen +1) +Length(#13#10))]) = '' do Cpy := IntToStr(StrToInt(Cpy) +1);
           Y := (X + StrToInt(Cpy)) +((SpltTxt2.GetTextLen +2) +Length(#13#10));
          end;
          if nCanc = false then X := -1;
          Application.ProcessMessages;
       end
     end
   end
  else if Opt16.Checked then 
   begin
    if Notes.SelLength < 1 then
     begin
      X := 1; // counter
      Y := 0; // loop index
      pBar.MaxValue := Notes.Lines.Count -1;
      while (Y <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if X = LineCount.Value then
         begin
          X := 1;
          Notes.Lines.Delete(Y);
          pBar.MaxValue := Notes.Lines.Count -1;
         end;
         Inc(X);
         Inc(Y);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := 1; // counter
      Y := GetIndex(true); // LOOP INDEX
      Z := GetIndex(false); // end loop
      pBar.MaxValue := Z;
      while (Y <= Z) and (nCanc) do
       begin
        if X = LineCount.Value then
         begin
          X := 1;
          Notes.Lines.Delete(Y);
          Z := Z -1;
          pBar.MaxValue := Notes.Lines.Count -1;
         end;
         Inc(X);
         Inc(Y);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt17.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if Pos(KeepChars.Text, Notes.Lines.Strings[X]) <= 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        if Pos(KeepChars.Text, Notes.Lines.Strings[X]) <= 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
          Z := Z -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
       end
     end
   end
  else if Opt18.Checked then
   begin
    if Notes.SelLength < 1 then
     begin
      X := 1;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if Pos(RmvChars.Text, Notes.Lines.Strings[X]) > 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        if Pos(RmvChars.Text, Notes.Lines.Strings[X]) > 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
   end
  else if Opt19.Checked then  // remove duplicate lines.
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := (Notes.Lines.Count -1) *2;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := X +1;
        while (Y <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Cpy := Notes.Lines.Strings[Y];
          if trim(Cpy) = trim(Tmp) then
           begin
            Notes.Lines.Delete(Y);
            pBar.MaxValue := Notes.Lines.Count -1;
            Y := Y -1;
           end;
           Inc(Y);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z *2;
      while (X <= Z) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := X +1;
        while (Y <= Z) and (nCanc) do
         begin
          Cpy := Notes.Lines.Strings[Y];
          if Cpy = Tmp then
           begin
            Notes.Lines.Delete(Y);
            pBar.MaxValue := Notes.Lines.Count -1;
            Y := Y -1;
           end;
           Inc(Y);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
   end
  else if Opt20.Checked then  // remove duplicate lines.
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := Pos(RmvCharsToChars.Text, Tmp);
        if Y > 0 then
         begin
          Tmp := Copy(Tmp, Y +Length(RmvCharsToChars.Text), Length(Tmp));
          Notes.Lines.Strings[X] := Tmp;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := Pos(RmvCharsToChars.Text, Tmp);
        if Y > 0 then
         begin
          Tmp := Copy(Tmp, Y +Length(RmvCharsToChars.Text), Length(Tmp));
          Notes.Lines.Strings[X] := Tmp;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
   end
  else if Opt21.Checked then  // remove break lines.
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      Cpy := Notes.Lines.Strings[0];
      while X < Notes.Lines.Count -1 do
       begin
        Cpy := Cpy + Notes.Lines.Strings[X +1];
        Inc(X);
        if nCanc = false then X := -1;
        Application.ProcessMessages;
       end;
       Notes.Lines.Text := Cpy;
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      Y := X;
      Tmp := '';
      while (X <= Z) and (nCanc) do
       begin
        Tmp := Tmp + Notes.Lines.Strings[Y +1];
        Inc(X);
        if X >= Z then nCanc := false
        else Notes.Lines.Delete(Y +1);
        if nCanc = false then X := Z +2;
        Application.ProcessMessages;
        pBar.Progress := pBar.Progress +1;
       end;
       Notes.Lines.Strings[Y +1] := Tmp;
     end
   end

  else if Opt22.Checked then  // break lines if all uppercase.
   begin
    if Notes.SelLength < 1 then
     begin
      X := 1;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := trim(Notes.Lines.Strings[X]);
        if brklnchr.ItemIndex = 0 then
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end
        else
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end;
         Inc(X);
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        Tmp := trim(Notes.Lines.Strings[X]);
        if brklnchr.ItemIndex = 0 then
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end
        else
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end;
         Inc(X);
       end
     end
   end

  else MessageDlg('No options have been choosen!.', mtWarning, [mbok], 0);
  nCanc := not nCanc;
  Menu1.Tag := 0;
  Notes.ReadOnly := false;
  pBar.Progress := 0;
  Main.Caption := Capt + 'Done ! ;-)';
 end
end;

procedure TMain.FormResize(Sender: TObject);
begin
pBar.Width := Main.Width -35;
Notes.Width := Main.Width -16;
pBar.Top := Main.Height -99;
Notes.Height := Main.Height -106;
end;

procedure TMain.Menu2Click(Sender: TObject);
begin
nOpts.Show;
end;

procedure TMain.Menu1Click(Sender: TObject);
begin
DoIt;
end;

end.

Open in new window


Unit1.dfm
object Main: TMain
  Left = 339
  Top = 157
  Width = 596
  Height = 499
  Caption = 'Main'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Menu = Menu
  OldCreateOrder = False
  OnResize = FormResize
  PixelsPerInch = 96
  TextHeight = 13
  object pBar: TGauge
    Left = 8
    Top = 400
    Width = 561
    Height = 17
    Progress = 0
  end
  object Notes: TRichEdit
    Left = 0
    Top = 0
    Width = 580
    Height = 393
    Lines.Strings = (
      'Notes')
    TabOrder = 0
  end
  object Stat: TStatusBar
    Left = 0
    Top = 422
    Width = 580
    Height = 19
    Panels = <
      item
        Width = 50
      end>
    SimplePanel = False
  end
  object Menu: TMainMenu
    Left = 240
    Top = 208
    object Menu1: TMenuItem
      Caption = 'Do It'
      OnClick = Menu1Click
    end
    object Menu2: TMenuItem
      Caption = '&Options'
      OnClick = Menu2Click
    end
  end
end

Open in new window


Unit2.pas
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Spin, StdCtrls, ExtCtrls;

type
  TnOpts = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    splitLabel: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Opt1: TRadioButton;
    AddChar1: TEdit;
    Chk1: TCheckBox;
    Chk2: TCheckBox;
    Opt2: TRadioButton;
    AddChar2: TEdit;
    Chk3: TCheckBox;
    Chk4: TCheckBox;
    Opt3: TRadioButton;
    AddVal: TSpinEdit;
    Opt4: TRadioButton;
    TakeVal1: TSpinEdit;
    Chk5: TCheckBox;
    Opt6: TRadioButton;
    Conv: TComboBox;
    Opt7: TRadioButton;
    Seed: TSpinEdit;
    Chk7: TCheckBox;
    Opt5: TRadioButton;
    TakeVal2: TSpinEdit;
    Chk6: TCheckBox;
    Opt9: TRadioButton;
    Opt8: TRadioButton;
    SplitVal: TSpinEdit;
    Opt10: TRadioButton;
    AddLines: TSpinEdit;
    Opt11: TRadioButton;
    RmvLines: TSpinEdit;
    Chk8: TCheckBox;
    Opt12: TRadioButton;
    FndText: TEdit;
    RplText: TEdit;
    Chk9: TCheckBox;
    Chk10: TCheckBox;
    sBar: TScrollBar;
    Opt13: TRadioButton;
    Label23: TLabel;
    SpltTxt: TEdit;
    Label24: TLabel;
    Opt14: TRadioButton;
    Chk11: TCheckBox;
    LeadChars: TEdit;
    Label25: TLabel;
    Chk12: TCheckBox;
    Label26: TLabel;
    Opt15: TRadioButton;
    SpltTxt2: TEdit;
    Label27: TLabel;
    Opt16: TRadioButton;
    LineCount: TSpinEdit;
    Label28: TLabel;
    Label29: TLabel;
    Opt17: TRadioButton;
    KeepChars: TEdit;
    Label30: TLabel;
    Opt18: TRadioButton;
    RmvChars: TEdit;
    Label31: TLabel;
    Opt19: TRadioButton;
    Label32: TLabel;
    Opt20: TRadioButton;
    RmvCharsToChars: TEdit;
    Label33: TLabel;
    Opt21: TRadioButton;
    Label34: TLabel;
    Opt22: TRadioButton;
    brklnchr: TComboBox;
    Chk13: TCheckBox;
    Label35: TLabel;
    BrkPos: TComboBox;
    procedure Opt1Click(Sender: TObject);
    procedure Opt2Click(Sender: TObject);
    procedure Opt3Click(Sender: TObject);
    procedure Opt4Click(Sender: TObject);
    procedure Opt5Click(Sender: TObject);
    procedure Opt6Click(Sender: TObject);
    procedure Opt7Click(Sender: TObject);
    procedure Chk7Click(Sender: TObject);
    procedure Chk6Click(Sender: TObject);
    procedure Chk5Click(Sender: TObject);
    procedure Chk4Click(Sender: TObject);
    procedure Chk3Click(Sender: TObject);
    procedure Chk2Click(Sender: TObject);
    procedure Chk1Click(Sender: TObject);
    procedure SeedChange(Sender: TObject);
    procedure ConvChange(Sender: TObject);
    procedure ConvClick(Sender: TObject);
    procedure TakeVal2Change(Sender: TObject);
    procedure TakeVal1Change(Sender: TObject);
    procedure AddValChange(Sender: TObject);
    procedure AddChar2Change(Sender: TObject);
    procedure AddChar1Change(Sender: TObject);
    procedure Opt9Click(Sender: TObject);
    procedure SplitValChange(Sender: TObject);
    procedure Opt8Click(Sender: TObject);
    procedure Opt10Click(Sender: TObject);
    procedure Opt11Click(Sender: TObject);
    procedure Opt12Click(Sender: TObject);
    procedure sBarChange(Sender: TObject);
    procedure Opt13Click(Sender: TObject);
    procedure Chk12Click(Sender: TObject);
    procedure Opt14Click(Sender: TObject);
    procedure Chk10Click(Sender: TObject);
    procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
      MousePos: TPoint; var Handled: Boolean);
    procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
      MousePos: TPoint; var Handled: Boolean);
    procedure LineCountChange(Sender: TObject);
    procedure LineCountEnter(Sender: TObject);
    procedure LineCountClick(Sender: TObject);
    procedure Opt16Click(Sender: TObject);
    procedure Opt17Click(Sender: TObject);
    procedure Opt18Click(Sender: TObject);
    procedure Opt15Click(Sender: TObject);
    procedure Opt19Click(Sender: TObject);
    procedure Opt20Click(Sender: TObject);
    procedure AddLinesChange(Sender: TObject);
    procedure RmvLinesChange(Sender: TObject);
    procedure Chk8Click(Sender: TObject);
    procedure Chk9Click(Sender: TObject);
    procedure FndTextChange(Sender: TObject);
    procedure RplTextChange(Sender: TObject);
    procedure SpltTxtChange(Sender: TObject);
    procedure Chk11Click(Sender: TObject);
    procedure SpltTxt2Change(Sender: TObject);
    procedure LeadCharsChange(Sender: TObject);
    procedure KeepCharsChange(Sender: TObject);
    procedure RmvCharsChange(Sender: TObject);
    procedure RmvCharsToCharsChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure GUIControl;
    procedure LineCounter;
  end;

var
  nOpts: TnOpts;

implementation

uses Unit1;

{$R *.dfm}

procedure TnOpts.GUIControl;
begin
AddChar1.Enabled := Opt1.Checked;
Label1.Enabled := Opt1.Checked;
Chk1.Enabled := Opt1.Checked;
Chk2.Enabled := Opt1.Checked;
AddChar2.Enabled := Opt2.Checked;
Label3.Enabled := Opt2.Checked;
Chk3.Enabled := Opt2.Checked;
Chk4.Enabled := Opt2.Checked;
AddVal.Enabled := Opt3.Checked;
Label5.Enabled := Opt3.Checked;
TakeVal1.Enabled := Opt4.Checked;
Label7.Enabled := Opt4.Checked;
Chk5.Enabled := Opt4.Checked;
Label8.Enabled := Opt4.Checked;
TakeVal2.Enabled := Opt5.Checked;
Label13.Enabled := Opt5.Checked;
Chk6.Enabled := Opt5.Checked;
Label14.Enabled := Opt5.Checked;
Conv.Enabled := Opt6.Checked;
Seed.Enabled := Opt7.Checked;
Label11.Enabled := Opt7.Checked;
Chk7.Enabled := Opt7.Checked;
SplitVal.Enabled := Opt8.Checked;
splitLabel.Enabled := Opt8.Checked;
AddLines.Enabled := Opt10.Checked;
Label18.Enabled := Opt10.Checked;
RmvLines.Enabled := Opt11.Checked;
Label20.Enabled := Opt11.Checked;
Chk8.Enabled := Opt11.Checked;
FndText.Enabled := Opt12.Checked;
Label22.Enabled := Opt12.Checked;
RplText.Enabled := Opt12.Checked;
Chk9.Enabled := Opt12.Checked;
Chk10.Enabled := Opt12.Checked;
SpltTxt.Enabled := Opt13.Checked;
Chk12.Enabled := Opt13.Checked;
Chk11.Enabled := Opt14.Checked;
SpltTxt2.Enabled := Opt15.Checked;
LineCount.Enabled := Opt16.Checked;
KeepChars.Enabled := Opt17.Checked;
RmvChars.Enabled := Opt18.Checked;
SpltTxt2.Enabled := Opt15.Checked;
RmvCharsToChars.Enabled := Opt20.Checked;
if Opt1.Checked then
 begin
  Main.Stat.Panels[0].Text := 'Add Leading Chars (' +AddChar1.Text + ');';
  if Chk1.Checked then
   begin
    if Chk2.Checked then Main.Stat.Panels[0].Text := Main.Stat.Panels[0].Text + ' Reversed Suffix'
    else Main.Stat.Panels[0].Text := Main.Stat.Panels[0].Text + ' Add Suffix';
   end;
 end
else if Opt2.Checked then 
 begin
  Main.Stat.Panels[0].Text := 'Add Trailing Chars (' +AddChar2.Text + ');';
  if Chk3.Checked then
   begin
    if Chk4.Checked then Main.Stat.Panels[0].Text := Main.Stat.Panels[0].Text + ' Reversed Prefix'
    else Main.Stat.Panels[0].Text := Main.Stat.Panels[0].Text + ' Add Prefix';
   end
 end
else if Opt3.Checked then Main.Stat.Panels[0].Text := 'Add ' + IntToStr(AddVal.Value) + ' Spaces'
else if Opt4.Checked then
 begin
  Main.Stat.Panels[0].Text := 'Take ' + IntToStr(TakeVal1.Value) + ' Leading Spaces;';
  if Chk5.Checked then Main.Stat.Panels[0].Text := Main.Stat.Panels[0].Text + ' Take Leading Chars';
 end
else if Opt5.Checked then
 begin
  Main.Stat.Panels[0].Text := 'Take ' + IntToStr(TakeVal2.Value) + ' Trailing Spaces;';
  if Chk6.Checked then Main.Stat.Panels[0].Text := Main.Stat.Panels[0].Text + ' Take Trailing Chars';
 end
else if Opt6.Checked then Main.Stat.Panels[0].Text := 'Convert all to ' + Conv.Text
else if Opt7.Checked then
 begin
  Main.Stat.Panels[0].Text := 'Generate ' + IntToStr(Seed.Value) + ' random characters;';
  if Chk7.Checked then Main.Stat.Panels[0].Text := Main.Stat.Panels[0].Text + '  New Line';
 end
else if Opt8.Checked then Main.Stat.Panels[0].Text := 'Lines split after ' + IntToStr(SplitVal.Value) + ' characters'
else if Opt9.Checked then Main.Stat.Panels[0].Text := 'Remove blank lines!.'
else if Opt10.Checked then Main.Stat.Panels[0].Text := 'Add ' + IntToStr(AddLines.Value) + ' lines!.'
else if Opt11.Checked then
 begin
  if Chk8.Checked then Main.Stat.Panels[0].Text := 'Remove ' + IntToStr(RmvLines.Value) + ' lines and characters!.'
  else Main.Stat.Panels[0].Text := 'Remove ' + IntToStr(RmvLines.Value) + ' lines!.';
 end
else if Opt12.Checked then
 begin
  if Chk9.Checked then
   begin
    if Chk10.Checked then Main.Stat.Panels[0].Text := 'Convert all (Matching Case, Whole Word) ' + FndText.Text + '''s to ' + RplText.Text + '!.'
    else Main.Stat.Panels[0].Text := 'Convert all (Matching Case) ' + FndText.Text + '''s to ' + RplText.Text + '!.'
   end
  else
   begin
    if Chk10.Checked then Main.Stat.Panels[0].Text := 'Convert all (Whole Word) ' + FndText.Text + '''s to ' + RplText.Text + '!.'
    else Main.Stat.Panels[0].Text := 'Convert all ' + FndText.Text + '''s to ' + RplText.Text + '!.';
   end
 end
else if Opt13.Checked then
 begin
  if Chk12.Checked then Main.Stat.Panels[0].Text := 'Split lines after the characters "' + SpltTxt.Text + '" only if more characters exist after split position.'
  else Main.Stat.Panels[0].Text := 'Split lines after the characters "' + SpltTxt.Text + '"';
 end
else if Opt14.Checked then
 begin
  if Chk11.Checked then Main.Stat.Panels[0].Text := 'Insert ascending numeral values, starting with ' + LeadChars.Text
  else Main.Stat.Panels[0].Text := 'Insert ascending numeral values.';
 end
else if Opt15.Checked then Main.Stat.Panels[0].Text := 'Split lines before the characters "' + SpltTxt2.Text + '"'
else if Opt16.Checked then Main.Stat.Panels[0].Text := 'Remove every ' + LineCount.Text + Label28.Caption
else if Opt17.Checked then Main.Stat.Panels[0].Text := 'Remove line/s that do not contain "' + KeepChars.Text + '"'
else if Opt18.Checked then Main.Stat.Panels[0].Text := 'Remove line/s that contain the characters "' + RmvChars.Text + '"'
else if Opt19.Checked then Main.Stat.Panels[0].Text := 'Remove all duplicate lines.'
else Main.Stat.Panels[0].Text := 'Remove all characters on line/s up to and including the character "' + RmvCharsToChars.Text + '"';
end;

procedure TnOpts.LineCounter;
begin
if LineCount.Value <= 1 then LineCount.Value := 2;
if (LineCount.Value <> 12) and (Copy(LineCount.Text, LineCount.GetTextLen, 1) = '2') then Label28.Caption := 'nd line.'
else if (LineCount.Value <> 13) and (Copy(LineCount.Text, LineCount.GetTextLen, 1) = '3') then Label28.Caption := 'rd line.'
else if (LineCount.Value <> 11) and (Copy(LineCount.Text, LineCount.GetTextLen, 1) = '1') then Label28.Caption := 'st line.'
else Label28.Caption := 'th line.';
end;

procedure TnOpts.Opt1Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt2Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt3Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt4Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt5Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt6Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt7Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk7Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk6Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk5Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk4Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk3Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk2Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk1Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.SeedChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.ConvChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.ConvClick(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.TakeVal2Change(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.TakeVal1Change(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.AddValChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.AddChar2Change(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.AddChar1Change(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt9Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.SplitValChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt8Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt10Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt11Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt12Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.sBarChange(Sender: TObject);
begin
if sBar.Tag < sBar.Position then Panel1.Top := Panel1.Top -(sBar.Position -sBar.Tag)
else if sBar.Tag > sBar.Position then Panel1.Top := Panel1.Top +(sBar.Tag -sBar.Position);
sBar.Tag := sBar.Position;
end;

procedure TnOpts.Opt13Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk12Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt14Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk10Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
  MousePos: TPoint; var Handled: Boolean);
begin
sBar.Position := sBar.Position +5;
end;

procedure TnOpts.FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
  MousePos: TPoint; var Handled: Boolean);
begin
sBar.Position := sBar.Position -5;
end;

procedure TnOpts.LineCountChange(Sender: TObject);
begin
LineCounter;
GUIControl;
end;

procedure TnOpts.LineCountEnter(Sender: TObject);
begin
LineCounter;
GUIControl;
end;

procedure TnOpts.LineCountClick(Sender: TObject);
begin
LineCounter;
GUIControl;
end;

procedure TnOpts.Opt16Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt17Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt18Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt15Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt19Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Opt20Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.AddLinesChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.RmvLinesChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk8Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk9Click(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.FndTextChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.RplTextChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.SpltTxtChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.Chk11Click(Sender: TObject);
begin
GUIControl;
LeadChars.Enabled := Chk11.Checked;
Label25.Enabled := Chk11.Checked;
end;

procedure TnOpts.SpltTxt2Change(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.LeadCharsChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.KeepCharsChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.RmvCharsChange(Sender: TObject);
begin
GUIControl;
end;

procedure TnOpts.RmvCharsToCharsChange(Sender: TObject);
begin
GUIControl;
end;

end.

Open in new window


Unit2.dfm
object nOpts: TnOpts
  Left = 288
  Top = 80
  BorderIcons = [biSystemMenu]
  BorderStyle = bsSingle
  Caption = 'Notepad Options'
  ClientHeight = 515
  ClientWidth = 490
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poScreenCenter
  OnMouseWheelDown = FormMouseWheelDown
  OnMouseWheelUp = FormMouseWheelUp
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 465
    Height = 969
    BevelOuter = bvNone
    TabOrder = 0
    object Label1: TLabel
      Left = 184
      Top = 8
      Width = 134
      Height = 13
      Caption = 'to the begining of each line!.'
      Enabled = False
    end
    object Label2: TLabel
      Left = 16
      Top = 80
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label3: TLabel
      Left = 184
      Top = 96
      Width = 112
      Height = 13
      Caption = 'to the end of each line!.'
      Enabled = False
    end
    object Label4: TLabel
      Left = 16
      Top = 168
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label5: TLabel
      Left = 144
      Top = 184
      Width = 171
      Height = 13
      Caption = 'spaces to the begining of each line!.'
    end
    object Label6: TLabel
      Left = 16
      Top = 208
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label7: TLabel
      Left = 144
      Top = 224
      Width = 34
      Height = 13
      Caption = 'spaces'
      Enabled = False
    end
    object Label8: TLabel
      Left = 283
      Top = 224
      Width = 145
      Height = 13
      Caption = 'from the begining of each line!.'
      Enabled = False
    end
    object Label9: TLabel
      Left = 16
      Top = 288
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label10: TLabel
      Left = 16
      Top = 328
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label11: TLabel
      Left = 168
      Top = 344
      Width = 85
      Height = 13
      Caption = 'random charactes'
      Enabled = False
    end
    object Label12: TLabel
      Left = 16
      Top = 248
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label13: TLabel
      Left = 144
      Top = 264
      Width = 34
      Height = 13
      Caption = 'spaces'
      Enabled = False
    end
    object Label14: TLabel
      Left = 283
      Top = 264
      Width = 123
      Height = 13
      Caption = 'from the end of each line!.'
      Enabled = False
    end
    object Label15: TLabel
      Left = 16
      Top = 368
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object splitLabel: TLabel
      Left = 182
      Top = 384
      Width = 113
      Height = 13
      Caption = 'characters in each line!.'
    end
    object Label16: TLabel
      Left = 16
      Top = 408
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label17: TLabel
      Left = 16
      Top = 448
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label18: TLabel
      Left = 144
      Top = 464
      Width = 106
      Height = 13
      Caption = 'lines to the begining!...'
      Enabled = False
    end
    object Label19: TLabel
      Left = 16
      Top = 488
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label20: TLabel
      Left = 160
      Top = 505
      Width = 21
      Height = 13
      Caption = 'lines'
      Enabled = False
    end
    object Label21: TLabel
      Left = 16
      Top = 528
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label22: TLabel
      Left = 368
      Top = 545
      Width = 9
      Height = 13
      Caption = 'to'
      Enabled = False
    end
    object Label23: TLabel
      Left = 16
      Top = 568
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label24: TLabel
      Left = 16
      Top = 648
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label25: TLabel
      Left = 336
      Top = 664
      Width = 106
      Height = 13
      Caption = 'leading each insertion.'
      Enabled = False
    end
    object Label26: TLabel
      Left = 16
      Top = 608
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label27: TLabel
      Left = 16
      Top = 688
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label28: TLabel
      Left = 168
      Top = 706
      Width = 31
      Height = 13
      Caption = 'nd line'
    end
    object Label29: TLabel
      Left = 16
      Top = 728
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label30: TLabel
      Left = 16
      Top = 768
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label31: TLabel
      Left = 16
      Top = 808
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label32: TLabel
      Left = 16
      Top = 848
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label33: TLabel
      Left = 16
      Top = 888
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label34: TLabel
      Left = 16
      Top = 928
      Width = 11
      Height = 13
      Caption = 'Or'
    end
    object Label35: TLabel
      Left = 120
      Top = 945
      Width = 111
      Height = 13
      Caption = 'line if all characters are '
    end
    object Opt1: TRadioButton
      Left = 8
      Top = 8
      Width = 41
      Height = 17
      Caption = 'Add'
      TabOrder = 0
      OnClick = Opt1Click
    end
    object AddChar1: TEdit
      Left = 56
      Top = 5
      Width = 121
      Height = 21
      Enabled = False
      TabOrder = 1
      Text = '//'
      OnChange = AddChar1Change
    end
    object Chk1: TCheckBox
      Left = 24
      Top = 32
      Width = 153
      Height = 17
      Caption = 'and to the end of each line!.'
      Enabled = False
      TabOrder = 2
      OnClick = Chk1Click
    end
    object Chk2: TCheckBox
      Left = 24
      Top = 56
      Width = 289
      Height = 17
      Caption = 'Reverse string before adding to end of line!. (a bc = cb a)'
      Enabled = False
      TabOrder = 3
      OnClick = Chk2Click
    end
    object Opt2: TRadioButton
      Left = 8
      Top = 96
      Width = 41
      Height = 17
      Caption = 'Add'
      TabOrder = 4
      OnClick = Opt2Click
    end
    object AddChar2: TEdit
      Left = 56
      Top = 93
      Width = 121
      Height = 21
      Enabled = False
      TabOrder = 5
      Text = '//'
      OnChange = AddChar2Change
    end
    object Chk3: TCheckBox
      Left = 24
      Top = 120
      Width = 177
      Height = 17
      Caption = 'and to the begining of each line!.'
      Enabled = False
      TabOrder = 6
      OnClick = Chk3Click
    end
    object Chk4: TCheckBox
      Left = 24
      Top = 144
      Width = 313
      Height = 17
      Caption = 'Reverse string before adding to begining of line!. (a bc = cb a)'
      Enabled = False
      TabOrder = 7
      OnClick = Chk4Click
    end
    object Opt3: TRadioButton
      Left = 8
      Top = 184
      Width = 41
      Height = 17
      Caption = 'Add'
      Checked = True
      TabOrder = 8
      TabStop = True
      OnClick = Opt3Click
    end
    object AddVal: TSpinEdit
      Left = 56
      Top = 181
      Width = 81
      Height = 22
      MaxValue = 255
      MinValue = 1
      TabOrder = 9
      Value = 1
      OnChange = AddValChange
    end
    object Opt4: TRadioButton
      Left = 8
      Top = 224
      Width = 49
      Height = 17
      Caption = 'Take'
      TabOrder = 10
      OnClick = Opt4Click
    end
    object TakeVal1: TSpinEdit
      Left = 56
      Top = 220
      Width = 81
      Height = 22
      Enabled = False
      MaxValue = 255
      MinValue = 1
      TabOrder = 11
      Value = 1
      OnChange = TakeVal1Change
    end
    object Chk5: TCheckBox
      Left = 184
      Top = 223
      Width = 97
      Height = 17
      Caption = '(and characters)'
      Enabled = False
      TabOrder = 12
      OnClick = Chk5Click
    end
    object Opt6: TRadioButton
      Left = 8
      Top = 304
      Width = 81
      Height = 17
      Caption = 'Convert all to'
      TabOrder = 13
      OnClick = Opt6Click
    end
    object Conv: TComboBox
      Left = 96
      Top = 301
      Width = 145
      Height = 21
      Enabled = False
      ItemHeight = 13
      ItemIndex = 0
      TabOrder = 14
      Text = 'Lowercase!.'
      OnChange = ConvChange
      OnClick = ConvClick
      Items.Strings = (
        'Lowercase!.'
        'Uppercase!.'
        'ASCII'
        'Hexadecimal!.'
        'Binary!.'
        'HTML/Javascript Escape!.'
        'HTML/Javascript Unescape!.'
        'String!.')
    end
    object Opt7: TRadioButton
      Left = 8
      Top = 344
      Width = 65
      Height = 17
      Caption = 'Generate'
      TabOrder = 15
      OnClick = Opt7Click
    end
    object Seed: TSpinEdit
      Left = 80
      Top = 341
      Width = 81
      Height = 22
      Enabled = False
      MaxValue = 255
      MinValue = 1
      TabOrder = 16
      Value = 32
      OnChange = SeedChange
    end
    object Chk7: TCheckBox
      Left = 256
      Top = 343
      Width = 89
      Height = 17
      Caption = 'on a new line!.'
      Enabled = False
      TabOrder = 17
      OnClick = Chk7Click
    end
    object Opt5: TRadioButton
      Left = 8
      Top = 264
      Width = 49
      Height = 17
      Caption = 'Take'
      TabOrder = 18
      OnClick = Opt5Click
    end
    object TakeVal2: TSpinEdit
      Left = 56
      Top = 261
      Width = 81
      Height = 22
      Enabled = False
      MaxValue = 255
      MinValue = 1
      TabOrder = 19
      Value = 1
      OnChange = TakeVal2Change
    end
    object Chk6: TCheckBox
      Left = 184
      Top = 263
      Width = 97
      Height = 17
      Caption = '(and characters)'
      Enabled = False
      TabOrder = 20
      OnClick = Chk6Click
    end
    object Opt9: TRadioButton
      Left = 8
      Top = 424
      Width = 177
      Height = 17
      Caption = 'Remove only blank (empty) lines!.'
      TabOrder = 21
      OnClick = Opt9Click
    end
    object Opt8: TRadioButton
      Left = 8
      Top = 384
      Width = 81
      Height = 17
      Caption = 'Split line after'
      TabOrder = 22
      OnClick = Opt8Click
    end
    object SplitVal: TSpinEdit
      Left = 97
      Top = 381
      Width = 81
      Height = 22
      MaxValue = 5000
      MinValue = 1
      TabOrder = 23
      Value = 64
      OnChange = SplitValChange
    end
    object Opt10: TRadioButton
      Left = 8
      Top = 463
      Width = 41
      Height = 17
      Caption = 'Add'
      TabOrder = 24
      OnClick = Opt10Click
    end
    object AddLines: TSpinEdit
      Left = 54
      Top = 461
      Width = 81
      Height = 22
      Enabled = False
      MaxValue = 255
      MinValue = 1
      TabOrder = 25
      Value = 1
      OnChange = AddLinesChange
    end
    object Opt11: TRadioButton
      Left = 8
      Top = 504
      Width = 65
      Height = 17
      Caption = 'Remove'
      TabOrder = 26
      OnClick = Opt11Click
    end
    object RmvLines: TSpinEdit
      Left = 72
      Top = 501
      Width = 81
      Height = 22
      Enabled = False
      MaxValue = 255
      MinValue = 1
      TabOrder = 27
      Value = 1
      OnChange = RmvLinesChange
    end
    object Chk8: TCheckBox
      Left = 187
      Top = 504
      Width = 190
      Height = 17
      Caption = '(and characters) from the begining!...'
      Enabled = False
      TabOrder = 28
      OnClick = Chk8Click
    end
    object Opt12: TRadioButton
      Left = 8
      Top = 544
      Width = 73
      Height = 17
      Caption = 'Convert all'
      TabOrder = 29
      OnClick = Opt12Click
    end
    object FndText: TEdit
      Left = 179
      Top = 541
      Width = 78
      Height = 21
      Enabled = False
      TabOrder = 30
      OnChange = FndTextChange
    end
    object RplText: TEdit
      Left = 384
      Top = 541
      Width = 81
      Height = 21
      Enabled = False
      TabOrder = 31
      OnChange = RplTextChange
    end
    object Chk9: TCheckBox
      Left = 81
      Top = 544
      Width = 97
      Height = 17
      Caption = '(matching case)'
      Checked = True
      Enabled = False
      State = cbChecked
      TabOrder = 32
      OnClick = Chk9Click
    end
    object Chk10: TCheckBox
      Left = 264
      Top = 544
      Width = 97
      Height = 17
      Caption = '(as whole words)'
      Enabled = False
      TabOrder = 33
      OnClick = Chk10Click
    end
    object Opt13: TRadioButton
      Left = 8
      Top = 584
      Width = 169
      Height = 17
      Caption = 'Split line/s after the characters '
      TabOrder = 34
      OnClick = Opt13Click
    end
    object SpltTxt: TEdit
      Left = 176
      Top = 581
      Width = 49
      Height = 21
      Enabled = False
      TabOrder = 35
      OnChange = SpltTxtChange
    end
    object Opt14: TRadioButton
      Left = 8
      Top = 664
      Width = 153
      Height = 17
      Caption = 'Incremental number insertion'
      TabOrder = 36
      OnClick = Opt14Click
    end
    object Chk11: TCheckBox
      Left = 168
      Top = 664
      Width = 137
      Height = 17
      Caption = 'and with the character/s'
      Enabled = False
      TabOrder = 37
      OnClick = Chk11Click
    end
    object LeadChars: TEdit
      Left = 307
      Top = 661
      Width = 25
      Height = 21
      Enabled = False
      MaxLength = 1
      TabOrder = 38
      Text = 'C0'
      OnChange = LeadCharsChange
    end
    object Chk12: TCheckBox
      Left = 228
      Top = 584
      Width = 237
      Height = 17
      Caption = 'only if more characters exist after split position'
      Checked = True
      Enabled = False
      State = cbChecked
      TabOrder = 39
      OnClick = Chk12Click
    end
    object Opt15: TRadioButton
      Left = 8
      Top = 624
      Width = 177
      Height = 17
      Caption = 'Split line/s before the characters'
      TabOrder = 40
      OnClick = Opt15Click
    end
    object SpltTxt2: TEdit
      Left = 184
      Top = 623
      Width = 49
      Height = 21
      Enabled = False
      TabOrder = 41
      OnChange = SpltTxt2Change
    end
    object Opt16: TRadioButton
      Left = 8
      Top = 704
      Width = 89
      Height = 17
      Caption = 'Remove every'
      TabOrder = 42
      OnClick = Opt16Click
    end
    object LineCount: TSpinEdit
      Left = 104
      Top = 704
      Width = 65
      Height = 22
      Enabled = False
      MaxValue = 0
      MinValue = 0
      TabOrder = 43
      Value = 2
      OnChange = LineCountChange
      OnClick = LineCountClick
      OnEnter = LineCountEnter
    end
    object Opt17: TRadioButton
      Left = 8
      Top = 744
      Width = 257
      Height = 17
      Caption = 'Remove line/s that do not contain the characters'
      TabOrder = 44
      OnClick = Opt17Click
    end
    object KeepChars: TEdit
      Left = 264
      Top = 742
      Width = 121
      Height = 21
      Enabled = False
      TabOrder = 45
      OnChange = KeepCharsChange
    end
    object Opt18: TRadioButton
      Left = 8
      Top = 784
      Width = 217
      Height = 17
      Caption = 'Remove line/s that contain the characters'
      TabOrder = 46
      OnClick = Opt18Click
    end
    object RmvChars: TEdit
      Left = 232
      Top = 782
      Width = 121
      Height = 21
      TabOrder = 47
      OnChange = RmvCharsChange
    end
    object Opt19: TRadioButton
      Left = 8
      Top = 824
      Width = 129
      Height = 17
      Caption = 'Remove duplicate lines'
      TabOrder = 48
      OnClick = Opt19Click
    end
    object Opt20: TRadioButton
      Left = 8
      Top = 864
      Width = 201
      Height = 17
      Caption = 'Remove all characters on line/s up to'
      TabOrder = 49
      OnClick = Opt20Click
    end
    object RmvCharsToChars: TEdit
      Left = 208
      Top = 864
      Width = 121
      Height = 21
      Enabled = False
      TabOrder = 50
      OnChange = RmvCharsToCharsChange
    end
    object Opt21: TRadioButton
      Left = 8
      Top = 904
      Width = 129
      Height = 17
      Caption = 'Remove all line breaks'
      TabOrder = 51
    end
    object Opt22: TRadioButton
      Left = 8
      Top = 944
      Width = 49
      Height = 17
      Caption = 'Break'
      TabOrder = 52
    end
    object brklnchr: TComboBox
      Left = 232
      Top = 941
      Width = 81
      Height = 21
      ItemHeight = 13
      ItemIndex = 0
      TabOrder = 53
      Text = 'Uppercase'
      Items.Strings = (
        'Uppercase'
        'Lowercase')
    end
    object Chk13: TCheckBox
      Left = 320
      Top = 944
      Width = 137
      Height = 17
      Caption = 'and including numerals.'
      TabOrder = 54
    end
    object BrkPos: TComboBox
      Left = 59
      Top = 941
      Width = 57
      Height = 21
      ItemHeight = 13
      ItemIndex = 0
      TabOrder = 55
      Text = 'Before'
      Items.Strings = (
        'Before'
        'After')
    end
  end
  object sBar: TScrollBar
    Left = 472
    Top = 0
    Width = 17
    Height = 257
    Kind = sbVertical
    Max = 457
    PageSize = 0
    TabOrder = 1
    OnChange = sBarChange
  end
end

Open in new window


Global.pas
unit Global;

interface

uses SysUtils, Classes;

type xRange = array [0..1] of integer;

var
   xEncRslt: TStringList;
   function GetCaretPos: integer;
   function iRandom(Range: xRange): integer;
   function UrlEncode(const DecodedStr: ansistring): ansistring;
   function UrlDecode(const EncodedStr: ansistring): ansistring;
   function HexToInt(HexStr: ansistring): Int64;

implementation

uses Unit1;

function GetCaretPos: integer;
var X, Y, rslt: integer;
begin
rslt := 0;
Y := Main.Notes.CaretPos.Y -1;
for X := 0 to Y do rslt := rslt +Length(Main.Notes.Lines.Strings[X]);
rslt := rslt +Main.Notes.CaretPos.X;
result := rslt;
end;

function iRandom(Range: xRange): integer;
begin
result := Random(Range[1] -Range[0] +1) +Range[0];
end;

function UrlEncode(const DecodedStr: ansistring): ansistring;
var i: Integer;
begin
result := '';
if Length(DecodedStr) > 0 then
 begin
  for i := 1 to Length(DecodedStr) do
   begin
    if not (DecodedStr[i] in ['0'..'9', 'a'..'z', 'A'..'Z']) then result := result + '%' + IntToHex(Ord(DecodedStr[i]), 2)
    else if not (DecodedStr[i] = ' ') then result := result + DecodedStr[i]
   end
 end
else result := result + '%20'
end;

function UrlDecode(const EncodedStr: ansistring): ansistring;
var i: Integer;
begin
result := '';
if Length(EncodedStr) > 0 then
 begin
  i := 1;
  while i <= Length(EncodedStr) do
   begin
    if EncodedStr[I] = '%' then
     begin
      result := result + Chr(HexToInt(EncodedStr[i +1] + EncodedStr[i +2]));
      i := Succ(Succ(i));
     end
    else result := result + EncodedStr[i];
    i := Succ(i);
   end
 end
end; 

function HexToInt(HexStr: ansistring): Int64;
var RetVar: Int64;
i: byte;
begin
HexStr := UpperCase(HexStr);
if HexStr[length(HexStr)] = 'H' then Delete(HexStr, length(HexStr), 1);
 RetVar := 0;

for i := 1 to length(HexStr) do
 begin
  RetVar := RetVar shl 4;
  if HexStr[i] in ['0'..'9'] then RetVar := RetVar + (byte(HexStr[i]) - 48)
  else if HexStr[i] in ['A'..'F'] then RetVar := RetVar + (byte(HexStr[i]) - 55)
  else
   begin
    Retvar := 0;
    break;
   end
 end;
 result := RetVar;
end;


end.
 

Open in new window


BinConv.pas
unit BinConv;

interface

uses SysUtils;

function Bin2Hex(var BinVal: ansistring): ansistring;
function Hex2Bin(const Hex: ansistring): ansistring;
function IsBinary(const Value: ansistring): boolean;

const ChkBin: array[0..15, 0..1] of string =
    (('0000', '0'), ('0001', '1'), ('0010', '2'), ('0011', '3'),
     ('0100', '4'), ('0101', '5'), ('0110', '6'), ('0111', '7'),
     ('1000', '8'), ('1001', '9'), ('1010', 'a'), ('1011', 'b'),
     ('1100', 'c'), ('1101', 'd'), ('1110', 'e'), ('1111', 'f'));

implementation

function Bin2Hex(var BinVal: ansistring): ansistring;
var X: integer;
Seg: string;
begin
result := '';
if IsBinary(BinVal) then
 begin
  case Length(BinVal) mod 4 of
   1: BinVal := '000' +BinVal;
   2: BinVal := '00' +BinVal;
   3: BinVal := '0' +BinVal;
  end;
  while Length(BinVal) > 0 do
   begin
    Seg := Copy(BinVal, Length(BinVal) -3, 4);
    Delete(BinVal, Length(BinVal) -3, 4);
    for X := 1 to 16 do
     begin
      if Seg = ChkBin[X -1, 0] then result := ChkBin[X -1, 1] +result;
     end
   end
 end
end;

function IntToBin(Num: Int64): ansistring;
var Bits: integer;
Tmp, Rslt: ansistring;
begin
Tmp := FloatToStr(Num);
Bits := SizeOf(Tmp) *2;
Rslt := StringOfChar('0', Bits);
while Num >= 1 do
 begin
  if (Num and 1) = 1 then Rslt[Bits] := '1';
  Dec(Bits);
  Num := Num shr 1;
 end;
 result := Rslt;
end;

function Hex2Bin(const Hex: ansistring): ansistring;
var X, Cpy: integer;
Tmp: ansistring;
begin
X := 1;
Tmp := '';
while X <= Length(Hex) do
 begin
  Cpy := Ord(Hex[X]);
  Tmp := Tmp +IntToBin(Cpy);
  Inc(X);
 end;
 result := Tmp;
end;

function IsBinary(const Value: ansistring): boolean;
var X: integer;
begin
if trim(Value) <> '' then result := true
else result := false; 
for X := 1 to Length(Value) do
 begin
  if not (Value[X] in ['0', '1']) then
   begin
    result := false;
    exit;
   end;
 end;
end;

end.

Open in new window


intutil.pas
unit intutil;

interface

uses SysUtils, Dialogs;

procedure chkint(const Num: string; out GoodNum: string; const AllowNegative, Correct, DispMsg: boolean);
function isint(const Value: ansistring; const isFloat, isNegative: boolean): boolean;
function xInc(var Num: ansistring): ansistring;

const intchar = '0123456789';

implementation

procedure chkint(const Num: ansistring; out GoodNum: ansistring; const AllowNegative, Correct, DispMsg: boolean);
var X, Y: Int64;
NumCpy: ansistring;
Fnd, DeciFnd, SlshFnd: boolean;
begin
X := 0;
NumCpy := trim(Num);
DeciFnd := false;
SlshFnd := false;
while X < Length(NumCpy) do
 begin
  Inc(X);
  Y := 0;
  Fnd := false;
  while Y <= Length(intchar) do
   begin
    Inc(Y);
    if NumCpy[X] = intchar[Y] then
     begin
      Fnd := true;
     end
    else
     begin
      if Y = Length(intchar) then
       begin
        if Fnd = false then
         begin
          if NumCpy[X] <> '.' then
           begin
            if AllowNegative then
             begin
              if NumCpy[X] <> '-' then
               begin
                if Correct then
                 begin
                  Delete(NumCpy, X, 1);
                  Dec(X);
                 end
                else
                 begin
                  if DispMsg then MessageDlg('Internal error... {' + NumCpy[X] + '}', mtError, [mbok], 0);
                  GoodNum := '#001';
                  exit;
                 end
               end
              else
               begin
                if not SlshFnd then SlshFnd := true
                else
                 begin
                  Delete(NumCpy, X, 1);
                  Dec(X);
                 end
               end
             end
            else
             begin
              if Correct then
               begin
                Delete(NumCpy, X, 1);
                Dec(X);
               end
              else
               begin
                if DispMsg then MessageDlg('Internal error... {' + NumCpy[X] + '}', mtError, [mbok], 0);
                GoodNum := '#001';
                exit;
               end
             end
           end
          else
           begin
            if not DeciFnd then DeciFnd := true
            else
             begin
              Delete(NumCpy, X, 1);
              Dec(X);
             end
           end
         end
       end
     end
   end
 end;
 if Copy(NumCpy, Length(NumCpy), 1) = '.' then NumCpy := NumCpy + '0'
 else if Copy(NumCpy, 1, 1) = '.' then NumCpy := '0' + NumCpy;
 GoodNum := NumCpy;
end;

function isint(const Value: ansistring; const isFloat, isNegative: boolean): boolean;
var X, Y, F: integer;
begin
F := 0;
result := true;
if trim(Value) = '' then
 begin
  result := false;
 end
else
 begin
  for X := 1 to Length(Value) do
   begin
    if F < 2 then
     begin
      F := 0;
      for Y := 1 to Length(intchar) do
       begin
        if Value[X] = intchar[Y] then
         begin
          F := 1;
         end
        else
         begin
          if (Value[X] <> '.') and (Value[X] <> '-') then
           begin
            if Y = Length(intchar) then
             begin
              if F = 0 then
               begin
                result := false;
                exit;
               end
             end
           end
          else
           begin
            if (Value[X] = '.') and not (isFloat) then
             begin
              result := false;
              exit;
             end;
             if (Value[X] = '-') and not (isNegative) then
              begin
               result := false;
               exit;
              end
           end
         end
       end
     end
   end
 end
end;

function xInc(var Num: ansistring): ansistring;
var X, Y, Pss, Cnt: Int64;
Z: integer;
Get, sPss: string;
Ngtv: boolean;
begin
Cnt := 0;
Ngtv := false;
X := Length(Num) +1;
if X > 1 then
 begin
  if Num[1] = '-' then
   begin
    Delete(Num, 1, 1);
    Ngtv := true;
    X := Length(Num) +1;
   end
 end;
 while X >= 1 do
  begin
   Dec(X);
   sPss := '';
   Get := Copy(Num, X, 1);
   if Get = '9' then
    begin
     if X <> 1 then
      begin
       Y := X -1;
       while Y >= 1 do
        begin
         sPss := Copy(Num, Y, 1);
         if sPss <> '9' then
          begin
           if sPss = '.' then Num[Y] := '.'
           else
            begin
             Pss := StrToInt(sPss);
             Inc(Pss);
             sPss := IntToStr(Pss);
             Num[Y] := sPss[1];
             for Z := Length(Num) downto Y +1 do
              begin
               if Num[Z] = '.' then Num[Z] := '.'
               else Num[Z] := '0';
              end;
              Cnt := 0;
              X := 0;
              Y := 0;
            end
          end
         else
          begin
           Inc(Cnt);
           if Cnt = Length(Num) then
            begin
             for Z := Length(Num) downto 1 do
              begin
               if Num[Z] = '.' then Num[Z] := '.'
               else Num[Z] := '0';
              end;
              Num := '1' + Num;
              Cnt := 0;
              X := 0;
              Y := 0;
            end
          end;
          Dec(Y);
        end
      end
     else
      begin
       for Z := Length(Num) downto 1 do
        begin
         if Num[Z] = '.' then Num[Z] := '.'
         else Num[Z] := '0';
        end;
        Num := '1' + Num;
        X := X -2;
      end
    end
   else
    begin
     if Get = '.' then Num[X] := '.'
     else
      begin
       Pss := StrToInt(Get);
       Inc(Pss);
       sPss := IntToStr(Pss);
       Num[X] := sPss[1];
       X := 0;
      end
    end
  end;
  if Ngtv then
   begin
    if Num <> '0' then Num := '-' +Num;
   end
  else Num := Num;
  chkint(Num, result, true, true, false);
end;

end.

Open in new window

have you ever heard of circular unit reference and code reusability ?
well ... you have both problems

either move this "function GetCaretPos: integer;" to unit1
or
make it a really global function like this:

function GetCaretPos(aMemo: TMemo): integer;
var X, Y, rslt: integer;
begin
  rslt := 0;
  Y := aMemo.CaretPos.Y -1;
  for X := 0 to Y do 
    rslt := rslt +Length(aMemo.Lines.Strings[X]);
  rslt := rslt +aMemo.CaretPos.X;
  result := rslt;
end;

Open in new window


now your globals.pas can be reused in other projects, even after you rename unit1 to something meaningfull
you have writting your own conversion routines ?
wow.

this is the code i use:

uses Math;

Open in new window


and i don't need to type anything for BinToHex > I use the procedures from the Classes unit

Learn what there is, before reinventing the wheel ...
Hi Geert,

I fully understand your point about the GetCaretPos function and it is duly noted, i ask to learn mate.

But this is a copy of my (or a portion of) math unit, im not seeing much to my use within it sorry, perhaps my version of delphi is too old?

uses SysUtils, Types;

const   { Ranges of the IEEE floating point types, including denormals }
  MinSingle   =  1.5e-45;
  MaxSingle   =  3.4e+38;
  MinDouble   =  5.0e-324;
  MaxDouble   =  1.7e+308;
  MinExtended =  3.4e-4932;
  MaxExtended =  1.1e+4932;
  MinComp     = -9.223372036854775807e+18;
  MaxComp     =  9.223372036854775807e+18;

  { The following constants should not be used for comparison, only
    assignments. For comparison please use the IsNan and IsInfinity functions
    provided below. }
  NaN         =  0.0 / 0.0;
  Infinity    =  1.0 / 0.0;
  NegInfinity = -1.0 / 0.0;

{ Trigonometric functions }
function ArcCos(const X: Extended): Extended;  { IN: |X| <= 1  OUT: [0..PI] radians }
function ArcSin(const X: Extended): Extended;  { IN: |X| <= 1  OUT: [-PI/2..PI/2] radians }

{ ArcTan2 calculates ArcTan(Y/X), and returns an angle in the correct quadrant.
  IN: |Y| < 2^64, |X| < 2^64, X <> 0   OUT: [-PI..PI] radians }
function ArcTan2(const Y, X: Extended): Extended;

{ SinCos is 2x faster than calling Sin and Cos separately for the same angle }
procedure SinCos(const Theta: Extended; var Sin, Cos: Extended) register;
function Tan(const X: Extended): Extended;
function Cotan(const X: Extended): Extended;           { 1 / tan(X), X <> 0 }
function Secant(const X: Extended): Extended;          { 1 / cos(X) }
function Cosecant(const X: Extended): Extended;        { 1 / sin(X) }
function Hypot(const X, Y: Extended): Extended;        { Sqrt(X**2 + Y**2) }

{ Angle unit conversion routines }
function RadToDeg(const Radians: Extended): Extended;  { Degrees := Radians * 180 / PI }
function RadToGrad(const Radians: Extended): Extended; { Grads := Radians * 200 / PI }
function RadToCycle(const Radians: Extended): Extended;{ Cycles := Radians / 2PI }

function DegToRad(const Degrees: Extended): Extended;  { Radians := Degrees * PI / 180}
function DegToGrad(const Degrees: Extended): Extended;
function DegToCycle(const Degrees: Extended): Extended;

function GradToRad(const Grads: Extended): Extended;   { Radians := Grads * PI / 200 }
function GradToDeg(const Grads: Extended): Extended;
function GradToCycle(const Grads: Extended): Extended;

function CycleToRad(const Cycles: Extended): Extended; { Radians := Cycles * 2PI }
function CycleToDeg(const Cycles: Extended): Extended;
function CycleToGrad(const Cycles: Extended): Extended;

{ Hyperbolic functions and inverses }
function Cot(const X: Extended): Extended;             { simply calls Cotan }
function Sec(const X: Extended): Extended;             { simply calls Secant }
function Csc(const X: Extended): Extended;             { simply calls Cosecant }
function Cosh(const X: Extended): Extended;
function Sinh(const X: Extended): Extended;
function Tanh(const X: Extended): Extended;
function CotH(const X: Extended): Extended;
function SecH(const X: Extended): Extended;
function CscH(const X: Extended): Extended;
function ArcCot(const X: Extended): Extended;
function ArcSec(const X: Extended): Extended;
function ArcCsc(const X: Extended): Extended;
function ArcCosh(const X: Extended): Extended;         { IN: X >= 1 }
function ArcSinh(const X: Extended): Extended;
function ArcTanh(const X: Extended): Extended;         { IN: |X| <= 1 }
function ArcCotH(const X: Extended): Extended;
function ArcSecH(const X: Extended): Extended;
function ArcCscH(const X: Extended): Extended;

{ Logorithmic functions }
function LnXP1(const X: Extended): Extended; { Ln(X + 1), accurate for X near zero }
function Log10(const X: Extended): Extended;                    { Log base 10 of X }
function Log2(const X: Extended): Extended;                      { Log base 2 of X }
function LogN(const Base, X: Extended): Extended;                { Log base N of X }

{ Exponential functions }

{ IntPower: Raise base to an integral power.  Fast. }
function IntPower(const Base: Extended; const Exponent: Integer): Extended register;

{ Power: Raise base to any power.
  For fractional exponents, or |exponents| > MaxInt, base must be > 0. }
function Power(const Base, Exponent: Extended): Extended;

{ Miscellaneous Routines }

{ Frexp:  Separates the mantissa and exponent of X. }
procedure Frexp(const X: Extended; var Mantissa: Extended; var Exponent: Integer) register;

{ Ldexp: returns X*2**P }
function Ldexp(const X: Extended; const P: Integer): Extended register;

{ Ceil: Smallest integer >= X, |X| < MaxInt }
function Ceil(const X: Extended):Integer;

{ Floor: Largest integer <= X,  |X| < MaxInt }
function Floor(const X: Extended): Integer;

{ Poly: Evaluates a uniform polynomial of one variable at value X.
    The coefficients are ordered in increasing powers of X:
    Coefficients[0] + Coefficients[1]*X + ... + Coefficients[N]*(X**N) }
function Poly(const X: Extended; const Coefficients: array of Double): Extended;

{-----------------------------------------------------------------------
Statistical functions.

Common commercial spreadsheet macro names for these statistical and
financial functions are given in the comments preceding each function.
-----------------------------------------------------------------------}

{ Mean:  Arithmetic average of values.  (AVG):  SUM / N }
function Mean(const Data: array of Double): Extended;

{ Sum: Sum of values.  (SUM) }
function Sum(const Data: array of Double): Extended register;
function SumInt(const Data: array of Integer): Integer register;
function SumOfSquares(const Data: array of Double): Extended;
procedure SumsAndSquares(const Data: array of Double;
  var Sum, SumOfSquares: Extended) register;

{ MinValue: Returns the smallest signed value in the data array (MIN) }
function MinValue(const Data: array of Double): Double;
function MinIntValue(const Data: array of Integer): Integer;

function Min(const A, B: Integer): Integer; overload;
function Min(const A, B: Int64): Int64; overload;
function Min(const A, B: Single): Single; overload;
function Min(const A, B: Double): Double; overload;
function Min(const A, B: Extended): Extended; overload;

{ MaxValue: Returns the largest signed value in the data array (MAX) }
function MaxValue(const Data: array of Double): Double;
function MaxIntValue(const Data: array of Integer): Integer;

function Max(const A, B: Integer): Integer; overload;
function Max(const A, B: Int64): Int64; overload;
function Max(const A, B: Single): Single; overload;
function Max(const A, B: Double): Double; overload;
function Max(const A, B: Extended): Extended; overload;

{ Standard Deviation (STD): Sqrt(Variance). aka Sample Standard Deviation }
function StdDev(const Data: array of Double): Extended;

{ MeanAndStdDev calculates Mean and StdDev in one call. }
procedure MeanAndStdDev(const Data: array of Double; var Mean, StdDev: Extended);

{ Population Standard Deviation (STDP): Sqrt(PopnVariance).
  Used in some business and financial calculations. }
function PopnStdDev(const Data: array of Double): Extended;

{ Variance (VARS): TotalVariance / (N-1). aka Sample Variance }
function Variance(const Data: array of Double): Extended;

{ Population Variance (VAR or VARP): TotalVariance/ N }
function PopnVariance(const Data: array of Double): Extended;

{ Total Variance: SUM(i=1,N)[(X(i) - Mean)**2] }
function TotalVariance(const Data: array of Double): Extended;

{ Norm:  The Euclidean L2-norm.  Sqrt(SumOfSquares) }
function Norm(const Data: array of Double): Extended;

{ MomentSkewKurtosis: Calculates the core factors of statistical analysis:
  the first four moments plus the coefficients of skewness and kurtosis.
  M1 is the Mean.  M2 is the Variance.
  Skew reflects symmetry of distribution: M3 / (M2**(3/2))
  Kurtosis reflects flatness of distribution: M4 / Sqr(M2) }
procedure MomentSkewKurtosis(const Data: array of Double;
  var M1, M2, M3, M4, Skew, Kurtosis: Extended);

{ RandG produces random numbers with Gaussian distribution about the mean.
  Useful for simulating data with sampling errors. }
function RandG(Mean, StdDev: Extended): Extended;

{-----------------------------------------------------------------------
General/Misc use functions
-----------------------------------------------------------------------}

{ Extreme testing }

// Like a infinity, a NaN double value has an exponent of 7FF, but the NaN
// values have a fraction field that is not 0.
function IsNan(const AValue: Double): Boolean;

// Like a NaN, an infinity double value has an exponent of 7FF, but the
// infinity values have a fraction field of 0. Infinity values can be positive
// or negative, which is specified in the high-order, sign bit.
function IsInfinite(const AValue: Double): Boolean;

{ Simple sign testing }

type
  TValueSign = -1..1;

const
  NegativeValue = Low(TValueSign);
  ZeroValue = 0;
  PositiveValue = High(TValueSign);

function Sign(const AValue: Integer): TValueSign; overload;
function Sign(const AValue: Int64): TValueSign; overload;
function Sign(const AValue: Double): TValueSign; overload;

{ CompareFloat & SameFloat: If epsilon is not given (or is zero) we will
  attempt to compute a reasonable one based on the percision of the floating
  point type used. }

function CompareValue(const A, B: Extended; Epsilon: Extended = 0): TValueRelationship; overload;
function CompareValue(const A, B: Double; Epsilon: Double = 0): TValueRelationship; overload;
function CompareValue(const A, B: Single; Epsilon: Single = 0): TValueRelationship; overload;
function CompareValue(const A, B: Integer): TValueRelationship; overload;
function CompareValue(const A, B: Int64): TValueRelationship; overload;

function SameValue(const A, B: Extended; Epsilon: Extended = 0): Boolean; overload;
function SameValue(const A, B: Double; Epsilon: Double = 0): Boolean; overload;
function SameValue(const A, B: Single; Epsilon: Single = 0): Boolean; overload;

{ IsZero: These will return true if the given value is zero (or very very very
  close to it). }

function IsZero(const A: Extended; Epsilon: Extended = 0): Boolean; overload;
function IsZero(const A: Double; Epsilon: Double = 0): Boolean; overload;
function IsZero(const A: Single; Epsilon: Single = 0): Boolean; overload;

{ Easy to use conditional functions }

function IfThen(AValue: Boolean; const ATrue: Integer; const AFalse: Integer = 0): Integer; overload;
function IfThen(AValue: Boolean; const ATrue: Int64; const AFalse: Int64 = 0): Int64; overload;
function IfThen(AValue: Boolean; const ATrue: Double; const AFalse: Double = 0.0): Double; overload;

{ Various random functions }

function RandomRange(const AFrom, ATo: Integer): Integer;
function RandomFrom(const AValues: array of Integer): Integer; overload;
function RandomFrom(const AValues: array of Int64): Int64; overload;
function RandomFrom(const AValues: array of Double): Double; overload;

{ Range testing functions }

function InRange(const AValue, AMin, AMax: Integer): Boolean; overload;
function InRange(const AValue, AMin, AMax: Int64): Boolean; overload;
function InRange(const AValue, AMin, AMax: Double): Boolean; overload;

{ Range truncation functions }

function EnsureRange(const AValue, AMin, AMax: Integer): Integer; overload;
function EnsureRange(const AValue, AMin, AMax: Int64): Int64; overload;
function EnsureRange(const AValue, AMin, AMax: Double): Double; overload;

{ 16 bit integer division and remainder in one operation }

procedure DivMod(Dividend: Integer; Divisor: Word;
  var Result, Remainder: Word);


{ Round to a specific digit or power of ten }
{ ADigit has a valid range of 37 to -37.  Here are some valid examples
  of ADigit values...
   3 = 10^3  = 1000   = thousand's place
   2 = 10^2  =  100   = hundred's place
   1 = 10^1  =   10   = ten's place
  -1 = 10^-1 = 1/10   = tenth's place
  -2 = 10^-2 = 1/100  = hundredth's place
  -3 = 10^-3 = 1/1000 = thousandth's place }

type
  TRoundToRange = -37..37;

function RoundTo(const AValue: Double; const ADigit: TRoundToRange): Double;

{ This variation of the RoundTo function follows the asymmetric arthmetic
  rounding algorithm (if Frac(X) < .5 then return X else return X + 1).  This
  function defaults to rounding to the hundredth's place (cents). }

function SimpleRoundTo(const AValue: Double; const ADigit: TRoundToRange = -2): Double;

{-----------------------------------------------------------------------
Financial functions.  Standard set from Quattro Pro.

Parameter conventions:

From the point of view of A, amounts received by A are positive and
amounts disbursed by A are negative (e.g. a borrower's loan repayments
are regarded by the borrower as negative).

Interest rates are per payment period.  11% annual percentage rate on a
loan with 12 payments per year would be (11 / 100) / 12 = 0.00916667

-----------------------------------------------------------------------}

type
  TPaymentTime = (ptEndOfPeriod, ptStartOfPeriod);

{ Double Declining Balance (DDB) }
function DoubleDecliningBalance(const Cost, Salvage: Extended;
  Life, Period: Integer): Extended;

{ Future Value (FVAL) }
function FutureValue(const Rate: Extended; NPeriods: Integer; const Payment,
  PresentValue: Extended; PaymentTime: TPaymentTime): Extended;

{ Interest Payment (IPAYMT)  }
function InterestPayment(const Rate: Extended; Period, NPeriods: Integer;
  const PresentValue, FutureValue: Extended; PaymentTime: TPaymentTime): Extended;

{ Interest Rate (IRATE) }
function InterestRate(NPeriods: Integer; const Payment, PresentValue,
  FutureValue: Extended; PaymentTime: TPaymentTime): Extended;

{ Internal Rate of Return. (IRR) Needs array of cash flows. }
function InternalRateOfReturn(const Guess: Extended;
  const CashFlows: array of Double): Extended;

{ Number of Periods (NPER) }
function NumberOfPeriods(const Rate: Extended; Payment: Extended;
  const PresentValue, FutureValue: Extended; PaymentTime: TPaymentTime): Extended;

{ Net Present Value. (NPV) Needs array of cash flows. }
function NetPresentValue(const Rate: Extended; const CashFlows: array of Double;
  PaymentTime: TPaymentTime): Extended;

{ Payment (PAYMT) }
function Payment(Rate: Extended; NPeriods: Integer; const PresentValue,
  FutureValue: Extended; PaymentTime: TPaymentTime): Extended;

{ Period Payment (PPAYMT) }
function PeriodPayment(const Rate: Extended; Period, NPeriods: Integer;
  const PresentValue, FutureValue: Extended; PaymentTime: TPaymentTime): Extended;

{ Present Value (PVAL) }
function PresentValue(const Rate: Extended; NPeriods: Integer;
  const Payment, FutureValue: Extended; PaymentTime: TPaymentTime): Extended;

{ Straight Line depreciation (SLN) }
function SLNDepreciation(const Cost, Salvage: Extended; Life: Integer): Extended;

{ Sum-of-Years-Digits depreciation (SYD) }
function SYDDepreciation(const Cost, Salvage: Extended; Life, Period: Integer): Extended;

type
  EInvalidArgument = class(EMathError) end;

{-----------------------------------------------------------------------
FPU exception/precision/rounding management

The following functions allow you to control the behavior of the FPU.  With
them you can control what constutes an FPU exception, what the default
precision is used and finally how rounding is handled by the FPU.

-----------------------------------------------------------------------}

type
  TFPURoundingMode = (rmNearest, rmDown, rmUp, rmTruncate);

{ Return the current rounding mode }
function GetRoundMode: TFPURoundingMode;

{ Set the rounding mode and return the old mode }
function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode;

type
  TFPUPrecisionMode = (pmSingle, pmReserved, pmDouble, pmExtended);

{ Return the current precision control mode }
function GetPrecisionMode: TFPUPrecisionMode;

{ Set the precision control mode and return the old one }
function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode;

type
  TFPUException = (exInvalidOp, exDenormalized, exZeroDivide,
                   exOverflow, exUnderflow, exPrecision);
  TFPUExceptionMask = set of TFPUException;

{ Return the exception mask from the control word.
  Any element set in the mask prevents the FPU from raising that kind of
  exception.  Instead, it returns its best attempt at a value, often NaN or an
  infinity. The value depends on the operation and the current rounding mode. }
function GetExceptionMask: TFPUExceptionMask;

{ Set a new exception mask and return the old one }
function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask;

{ Clear any pending exception bits in the status word }
procedure ClearExceptions;

implementation

Open in new window

But what about my original question regarding the following code?

procedure TMain.DoIt;
var X, Y, Z: integer;
Tmp, Cpy: ansistring;
pRange: xRange;
Canc: boolean;
 function GetIndex(start: boolean): integer;
 var L: integer;
 Math: Extended;
 begin
 L := 0;
 result := 0;
 Math := 0;
 while (L <= Notes.Lines.Count -1) and (nCanc) do
  begin
   Math := Math +Length(Notes.Lines.Strings[L]) +2;
   if Math < 0 then Math := 0;
   if start then
    begin
     if Math >= Notes.SelStart then
      begin
       if Notes.SelStart = Math then L := L+1;
       result := L;
       L := Notes.Lines.Count +2;
      end
    end
   else
    begin
     if Math >= Notes.SelStart +Notes.SelLength then
      begin
       result := L;
       L := Notes.Lines.Count +2;
      end
    end;
    Inc(L);
  end
 end;
begin
with nOpts do
 begin
  X := 0;
  Tmp := '';
  nCanc := true;
  if Opt1.Checked then // add characters to beginning
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := AddChar1.Text +Notes.Lines.Strings[X];
        if Chk1.Checked then
         begin
          if Chk2.Checked then Tmp := Tmp +ReverseString(AddChar1.Text)
          else Tmp := Tmp +AddChar1.Text;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := AddChar1.Text +Notes.Lines.Strings[X];
        if Chk1.Checked then
         begin
          if Chk2.Checked then Tmp := Tmp +ReverseString(AddChar1.Text)
          else Tmp := Tmp +AddChar1.Text;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt2.Checked then // add characters to end
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X] +AddChar2.Text;
        if Chk3.Checked then
         begin
          if Chk4.Checked then Tmp := ReverseString(AddChar2.Text) +Tmp
          else Tmp := AddChar2.Text +Tmp;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X] +AddChar2.Text;
        if Chk3.Checked then
         begin
          if Chk4.Checked then Tmp := ReverseString(AddChar2.Text) +Tmp
          else Tmp := AddChar2.Text +Tmp;
         end;
         if nCanc then Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt3.Checked then //add spaces to beginning of lines
   begin
    if Notes.SelLength < 1 then
     begin
      for X := 1 to AddVal.Value do Tmp := Tmp + ' ';
      X := 0;
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Notes.Lines.Strings[X] := Tmp +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := X;
        Application.ProcessMessages;
       end
     end
    else
     begin
      for X := 1 to AddVal.Value do Tmp := Tmp + ' ';
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Notes.Lines.Strings[X] := Tmp +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
   end
  else if Opt4.Checked then // remove spaces from beginning of line
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk5.Checked then Delete(Tmp, 1, TakeVal1.Value)
        else
         begin
          if trim(Copy(Tmp, 1, TakeVal1.Value)) = '' then Delete(Tmp, 1, TakeVal1.Value)
          else
           begin
            while Copy(Tmp, 1, 1) = ' ' do Delete(Tmp, 1, 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk5.Checked then Delete(Tmp, 1, TakeVal1.Value)
        else
         begin
          if trim(Copy(Tmp, 1, TakeVal1.Value)) = '' then Delete(Tmp, 1, TakeVal1.Value)
          else
           begin
            while Copy(Tmp, 1, 1) = ' ' do Delete(Tmp, 1, 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt5.Checked then // remove spaces from end of lines
   begin
    if Notes.SelLength < 1 then
     begin
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk6.Checked then Tmp := Copy(Tmp, 1, Length(Tmp) -TakeVal2.Value)
        else
         begin
          if trim(Copy(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)) = '' then Delete(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)
          else
           begin
            while Copy(Tmp, Length(Tmp), 1) = ' ' do Delete(Tmp, Length(Tmp), 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if Chk6.Checked then Tmp := Copy(Tmp, 1, Length(Tmp) -TakeVal2.Value)
        else
         begin
          if trim(Copy(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)) = '' then Delete(Tmp, Length(Tmp) -TakeVal2.Value, TakeVal2.Value)
          else
           begin
            while Copy(Tmp, Length(Tmp), 1) = ' ' do Delete(Tmp, Length(Tmp), 1);
           end
         end;
         Notes.Lines.Strings[X] := Tmp;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt6.Checked then // convert all too...
   begin
    if Conv.ItemIndex = 0 then // lowercase
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := LowerCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := LowerCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 1 then //uppercase
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UpperCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UpperCase(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 2 then /ASCII values
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Y := 1;
          Cpy := '';
          Tmp := Notes.Lines.Strings[X];
          while (Y <= Length(Tmp)) and (nCanc) do
           begin
            Cpy := Cpy +IntToStr(Ord(Tmp[Y])) + ', ';
            Inc(Y);
           end;
           Cpy := trim(Cpy);
           if Copy(Cpy, Length(Cpy), 1) = ',' then Delete(Cpy, Length(Cpy), 1);
           Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := X;
           Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Z := 1;
          Cpy := '';
          Tmp := Notes.Lines.Strings[X];
          while (Z <= Length(Tmp)) and (nCanc) do
           begin
            Cpy := Cpy +IntToStr(Ord(Tmp[Z])) + ', ';
            Inc(Z);
           end;
           Cpy := trim(Cpy);
           if Copy(Cpy, Length(Cpy), 1) = ',' then Delete(Cpy, Length(Cpy), 1);
           Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 3 then //hexadecimal
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Tmp := Hex2Bin(Notes.Lines.Strings[X]);
          Tmp := Bin2Hex(Tmp);
          Notes.Lines.Strings[X] := Tmp;
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end;
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Tmp := Hex2Bin(Notes.Lines.Strings[X]);
          Tmp := Bin2Hex(Tmp);
          Notes.Lines.Strings[X] := Tmp;
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 4 then //Binary
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := Hex2Bin(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := Hex2Bin(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 5 then //Javascript escape
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlEncode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlEncode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else if Conv.ItemIndex = 6 then //Javascript unescape
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
        while (X <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlDecode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := X;
          Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Notes.Lines.Strings[X] := UrlDecode(Notes.Lines.Strings[X]);
          Inc(X);
          pBar.Progress := pBar.Progress +1;
          Application.ProcessMessages;
         end
       end
     end
    else //String (clear text characters)
     begin
      if Notes.SelLength < 1 then
       begin
        X := 0;
        Cpy := '';
        if Notes.Lines.Count > 0 then pBar.MaxValue := Length(Notes.Lines.Text);
        while (X <= pBar.MaxValue) and (nCanc) do
         begin
          Tmp := Notes.Lines.Strings[X];
          if IsBinary(Tmp) then
           begin
            Tmp := Bin2Hex(Tmp);
            Cpy := StringOfChar('0', Length(Tmp) div 2);
            HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
           end
          else
           begin
            Canc := true;
            Cpy := '';
            Z := 0;
            while (Length(Tmp) > 0) and (nCanc) do
             begin
              if Pos(',', Tmp) > 0 then
               begin
                if isint(Copy(Tmp, 1, Pos(',', Tmp) -1), false, false) then
                 begin
                  if (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) < 256) and (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) > 0) then
                   begin
                    Cpy := Cpy +Chr(StrToInt(Copy(Tmp, 1, Pos(',', Tmp) -1)));
                    Canc := false;
                    Z := 1;
                   end
                  else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                 end
                else
                 begin
                  MessageDlg('Data is not numerical and is not an ASCII code!.', mtWarning, [mbok], 0);
                  nCanc := not nCanc;
                 end;
                 Delete(Tmp, 1, Pos(',', Tmp) +1);
               end
              else
               begin
                if isint(Tmp, false, false) then
                 begin
                  if (StrToFloat(Tmp) < 100) and (Canc) then
                   begin
                    if MessageDlg('Unable to determine data type!, is the data ASCII?', mtConfirmation, [mbyes, mbno], 0) = mryes then Z := 1;
                   end
                  else Z := 1;
                  if StrToFloat(Tmp) > 255 then Z := 0;
                  if Z = 0 then // hexadecimal
                   begin
                    Cpy := StringOfChar('0', Length(Tmp) div 2);
                    HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                   end
                  else // ASCII
                   begin
                    if (StrToFloat(Tmp) < 256) and (StrToFloat(Tmp) > 0) then Cpy := Cpy +Chr(StrToInt(Tmp))
                    else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                   end
                 end
                else
                 begin
                  Cpy := StringOfChar('0', Length(Tmp) div 2);
                  HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                 end;
                 Tmp := '';
               end
             end
           end;
           if nCanc = true then Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := X;
           Application.ProcessMessages;
         end
       end
      else
       begin
        X := GetIndex(true);
        Y := GetIndex(false);
        pBar.MaxValue := Y -X;
        while (X <= Y) and (nCanc) do
         begin
          Tmp := Notes.Lines.Strings[X];
          if IsBinary(Tmp) then
           begin
            Tmp := Bin2Hex(Tmp);
            Cpy := StringOfChar('0', Length(Tmp) div 2);
            HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
           end
          else
           begin
            Canc := true;
            Cpy := '';
            Z := 0;
            while (Length(Tmp) > 0) and (nCanc) do
             begin
              if Pos(',', Tmp) > 0 then
               begin
                if isint(Copy(Tmp, 1, Pos(',', Tmp) -1), false, false) then
                 begin
                  if (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) < 256) and (StrToFloat(Copy(Tmp, 1, Pos(',', Tmp) -1)) > 0) then
                   begin
                    Cpy := Cpy +Chr(StrToInt(Copy(Tmp, 1, Pos(',', Tmp) -1)));
                    Canc := false;
                    Z := 1;
                   end
                  else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                 end
                else MessageDlg('Data is not numerical and is not an ASCII code!.', mtWarning, [mbok], 0);
                Delete(Tmp, 1, Pos(',', Tmp) +1);
               end
              else
               begin
                if isint(Tmp, false, false) then
                 begin
                  if (StrToFloat(Tmp) < 100) and (Canc) then
                   begin
                    if MessageDlg('Unable to determine data type!, is the data ASCII?', mtConfirmation, [mbyes, mbno], 0) = mryes then Z := 1;
                   end
                  else Z := 1;
                  if StrToFloat(Tmp) > 255 then Z := 0;
                  if Z = 0 then // hexadecimal
                   begin
                    Cpy := StringOfChar('0', Length(Tmp) div 2);
                    HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                   end
                  else // ASCII
                   begin
                    if (StrToFloat(Tmp) < 256) and (StrToFloat(Tmp) > 0) then Cpy := Cpy +Chr(StrToInt(Tmp))
                    else MessageDlg('Numeral value is not an ASCII code!.', mtWarning, [mbok], 0);
                   end
                 end
                else
                 begin
                  Cpy := StringOfChar('0', Length(Tmp) div 2);
                  HexToBin(PChar(Tmp), PChar(Cpy), Length(Tmp));
                 end;
                 Tmp := '';
               end
             end
           end;
           Notes.Lines.Strings[X] := Cpy;
           Inc(X);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end
       end
     end
   end
  else if Opt7.Checked then //generate random characters
   begin
    pRange[0] := 1;
    pRange[1] := 255;
    pBar.MaxValue := Seed.Value -1;
    for X := 1 to Seed.Value do
     begin
      Tmp := Tmp +Chr(iRandom(pRange));
      pBar.Progress := pBar.Progress +1;
     end;
     if Chk7.Checked then Notes.Lines.Add(Tmp)
     else Notes.Lines.Text := Notes.Lines.Text +Tmp;
   end
  else if Opt8.Checked then // split/break line after n (number of) characters
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if trim(Notes.Lines.Strings[X]) <> '' then
         begin
          with Notes.Lines do Strings[X] := Copy(Strings[X], 1, SplitVal.Value) + #13#10 + Copy(Strings[X], SplitVal.Value +1, Length(Strings[X]));
         end;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end;
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if trim(Notes.Lines.Strings[X]) <> '' then
         begin
          with Notes.Lines do Strings[X] := Copy(Strings[X], 1, SplitVal.Value) + #13#10 + Copy(Strings[X], SplitVal.Value +1, Length(Strings[X]));
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt9.Checked then // remove only blank lines
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      if Notes.Lines.Count > 0 then pBar.MaxValue := Notes.Lines.Count;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if trim(Notes.Lines.Strings[X]) = '' then
         begin
          Notes.Lines.Delete(X);
          if X < Notes.Lines.Count -1 then Dec(X)
          else nCanc := false
         end;
         Inc(X);
         pBar.Progress := X;
         Application.ProcessMessages;
       end;
     end
    else
     begin
      X := GetIndex(true);
      Y := GetIndex(false);
      pBar.MaxValue := Y -X;
      while (X <= Y) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        if trim(Notes.Lines.Strings[X]) = '' then
         begin
          Dec(Y);
          Notes.Lines.Delete(X);
          if X < Notes.Lines.Count -1 then Dec(X)
          else nCanc := false
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt10.Checked then // add lines to beginning
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := AddLines.Value;
      while (X <= AddLines.Value -1) and (nCanc) do
       begin
        Notes.Lines.Insert(0, '');
        Inc(X);
        pBar.Progress := X;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := 0;
      Y := GetIndex(true);
      pBar.MaxValue := AddLines.Value;
      while (X <= AddLines.Value -1) and (nCanc) do
       begin
        Notes.Lines.Insert(Y, '');
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end 
   end
  else if Opt11.Checked then // remove lines from beginning 
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := RmvLines.Value;
      while (X <= RmvLines.Value -1) and (nCanc) do
       begin
        if Chk8.Checked then Notes.Lines.Delete(0)
        else if Notes.Lines.Strings[0] = '' then Notes.Lines.Delete(0);
        Inc(X);
        pBar.Progress := X;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := 0;
      Y := GetIndex(true);
      pBar.MaxValue := RmvLines.Value;
      while (X <= RmvLines.Value -1) and (nCanc) do
       begin
        if Chk8.Checked then Notes.Lines.Delete(Y -1)
        else
         begin
          if Y > 0 then
           begin
            if Notes.Lines.Strings[Y -1] = '' then Notes.Lines.Delete(Y -1)
            else
             begin
              if Y > 1 then Z := Y -1
              else Z := 0;
              while (Notes.Lines.Strings[Z] <> '') and (Z > 0) do Dec(Z);
              if Z > 0 then Notes.Lines.Delete(Z);
             end
           end
         end;
         Dec(Y);
         Inc(X);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt12.Checked then // find and replace
   begin
    if Notes.SelLength < 1 then
     begin
      Y := 0;
      while (Y >= 0) and (nCanc) do
       begin
        if (Chk9.Checked) and (not Chk10.Checked) then Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, [stMatchCase])
        else if (Chk9.Checked) and (Chk10.Checked) then Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, [stMatchCase, stWholeWord])
        else if (not Chk9.Checked) and (Chk10.Checked) then Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, [stWholeWord])
        else Y := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -Y, []);
        if Y >= 0 then
         begin
          Notes.SelStart := Y;
          Notes.SelLength := FndText.GetTextLen;
          Notes.SelText := RplText.Text;
         end
       end
     end
    else
     begin
      X := GetIndex(true);
      if X > 0 then Y := Length(Notes.Lines.Strings[X -1])
      else Y := 0;
      X := 0;
      Z := GetIndex(false);
      while (X >= 0) and (nCanc) do
       begin
        if (Chk9.Checked) and (not Chk10.Checked) then X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, [stMatchCase])
        else if (Chk9.Checked) and (Chk10.Checked) then X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, [stMatchCase, stWholeWord])
        else if (not Chk9.Checked) and (Chk10.Checked) then X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, [stWholeWord])
        else X := Notes.FindText(FndText.Text, Y, Notes.GetTextLen -X, []);
        if X >= 0 then
         begin
          Notes.SelStart := X;
          Notes.SelLength := FndText.GetTextLen;
          if GetIndex(true) > Z then X := -1
          else Notes.SelText := RplText.Text;
         end;
         Y := X;
       end
     end
   end
  else if Opt13.Checked then // split lines after characters
   begin
    if Notes.SelLength < 1 then
     begin
      Y := 1;
      X := Notes.FindText(SpltTxt.Text, Y, Notes.GetTextLen, [stMatchCase]);
      while X > 0 do
       begin
        if Chk12.Checked then
         begin
          if (X > 0) and (Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, 1) <> #13) then Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
         end
        else Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
        Y := X +SpltTxt.GetTextLen;
        X := Notes.FindText(SpltTxt.Text, Y, Notes.GetTextLen -X, [stMatchCase]);
        Application.ProcessMessages;
        if nCanc = false then X := -1;
       end
     end
    else
     begin
      Y := Notes.SelStart;
      Z := Notes.SelLength;
      Tmp := IntToStr(Y +Z);
      X := Notes.FindText(SpltTxt.Text, Y, Z, [stMatchCase]);
      Cpy := '0';
      while X > 0 do
       begin
         if Y >= StrToInt(Tmp) then X := -1
         else X := Notes.FindText(SpltTxt.Text, Y, Z, [stMatchCase]);
         if X > 0 then
          begin
           if Chk12.Checked then
            begin
             if Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, 1) <> #13 then
              begin
               Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
               Z := Z +Length(#13#10);
               Tmp := IntToStr(StrToInt(Tmp) +Length(#13#10));
              end
            end
           else
            begin
             Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X +SpltTxt.GetTextLen) + #13#10 + Copy(Notes.Lines.Text, (X +SpltTxt.GetTextLen) +1, Notes.GetTextLen -(X +SpltTxt.GetTextLen));
             Z := Z +Length(#13#10);
             Tmp := IntToStr(StrToInt(Tmp) +Length(#13#10));
            end;
            while trim(Notes.Lines.Text[(X + StrToInt(Cpy)) +(SpltTxt.GetTextLen +Length(#13#10))]) = '' do Cpy := IntToStr(StrToInt(Cpy) +1);
            Y := (X + StrToInt(Cpy)) +(SpltTxt.GetTextLen +Length(#13#10));
          end;
          if nCanc = false then X := -1;
          Application.ProcessMessages;
       end
     end
   end
  else if Opt14.Checked then // split lines before characters
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      Y := 0;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Inc(Y);
        if Chk11.Checked then Notes.Lines.Strings[X] := LeadChars.Text + IntToStr(Y) +Notes.Lines.Strings[X]
        else Notes.Lines.Strings[X] := IntToStr(Y) +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
    else
     begin
      Y := 0;
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        Inc(Y);
        if Chk11.Checked then Notes.Lines.Strings[X] := LeadChars.Text + IntToStr(Y) +Notes.Lines.Strings[X]
        else Notes.Lines.Strings[X] := IntToStr(Y) +Notes.Lines.Strings[X];
        Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
   end
  else if Opt15.Checked then // incremental number insertion (line count)
   begin
    if Notes.SelLength < 1 then
     begin
      Y := 1;
      X := Notes.FindText(SpltTxt2.Text, Y, Notes.GetTextLen, [stMatchCase]);
      while X > 0 do
       begin
        Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X) + #13#10 + Copy(Notes.Lines.Text, X +1, Notes.GetTextLen -(X +1));
        Y := X +(SpltTxt2.GetTextLen +2);
        X := Notes.FindText(SpltTxt2.Text, Y, Notes.GetTextLen -X, [stMatchCase]);
        Application.ProcessMessages;
        if nCanc = false then X := -1;
       end
     end
    else
     begin
      Y := Notes.SelStart;
      Z := Notes.SelLength;
      Tmp := IntToStr(Y +Z);
      X := Notes.FindText(SpltTxt2.Text, Y, Z, [stMatchCase]);
      Cpy := '0';
      while X > 0 do
       begin
         if Y >= StrToInt(Tmp) then X := -1
         else X := Notes.FindText(SpltTxt2.Text, Y, Z, [stMatchCase]);
         if X > 0 then
          begin
           Notes.Lines.Text := Copy(Notes.Lines.Text, 1, X) + #13#10 + Copy(Notes.Lines.Text, X +1, Notes.GetTextLen -(X +1));
           Z := Z +Length(#13#10);
           Tmp := IntToStr(StrToInt(Tmp) +Length(#13#10));
           while trim(Notes.Lines.Text[(X + StrToInt(Cpy)) +((SpltTxt2.GetTextLen +1) +Length(#13#10))]) = '' do Cpy := IntToStr(StrToInt(Cpy) +1);
           Y := (X + StrToInt(Cpy)) +((SpltTxt2.GetTextLen +2) +Length(#13#10));
          end;
          if nCanc = false then X := -1;
          Application.ProcessMessages;
       end
     end
   end
  else if Opt16.Checked then // remove every second line
   begin
    if Notes.SelLength < 1 then
     begin
      X := 1; // counter
      Y := 0; // loop index
      pBar.MaxValue := Notes.Lines.Count -1;
      while (Y <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if X = LineCount.Value then
         begin
          X := 1;
          Notes.Lines.Delete(Y);
          pBar.MaxValue := Notes.Lines.Count -1;
         end;
         Inc(X);
         Inc(Y);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
    else
     begin
      X := 1; // counter
      Y := GetIndex(true); // LOOP INDEX
      Z := GetIndex(false); // end loop
      pBar.MaxValue := Z;
      while (Y <= Z) and (nCanc) do
       begin
        if X = LineCount.Value then
         begin
          X := 1;
          Notes.Lines.Delete(Y);
          Z := Z -1;
          pBar.MaxValue := Notes.Lines.Count -1;
         end;
         Inc(X);
         Inc(Y);
         pBar.Progress := pBar.Progress +1;
         Application.ProcessMessages;
       end
     end
   end
  else if Opt17.Checked then // remove lines that do not contain characters
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if Pos(KeepChars.Text, Notes.Lines.Strings[X]) <= 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        if Pos(KeepChars.Text, Notes.Lines.Strings[X]) <= 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
          Z := Z -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
       end
     end
   end
  else if Opt18.Checked then // remove lines that contain characters
   begin
    if Notes.SelLength < 1 then
     begin
      X := 1;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        if Pos(RmvChars.Text, Notes.Lines.Strings[X]) > 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        if Pos(RmvChars.Text, Notes.Lines.Strings[X]) > 0 then
         begin
          Notes.Lines.Delete(X);
          pBar.MaxValue := Notes.Lines.Count -1;
         end
        else Inc(X);
        pBar.Progress := pBar.Progress +1;
        Application.ProcessMessages;
       end
     end
   end
  else if Opt19.Checked then  // remove duplicate lines
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := (Notes.Lines.Count -1) *2;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := X +1;
        while (Y <= Notes.Lines.Count -1) and (nCanc) do
         begin
          Cpy := Notes.Lines.Strings[Y];
          if trim(Cpy) = trim(Tmp) then
           begin
            Notes.Lines.Delete(Y);
            pBar.MaxValue := Notes.Lines.Count -1;
            Y := Y -1;
           end;
           Inc(Y);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z *2;
      while (X <= Z) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := X +1;
        while (Y <= Z) and (nCanc) do
         begin
          Cpy := Notes.Lines.Strings[Y];
          if Cpy = Tmp then
           begin
            Notes.Lines.Delete(Y);
            pBar.MaxValue := Notes.Lines.Count -1;
            Y := Y -1;
           end;
           Inc(Y);
           pBar.Progress := pBar.Progress +1;
           Application.ProcessMessages;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
   end
  else if Opt20.Checked then  // remove all characters on line up to "character"
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := Pos(RmvCharsToChars.Text, Tmp);
        if Y > 0 then
         begin
          Tmp := Copy(Tmp, Y +Length(RmvCharsToChars.Text), Length(Tmp));
          Notes.Lines.Strings[X] := Tmp;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        Tmp := Notes.Lines.Strings[X];
        Y := Pos(RmvCharsToChars.Text, Tmp);
        if Y > 0 then
         begin
          Tmp := Copy(Tmp, Y +Length(RmvCharsToChars.Text), Length(Tmp));
          Notes.Lines.Strings[X] := Tmp;
         end;
         Inc(X);
         pBar.Progress := pBar.Progress +1;
       end
     end
   end
  else if Opt21.Checked then  // remove all line breaks
   begin
    if Notes.SelLength < 1 then
     begin
      X := 0;
      Cpy := Notes.Lines.Strings[0];
      while X < Notes.Lines.Count -1 do
       begin
        Cpy := Cpy + Notes.Lines.Strings[X +1];
        Inc(X);
        if nCanc = false then X := -1;
        Application.ProcessMessages;
       end;
       Notes.Lines.Text := Cpy;
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      Y := X;
      Tmp := '';
      while (X <= Z) and (nCanc) do
       begin
        Tmp := Tmp + Notes.Lines.Strings[Y +1];
        Inc(X);
        if X >= Z then nCanc := false
        else Notes.Lines.Delete(Y +1);
        if nCanc = false then X := Z +2;
        Application.ProcessMessages;
        pBar.Progress := pBar.Progress +1;
       end;
       Notes.Lines.Strings[Y +1] := Tmp;
     end
   end

  else if Opt22.Checked then  // break before/after line if all characters are uppercase/lowercase
   begin
    if Notes.SelLength < 1 then
     begin
      X := 1;
      pBar.MaxValue := Notes.Lines.Count -1;
      while (X <= Notes.Lines.Count -1) and (nCanc) do
       begin
        Tmp := trim(Notes.Lines.Strings[X]);
        if brklnchr.ItemIndex = 0 then
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end
        else
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end;
         Inc(X);
       end
     end
    else
     begin
      X := GetIndex(true);
      Z := GetIndex(false);
      pBar.MaxValue := Z;
      while (X <= Z) and (nCanc) do
       begin
        Tmp := trim(Notes.Lines.Strings[X]);
        if brklnchr.ItemIndex = 0 then
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 90) and (Ord(Tmp[Y]) >= 65)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end
        else
         begin
          Y := 1;
          while Y <= Length(Tmp) do
           begin
            if Chk13.Checked then
             begin
              if ((Ord(Tmp[Y]) <= 57) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end
            else
             begin
              if ((Ord(Tmp[Y]) <= 47) and (Ord(Tmp[Y]) >= 33)) or ((Ord(Tmp[Y]) <= 122) and (Ord(Tmp[Y]) >= 97)) or (Ord(Tmp[Y]) = 32) then
               begin
                if Y = Length(Tmp) then
                 begin
                  if BrkPos.ItemIndex = 0 then Notes.Lines.Strings[X] := #13#10 + Notes.Lines.Strings[X]
                  else Notes.Lines.Strings[X] := Notes.Lines.Strings[X] + #13#10;
                  pBar.MaxValue := Notes.Lines.Count -1;
                  Inc(X);
                 end
               end
              else Y := Length(Tmp) +2;
             end;
             pBar.Progress := pBar.Progress +1;
             Application.ProcessMessages;
             Inc(Y);
           end
         end;
         Inc(X);
       end
     end
   end

  else MessageDlg('No options have been choosen!.', mtWarning, [mbok], 0);
  nCanc := not nCanc;
  ToolButton17.Tag := 0;
  ToolButton17.ImageIndex := 11;
  Notes.ReadOnly := false;
  pBar.Progress := 0;
  Main.Caption := Capt + 'Done ! ;-)';
 end
end;

Open in new window

why is ncanc defined as a global variable ?


change
Application.ProcessMessages;
to
pbar.Update;

lol ... reverse order sometimes required ?
at line 1186:
  Application.ProcessMessages;
  pBar.Progress := pBar.Progress +1;

Open in new window


now and then you forgot to add application.processmessages

i'd start with creating a proc to update the progressbar

procedure TMain.Progress(aProgress: Integer = 1);
begin
  pBar.Progress := pBar.Progress + aProgress;
  pBar.Update;
end;

Open in new window


now and then, i also see the max changing
pBar.MaxValue :=  Notes.Lines.Count -1;

Open in new window

wouldn't it be better to set this once ? at the beginning of the procedure

next i would cut the very procedure up into several smaller pieces
you'll probably find you have reusable code
and that will greatly reduce the amount of code

and debugging that will be way simpler ...
Hi Geert,
 You valued assistance is incredibly appreciated, as i am merely a self-taught programmer who has only learned primarily from the Delphi Help *.hlp file (help file) and i have little "good" knowledge but only enough to make things work...

I will start with the "pBar.MaxValue :=  Notes.Lines.Count -1;" changing, that is likely due to adding breaks in the line which of course increased the count of lines in the richedit, so as the richedit count increased the max of the progress bar will need to increase but i will still look over the code to make certain that this is the only reason for that happening!.

The reason there is so many processmessages is due to the fact that the procedure can be cancelled when the user clicks the cancel button.
When the procedure starts the boolean value ncanc is set to false and the procedure will continue until either completed or until ncanc becomes true... ncanc can be set to true by clicking a button (the same button that is used to start the procedure in fact) and because ncanc is a global variable i have used processmessages to make the variable change take place, please if you know of a better method, let me know but this is the only way i have found of stopping a procedure mid-operation.
But i most certainly will be adopting your suggestion of creating a single progress bar update procedure.

And yes it is such a MASSIVE chunk of code!.
click cancel ?
unless you work with threads ... it won't work very well

well, if you add that line application.processmessages to the progress routine ... it will more or less work the same
Great point!
lol, this functionality in opts is all anyone could ever want :)
the way it's programmed causes a maze-like effect

when you look at the code, you have no idea where it leads or where to look
unless off course, you've been adding to this gradually over the years

you have a separation of the options and code ...
when not move the code the opts unit ?

then you could reuse this with any Richedit ... and from unit, without the need for circular unit reference
i'll solve the circular unit reference and convert unit2 into an independant unit

in the opts form ...
add a scrollbox, ctrl-X panel1, click in scrollbox, ctrl-V the panel1
set the scrollbox align to alignclient

now, in the IDE, you can see all the checks, labels etc and can move the form contents up and down ...

first, providing a callback from the opts unit to the main unit:

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Spin, StdCtrls, ExtCtrls;

type
  TnOptsCallbackMsg = procedure (Sender: TObject; aPanelMsg: string; aPanelId: integer = 0) of object;
  TnOptsCallbackProgress = procedure (Sender: TObject; aProgress: Integer = 1; aProgressMax: Integer = 0) of object;

  TnOpts = class(TForm)
    ScrollBox1: TScrollBox;
      // removed 
  private
    fCallBackMsg: TOptsCallbackMsg;
    fCallBackProgress: TOptsCallbackProgress;
    fNotes: TRichEdit;
    procedure GUIControl(Sender: TObject);
    procedure LineCounter;
    procedure CallbackMsg(PanelMsg: string; PanelId: Integer = 0);
    procedure CallbackProgress(Progress: Integer = 1; ProgressMax: Integer = 0);
  public
    constructor Create(aOwner: TComponent; aNotes: TRichEdit; aCallbackMsg: TnOptsCallback = nil; aCallbackProgress: TnOptsCallbackProgress);

    property Notes: TRichEdit read fNotes;
  end;

var
  nOpts: TnOpts;

implementation

{$R *.dfm}

constructor TnOpts.Create(aOwner: TComponent; aNotes: TRichEdit; aCallbackMsg: TnOptsCallback = nil; aCallbackProgress: TnOptsCallbackProgress);
begin
  inherited Create(aOwner);
  fNotes := aNotes;
  fCallbackMsg := aCallbackMsg;
  fCallbackProgress := aCallbackProgress;
end;

procedure TnOpts.CallbackMsg(PanelMsg: string; PanelId: Integer = 0);
begin
  if Assigned(fCallbackMsg) then
    fCallbackMsg(Self, PanelMsg, PanelId);
end;

procedure TnOpts.CallbackProgress(Progress: Integer = 1; ProgressMax: Integer = 0);
begin
  if Assigned(fCallbackProgress) then
    fCallbackProgress(Self, Progress, ProgressMax);
end;

Open in new window


in the main form, i see code for showing the opts unit ...
i'd add a create so i can pass the call back procedures :


type
  TMain = class(TForm)
    Notes: TRichEdit;
    Menu: TMainMenu;
    Menu1: TMenuItem;
    Stat: TStatusBar;
    pBar: TGauge;
    Menu2: TMenuItem;
    procedure FormResize(Sender: TObject);
    procedure Menu2Click(Sender: TObject);
    procedure Menu1Click(Sender: TObject);
  private
    fOpts: TForm;
    procedure DoIt;
    procedure CallbackMsg(Sender: TObject; PanelMsg: string; PanelId: Integer = 0);
    procedure CallbackProgress(Sender: TObject; Progress: Integer = 1; Max: Integer = 0);
  public
    constructor Create(aOwner: TComponent); override;
  end;

var
  Main: TMain;
  nCanc: boolean;

const Capt: string = 'Notepad tool    ';

implementation

uses Unit2, BinConv, Global, intutil;

{$R *.dfm}

constructor TMain.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  fOpts := TnOpts.Create(Self, Notes, CallbackMsg, CallbackProgress);
end;

procedure TMain.CallbackMsg(Sender: TObject; PanelMsg: string; PanelId: Integer = 0);
begin
  Stat.Panels[PanelId] := PanelMsg;
  Stat.Update;
  // Application.ProcessMessages;
end;

procedure TMain.CallbackProgress(Sender: TObject; Progress: Integer = 1; Max: Integer = 0);
begin
  // Max = -1 > Progress = position
  if Max = -1 then
    pbar.Progress Progress
  else if Max = 0 then // add progress
    pBar.Progress := pBar.Progress + Progress
  else if Max > 0 then
  begin
    pBar.Progress := 0;
    pBar.Max := Max;
    pBar.Progress := Progress;
  end;
  pBar.Update;
  // Application.ProcessMessages;
end;

Open in new window

had to adapt the callbackmsg:
you never change a different panel > removed panelId
and optionally add a piece of text:

procedure TMain.CallbackMsg(Sender: TObject; PanelMsg: string; AddMsg: boolean = False);
begin
  if not AddMsg then
    Stat.Panels[0] := PanelMsg
  else
    Stat.Panels[0] := Stat.Panels[PanelId] + PanelMsg;
  Stat.Update;
  // Application.ProcessMessages;
end;

Open in new window

now the callbackmsg can be used to make unit2 independant of unit1

procedure TnOpts.GUIControl(Sender: TObject);
var Msg: string;
begin
  AddChar1.Enabled := Opt1.Checked;
  Label1.Enabled := Opt1.Checked;
  Chk1.Enabled := Opt1.Checked;
  Chk2.Enabled := Opt1.Checked;
  AddChar2.Enabled := Opt2.Checked;
  Label3.Enabled := Opt2.Checked;
  Chk3.Enabled := Opt2.Checked;
  Chk4.Enabled := Opt2.Checked;
  AddVal.Enabled := Opt3.Checked;
  Label5.Enabled := Opt3.Checked;
  TakeVal1.Enabled := Opt4.Checked;
  Label7.Enabled := Opt4.Checked;
  Chk5.Enabled := Opt4.Checked;
  Label8.Enabled := Opt4.Checked;
  TakeVal2.Enabled := Opt5.Checked;
  Label13.Enabled := Opt5.Checked;
  Chk6.Enabled := Opt5.Checked;
  Label14.Enabled := Opt5.Checked;
  Conv.Enabled := Opt6.Checked;
  Seed.Enabled := Opt7.Checked;
  Label11.Enabled := Opt7.Checked;
  Chk7.Enabled := Opt7.Checked;
  SplitVal.Enabled := Opt8.Checked;
  splitLabel.Enabled := Opt8.Checked;
  AddLines.Enabled := Opt10.Checked;
  Label18.Enabled := Opt10.Checked;
  RmvLines.Enabled := Opt11.Checked;
  Label20.Enabled := Opt11.Checked;
  Chk8.Enabled := Opt11.Checked;
  FndText.Enabled := Opt12.Checked;
  Label22.Enabled := Opt12.Checked;
  RplText.Enabled := Opt12.Checked;
  Chk9.Enabled := Opt12.Checked;
  Chk10.Enabled := Opt12.Checked;
  SpltTxt.Enabled := Opt13.Checked;
  Chk12.Enabled := Opt13.Checked;
  Chk11.Enabled := Opt14.Checked;
  SpltTxt2.Enabled := Opt15.Checked;
  LineCount.Enabled := Opt16.Checked;
  KeepChars.Enabled := Opt17.Checked;
  RmvChars.Enabled := Opt18.Checked;
  SpltTxt2.Enabled := Opt15.Checked;
  RmvCharsToChars.Enabled := Opt20.Checked;
  if Opt1.Checked then
  begin
    CallbackMsg('Add Leading Chars (' +AddChar1.Text + ');');
    if Chk1.Checked then
    begin
      if Chk2.Checked then
        CallbackMsg(' Reversed Suffix', True)
      else
        CallbackMsg(' Add Suffix', True);
    end;
  end else if Opt2.Checked then
  begin
    CallBackMsg('Add Trailing Chars (' +AddChar2.Text + ');';
    if Chk3.Checked then
    begin
      if Chk4.Checked then
        CallBackMsg(' Reversed Prefix', True)
      else
        CallBackMsg(' Add Prefix', True);
    end;
  end
  else if Opt3.Checked then CallBackMsg('Add ' + IntToStr(AddVal.Value) + ' Spaces')
  else if Opt4.Checked then
  begin
    CallBackMsg('Take ' + IntToStr(TakeVal1.Value) + ' Leading Spaces;');
    if Chk5.Checked then CallBackMsg(' Take Leading Chars', True);
  end
  else if Opt5.Checked then
  begin
    CallBackMsg('Take ' + IntToStr(TakeVal2.Value) + ' Trailing Spaces;');
    if Chk6.Checked then CallBackMsg(' Take Trailing Chars', True);
  end
  else if Opt6.Checked then CallBackMsg('Convert all to ' + Conv.Text)
  else if Opt7.Checked then
  begin
    CallBackMsg('Generate ' + IntToStr(Seed.Value) + ' random characters;');
    if Chk7.Checked then CallBackMsg('  New Line', True);
  end
  else if Opt8.Checked then CallBackMsg('Lines split after ' + IntToStr(SplitVal.Value) + ' characters')
  else if Opt9.Checked then CallBackMsg('Remove blank lines!.')
  else if Opt10.Checked then CallBackMsg('Add ' + IntToStr(AddLines.Value) + ' lines!.')
  else if Opt11.Checked then
  begin
    if Chk8.Checked then CallBackMsg('Remove ' + IntToStr(RmvLines.Value) + ' lines and characters!.')
   else CallBackMsg('Remove ' + IntToStr(RmvLines.Value) + ' lines!.');
  end
  else if Opt12.Checked then
  begin
    if Chk9.Checked then
    begin
      if Chk10.Checked then CallBackMsg('Convert all (Matching Case, Whole Word) ' + FndText.Text + '''s to ' + RplText.Text + '!.')
      else CallBackMsg('Convert all (Matching Case) ' + FndText.Text + '''s to ' + RplText.Text + '!.')
    end
      else
    begin
      if Chk10.Checked then CallBackMsg('Convert all (Whole Word) ' + FndText.Text + '''s to ' + RplText.Text + '!.')
      else CallBackMsg('Convert all ' + FndText.Text + '''s to ' + RplText.Text + '!.');
    end
  end
  else if Opt13.Checked then
  begin
    if Chk12.Checked then CallBackMsg('Split lines after the characters "' + SpltTxt.Text + '" only if more characters exist after split position.')
    else CallBackMsg('Split lines after the characters "' + SpltTxt.Text + '"');
  end
    else if Opt14.Checked then
  begin
    if Chk11.Checked then CallBackMsg('Insert ascending numeral values, starting with ' + LeadChars.Text)
    else CallBackMsg('Insert ascending numeral values.');
  end
  else if Opt15.Checked then CallBackMsg('Split lines before the characters "' + SpltTxt2.Text + '"')
  else if Opt16.Checked then CallBackMsg('Remove every ' + LineCount.Text + Label28.Caption)
  else if Opt17.Checked then CallBackMsg('Remove line/s that do not contain "' + KeepChars.Text + '"')
  else if Opt18.Checked then CallBackMsg('Remove line/s that contain the characters "' + RmvChars.Text + '"')
  else if Opt19.Checked then CallBackMsg('Remove all duplicate lines.')
  else CallBackMsg('Remove all characters on line/s up to and including the character "' + RmvCharsToChars.Text + '"');
end;

Open in new window

for all those click events ...
i changed guicontrol procedure to an notify procedure

    procedure GUIControl(Sender: TObject);

Open in new window


and then reassigned all the onclick events to that guicontrol directly
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Spin, StdCtrls, ExtCtrls;

type
  TnOptsCallbackMsg = procedure (Sender: TObject; aPanelMsg: string; AddMsg: boolean = False) of object;
  TnOptsCallbackProgress = procedure (Sender: TObject; aProgress: Integer = 1; aProgressMax: Integer = 0) of object;

  TnOpts = class(TForm)
    ScrollBox1: TScrollBox;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    splitLabel: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    Opt1: TRadioButton;
    AddChar1: TEdit;
    Chk1: TCheckBox;
    Chk2: TCheckBox;
    Opt2: TRadioButton;
    AddChar2: TEdit;
    Chk3: TCheckBox;
    Chk4: TCheckBox;
    Opt3: TRadioButton;
    AddVal: TSpinEdit;
    Opt4: TRadioButton;
    TakeVal1: TSpinEdit;
    Chk5: TCheckBox;
    Opt6: TRadioButton;
    Conv: TComboBox;
    Opt7: TRadioButton;
    Seed: TSpinEdit;
    Chk7: TCheckBox;
    Opt5: TRadioButton;
    TakeVal2: TSpinEdit;
    Chk6: TCheckBox;
    Opt9: TRadioButton;
    Opt8: TRadioButton;
    SplitVal: TSpinEdit;
    Opt10: TRadioButton;
    AddLines: TSpinEdit;
    Opt11: TRadioButton;
    RmvLines: TSpinEdit;
    Chk8: TCheckBox;
    Opt12: TRadioButton;
    FndText: TEdit;
    RplText: TEdit;
    Chk9: TCheckBox;
    Chk10: TCheckBox;
    Opt13: TRadioButton;
    SpltTxt: TEdit;
    Opt14: TRadioButton;
    Chk11: TCheckBox;
    LeadChars: TEdit;
    Chk12: TCheckBox;
    Opt15: TRadioButton;
    SpltTxt2: TEdit;
    Opt16: TRadioButton;
    LineCount: TSpinEdit;
    Opt17: TRadioButton;
    KeepChars: TEdit;
    Opt18: TRadioButton;
    RmvChars: TEdit;
    Opt19: TRadioButton;
    Opt20: TRadioButton;
    RmvCharsToChars: TEdit;
    Opt21: TRadioButton;
    Opt22: TRadioButton;
    brklnchr: TComboBox;
    Chk13: TCheckBox;
    BrkPos: TComboBox;
    procedure LineCountChange(Sender: TObject);
    procedure Chk11Click(Sender: TObject);
    procedure GUIControl(Sender: TObject);
  private
    fCallBackMsg: TOptsCallbackMsg;
    fCallBackProgress: TOptsCallbackProgress;
    fNotes: TRichEdit;
    procedure LineCounter;
    procedure CallbackMsg(PanelMsg: string; AddMsg: boolean = False);
    procedure CallbackProgress(Progress: Integer = 1; ProgressMax: Integer = 0);
  public
    constructor Create(aOwner: TComponent; aNotes: TRichEdit; aCallbackMsg: TnOptsCallback = nil; aCallbackProgress: TnOptsCallbackProgress);

    property Notes: TRichEdit read fNotes;
  end;

var
  nOpts: TnOpts;

implementation

{$R *.dfm}

constructor TnOpts.Create(aOwner: TComponent; aNotes: TRichEdit; aCallbackMsg: TnOptsCallback = nil; aCallbackProgress: TnOptsCallbackProgress);
begin
  inherited Create(aOwner);
  fNotes := aNotes;
  fCallbackMsg := aCallbackMsg;
  fCallbackProgress := aCallbackProgress;
end;

procedure TnOpts.CallbackMsg(PanelMsg: string; AddMsg: boolean = False);
begin
  if Assigned(fCallbackMsg) then
    fCallbackMsg(Self, PanelMsg, AddMSg);
end;

procedure TnOpts.CallbackProgress(Progress: Integer = 1; ProgressMax: Integer = 0);
begin
  if Assigned(fCallbackProgress) then
    fCallbackProgress(Self, Progress, ProgressMax);
end;

procedure TnOpts.GUIControl(Sender: TObject);
var Msg: string;
begin
  AddChar1.Enabled := Opt1.Checked;
  Label1.Enabled := Opt1.Checked;
  Chk1.Enabled := Opt1.Checked;
  Chk2.Enabled := Opt1.Checked;
  AddChar2.Enabled := Opt2.Checked;
  Label3.Enabled := Opt2.Checked;
  Chk3.Enabled := Opt2.Checked;
  Chk4.Enabled := Opt2.Checked;
  AddVal.Enabled := Opt3.Checked;
  Label5.Enabled := Opt3.Checked;
  TakeVal1.Enabled := Opt4.Checked;
  Label7.Enabled := Opt4.Checked;
  Chk5.Enabled := Opt4.Checked;
  Label8.Enabled := Opt4.Checked;
  TakeVal2.Enabled := Opt5.Checked;
  Label13.Enabled := Opt5.Checked;
  Chk6.Enabled := Opt5.Checked;
  Label14.Enabled := Opt5.Checked;
  Conv.Enabled := Opt6.Checked;
  Seed.Enabled := Opt7.Checked;
  Label11.Enabled := Opt7.Checked;
  Chk7.Enabled := Opt7.Checked;
  SplitVal.Enabled := Opt8.Checked;
  splitLabel.Enabled := Opt8.Checked;
  AddLines.Enabled := Opt10.Checked;
  Label18.Enabled := Opt10.Checked;
  RmvLines.Enabled := Opt11.Checked;
  Label20.Enabled := Opt11.Checked;
  Chk8.Enabled := Opt11.Checked;
  FndText.Enabled := Opt12.Checked;
  Label22.Enabled := Opt12.Checked;
  RplText.Enabled := Opt12.Checked;
  Chk9.Enabled := Opt12.Checked;
  Chk10.Enabled := Opt12.Checked;
  SpltTxt.Enabled := Opt13.Checked;
  Chk12.Enabled := Opt13.Checked;
  Chk11.Enabled := Opt14.Checked;
  SpltTxt2.Enabled := Opt15.Checked;
  LineCount.Enabled := Opt16.Checked;
  KeepChars.Enabled := Opt17.Checked;
  RmvChars.Enabled := Opt18.Checked;
  SpltTxt2.Enabled := Opt15.Checked;
  RmvCharsToChars.Enabled := Opt20.Checked;
  if Opt1.Checked then
  begin
    CallbackMsg('Add Leading Chars (' +AddChar1.Text + ');');
    if Chk1.Checked then
    begin
      if Chk2.Checked then
        CallbackMsg(' Reversed Suffix', True)
      else
        CallbackMsg(' Add Suffix', True);
    end;
  end else if Opt2.Checked then
  begin
    CallBackMsg('Add Trailing Chars (' +AddChar2.Text + ');';
    if Chk3.Checked then
    begin
      if Chk4.Checked then
        CallBackMsg(' Reversed Prefix', True)
      else
        CallBackMsg(' Add Prefix', True);
    end;
  end
  else if Opt3.Checked then CallBackMsg('Add ' + IntToStr(AddVal.Value) + ' Spaces')
  else if Opt4.Checked then
  begin
    CallBackMsg('Take ' + IntToStr(TakeVal1.Value) + ' Leading Spaces;');
    if Chk5.Checked then CallBackMsg(' Take Leading Chars', True);
  end
  else if Opt5.Checked then
  begin
    CallBackMsg('Take ' + IntToStr(TakeVal2.Value) + ' Trailing Spaces;');
    if Chk6.Checked then CallBackMsg(' Take Trailing Chars', True);
  end
  else if Opt6.Checked then CallBackMsg('Convert all to ' + Conv.Text)
  else if Opt7.Checked then
  begin
    CallBackMsg('Generate ' + IntToStr(Seed.Value) + ' random characters;');
    if Chk7.Checked then CallBackMsg('  New Line', True);
  end
  else if Opt8.Checked then CallBackMsg('Lines split after ' + IntToStr(SplitVal.Value) + ' characters')
  else if Opt9.Checked then CallBackMsg('Remove blank lines!.')
  else if Opt10.Checked then CallBackMsg('Add ' + IntToStr(AddLines.Value) + ' lines!.')
  else if Opt11.Checked then
  begin
    if Chk8.Checked then CallBackMsg('Remove ' + IntToStr(RmvLines.Value) + ' lines and characters!.')
   else CallBackMsg('Remove ' + IntToStr(RmvLines.Value) + ' lines!.');
  end
  else if Opt12.Checked then
  begin
    if Chk9.Checked then
    begin
      if Chk10.Checked then CallBackMsg('Convert all (Matching Case, Whole Word) ' + FndText.Text + '''s to ' + RplText.Text + '!.')
      else CallBackMsg('Convert all (Matching Case) ' + FndText.Text + '''s to ' + RplText.Text + '!.')
    end
      else
    begin
      if Chk10.Checked then CallBackMsg('Convert all (Whole Word) ' + FndText.Text + '''s to ' + RplText.Text + '!.')
      else CallBackMsg('Convert all ' + FndText.Text + '''s to ' + RplText.Text + '!.');
    end
  end
  else if Opt13.Checked then
  begin
    if Chk12.Checked then CallBackMsg('Split lines after the characters "' + SpltTxt.Text + '" only if more characters exist after split position.')
    else CallBackMsg('Split lines after the characters "' + SpltTxt.Text + '"');
  end
    else if Opt14.Checked then
  begin
    if Chk11.Checked then CallBackMsg('Insert ascending numeral values, starting with ' + LeadChars.Text)
    else CallBackMsg('Insert ascending numeral values.');
  end
  else if Opt15.Checked then CallBackMsg('Split lines before the characters "' + SpltTxt2.Text + '"')
  else if Opt16.Checked then CallBackMsg('Remove every ' + LineCount.Text + Label28.Caption)
  else if Opt17.Checked then CallBackMsg('Remove line/s that do not contain "' + KeepChars.Text + '"')
  else if Opt18.Checked then CallBackMsg('Remove line/s that contain the characters "' + RmvChars.Text + '"')
  else if Opt19.Checked then CallBackMsg('Remove all duplicate lines.')
  else CallBackMsg('Remove all characters on line/s up to and including the character "' + RmvCharsToChars.Text + '"');
end;

procedure TnOpts.LineCounter;
begin
  if LineCount.Value <= 1 then LineCount.Value := 2;
  if (LineCount.Value <> 12) and (Copy(LineCount.Text, LineCount.GetTextLen, 1) = '2') then Label28.Caption := 'nd line.'
  else if (LineCount.Value <> 13) and (Copy(LineCount.Text, LineCount.GetTextLen, 1) = '3') then Label28.Caption := 'rd line.'
  else if (LineCount.Value <> 11) and (Copy(LineCount.Text, LineCount.GetTextLen, 1) = '1') then Label28.Caption := 'st line.'
  else Label28.Caption := 'th line.';
end;

procedure TnOpts.LineCountChange(Sender: TObject);
begin
LineCounter;
GUIControl(Sender);
end;

procedure TnOpts.Chk11Click(Sender: TObject);
begin
GUIControl(Sender);
LeadChars.Enabled := Chk11.Checked;
Label25.Enabled := Chk11.Checked;
end;

end.

Open in new window


and the dfm:
object nOpts: TnOpts
  Left = 2014
  Top = 62
  BorderIcons = [biSystemMenu]
  BorderStyle = bsSingle
  Caption = 'Notepad Options'
  ClientHeight = 674
  ClientWidth = 647
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Position = poScreenCenter
  PixelsPerInch = 96
  TextHeight = 13
  object ScrollBox1: TScrollBox
    Left = 0
    Top = 0
    Width = 647
    Height = 674
    VertScrollBar.ButtonSize = 30
    VertScrollBar.Position = 321
    VertScrollBar.Size = 1000
    Align = alClient
    TabOrder = 0
    ExplicitWidth = 1223
    ExplicitHeight = 830
    object Panel1: TPanel
      Left = 32
      Top = -299
      Width = 465
      Height = 969
      BevelOuter = bvNone
      TabOrder = 0
      object Label1: TLabel
        Left = 184
        Top = 8
        Width = 134
        Height = 13
        Caption = 'to the begining of each line!.'
        Enabled = False
      end
      object Label2: TLabel
        Left = 16
        Top = 80
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label3: TLabel
        Left = 184
        Top = 96
        Width = 112
        Height = 13
        Caption = 'to the end of each line!.'
        Enabled = False
      end
      object Label4: TLabel
        Left = 16
        Top = 168
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label5: TLabel
        Left = 144
        Top = 184
        Width = 171
        Height = 13
        Caption = 'spaces to the begining of each line!.'
      end
      object Label6: TLabel
        Left = 16
        Top = 208
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label7: TLabel
        Left = 144
        Top = 224
        Width = 34
        Height = 13
        Caption = 'spaces'
        Enabled = False
      end
      object Label8: TLabel
        Left = 283
        Top = 224
        Width = 145
        Height = 13
        Caption = 'from the begining of each line!.'
        Enabled = False
      end
      object Label9: TLabel
        Left = 16
        Top = 288
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label10: TLabel
        Left = 16
        Top = 328
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label11: TLabel
        Left = 168
        Top = 344
        Width = 85
        Height = 13
        Caption = 'random charactes'
        Enabled = False
      end
      object Label12: TLabel
        Left = 16
        Top = 248
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label13: TLabel
        Left = 144
        Top = 264
        Width = 34
        Height = 13
        Caption = 'spaces'
        Enabled = False
      end
      object Label14: TLabel
        Left = 283
        Top = 264
        Width = 123
        Height = 13
        Caption = 'from the end of each line!.'
        Enabled = False
      end
      object Label15: TLabel
        Left = 16
        Top = 368
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object splitLabel: TLabel
        Left = 182
        Top = 384
        Width = 113
        Height = 13
        Caption = 'characters in each line!.'
      end
      object Label16: TLabel
        Left = 16
        Top = 408
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label17: TLabel
        Left = 16
        Top = 448
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label18: TLabel
        Left = 144
        Top = 464
        Width = 106
        Height = 13
        Caption = 'lines to the begining!...'
        Enabled = False
      end
      object Label19: TLabel
        Left = 16
        Top = 488
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label20: TLabel
        Left = 160
        Top = 505
        Width = 21
        Height = 13
        Caption = 'lines'
        Enabled = False
      end
      object Label21: TLabel
        Left = 16
        Top = 528
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label22: TLabel
        Left = 368
        Top = 545
        Width = 9
        Height = 13
        Caption = 'to'
        Enabled = False
      end
      object Label23: TLabel
        Left = 16
        Top = 568
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label24: TLabel
        Left = 16
        Top = 648
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label25: TLabel
        Left = 336
        Top = 664
        Width = 106
        Height = 13
        Caption = 'leading each insertion.'
        Enabled = False
      end
      object Label26: TLabel
        Left = 16
        Top = 608
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label27: TLabel
        Left = 16
        Top = 688
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label28: TLabel
        Left = 168
        Top = 706
        Width = 31
        Height = 13
        Caption = 'nd line'
      end
      object Label29: TLabel
        Left = 16
        Top = 728
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label30: TLabel
        Left = 16
        Top = 768
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label31: TLabel
        Left = 16
        Top = 808
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label32: TLabel
        Left = 16
        Top = 848
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label33: TLabel
        Left = 16
        Top = 888
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label34: TLabel
        Left = 16
        Top = 928
        Width = 11
        Height = 13
        Caption = 'Or'
      end
      object Label35: TLabel
        Left = 120
        Top = 945
        Width = 111
        Height = 13
        Caption = 'line if all characters are '
      end
      object Opt1: TRadioButton
        Left = 8
        Top = 8
        Width = 41
        Height = 17
        Caption = 'Add'
        TabOrder = 0
        OnClick = GUIControl
      end
      object AddChar1: TEdit
        Left = 56
        Top = 5
        Width = 121
        Height = 21
        Enabled = False
        TabOrder = 1
        Text = '//'
        OnChange = GUIControl
      end
      object Chk1: TCheckBox
        Left = 24
        Top = 32
        Width = 153
        Height = 17
        Caption = 'and to the end of each line!.'
        Enabled = False
        TabOrder = 2
        OnClick = GUIControl
      end
      object Chk2: TCheckBox
        Left = 24
        Top = 56
        Width = 289
        Height = 17
        Caption = 'Reverse string before adding to end of line!. (a bc = cb a)'
        Enabled = False
        TabOrder = 3
        OnClick = GUIControl
      end
      object Opt2: TRadioButton
        Left = 8
        Top = 96
        Width = 41
        Height = 17
        Caption = 'Add'
        TabOrder = 4
        OnClick = GUIControl
      end
      object AddChar2: TEdit
        Left = 56
        Top = 93
        Width = 121
        Height = 21
        Enabled = False
        TabOrder = 5
        Text = '//'
        OnChange = GUIControl
      end
      object Chk3: TCheckBox
        Left = 24
        Top = 120
        Width = 177
        Height = 17
        Caption = 'and to the begining of each line!.'
        Enabled = False
        TabOrder = 6
        OnClick = GUIControl
      end
      object Chk4: TCheckBox
        Left = 24
        Top = 144
        Width = 313
        Height = 17
        Caption = 'Reverse string before adding to begining of line!. (a bc = cb a)'
        Enabled = False
        TabOrder = 7
        OnClick = GUIControl
      end
      object Opt3: TRadioButton
        Left = 8
        Top = 184
        Width = 41
        Height = 17
        Caption = 'Add'
        Checked = True
        TabOrder = 8
        TabStop = True
        OnClick = GUIControl
      end
      object AddVal: TSpinEdit
        Left = 56
        Top = 181
        Width = 81
        Height = 22
        MaxValue = 255
        MinValue = 1
        TabOrder = 9
        Value = 1
        OnChange = GUIControl
      end
      object Opt4: TRadioButton
        Left = 8
        Top = 224
        Width = 49
        Height = 17
        Caption = 'Take'
        TabOrder = 10
        OnClick = GUIControl
      end
      object TakeVal1: TSpinEdit
        Left = 56
        Top = 220
        Width = 81
        Height = 22
        Enabled = False
        MaxValue = 255
        MinValue = 1
        TabOrder = 11
        Value = 1
        OnChange = GUIControl
      end
      object Chk5: TCheckBox
        Left = 184
        Top = 223
        Width = 97
        Height = 17
        Caption = '(and characters)'
        Enabled = False
        TabOrder = 12
        OnClick = GUIControl
      end
      object Opt6: TRadioButton
        Left = 8
        Top = 304
        Width = 81
        Height = 17
        Caption = 'Convert all to'
        TabOrder = 13
        OnClick = GUIControl
      end
      object Conv: TComboBox
        Left = 96
        Top = 301
        Width = 145
        Height = 21
        Enabled = False
        ItemIndex = 0
        TabOrder = 14
        Text = 'Lowercase!.'
        OnChange = GUIControl
        OnClick = GUIControl
        Items.Strings = (
          'Lowercase!.'
          'Uppercase!.'
          'ASCII'
          'Hexadecimal!.'
          'Binary!.'
          'HTML/Javascript Escape!.'
          'HTML/Javascript Unescape!.'
          'String!.')
      end
      object Opt7: TRadioButton
        Left = 8
        Top = 344
        Width = 65
        Height = 17
        Caption = 'Generate'
        TabOrder = 15
        OnClick = GUIControl
      end
      object Seed: TSpinEdit
        Left = 80
        Top = 341
        Width = 81
        Height = 22
        Enabled = False
        MaxValue = 255
        MinValue = 1
        TabOrder = 16
        Value = 32
        OnChange = GUIControl
      end
      object Chk7: TCheckBox
        Left = 256
        Top = 343
        Width = 89
        Height = 17
        Caption = 'on a new line!.'
        Enabled = False
        TabOrder = 17
        OnClick = GUIControl
      end
      object Opt5: TRadioButton
        Left = 8
        Top = 264
        Width = 49
        Height = 17
        Caption = 'Take'
        TabOrder = 18
        OnClick = GUIControl
      end
      object TakeVal2: TSpinEdit
        Left = 56
        Top = 261
        Width = 81
        Height = 22
        Enabled = False
        MaxValue = 255
        MinValue = 1
        TabOrder = 19
        Value = 1
        OnChange = GUIControl
      end
      object Chk6: TCheckBox
        Left = 184
        Top = 263
        Width = 97
        Height = 17
        Caption = '(and characters)'
        Enabled = False
        TabOrder = 20
        OnClick = GUIControl
      end
      object Opt9: TRadioButton
        Left = 8
        Top = 424
        Width = 177
        Height = 17
        Caption = 'Remove only blank (empty) lines!.'
        TabOrder = 21
        OnClick = GUIControl
      end
      object Opt8: TRadioButton
        Left = 8
        Top = 384
        Width = 81
        Height = 17
        Caption = 'Split line after'
        TabOrder = 22
        OnClick = GUIControl
      end
      object SplitVal: TSpinEdit
        Left = 97
        Top = 381
        Width = 81
        Height = 22
        MaxValue = 5000
        MinValue = 1
        TabOrder = 23
        Value = 64
        OnChange = GUIControl
      end
      object Opt10: TRadioButton
        Left = 8
        Top = 463
        Width = 41
        Height = 17
        Caption = 'Add'
        TabOrder = 24
        OnClick = GUIControl
      end
      object AddLines: TSpinEdit
        Left = 54
        Top = 461
        Width = 81
        Height = 22
        Enabled = False
        MaxValue = 255
        MinValue = 1
        TabOrder = 25
        Value = 1
        OnChange = GUIControl
      end
      object Opt11: TRadioButton
        Left = 8
        Top = 504
        Width = 65
        Height = 17
        Caption = 'Remove'
        TabOrder = 26
        OnClick = GUIControl
      end
      object RmvLines: TSpinEdit
        Left = 72
        Top = 501
        Width = 81
        Height = 22
        Enabled = False
        MaxValue = 255
        MinValue = 1
        TabOrder = 27
        Value = 1
        OnChange = GUIControl
      end
      object Chk8: TCheckBox
        Left = 187
        Top = 504
        Width = 190
        Height = 17
        Caption = '(and characters) from the begining!...'
        Enabled = False
        TabOrder = 28
        OnClick = GUIControl
      end
      object Opt12: TRadioButton
        Left = 8
        Top = 544
        Width = 73
        Height = 17
        Caption = 'Convert all'
        TabOrder = 29
        OnClick = GUIControl
      end
      object FndText: TEdit
        Left = 179
        Top = 541
        Width = 78
        Height = 21
        Enabled = False
        TabOrder = 30
        OnChange = GUIControl
      end
      object RplText: TEdit
        Left = 384
        Top = 541
        Width = 81
        Height = 21
        Enabled = False
        TabOrder = 31
        OnChange = GUIControl
      end
      object Chk9: TCheckBox
        Left = 81
        Top = 544
        Width = 97
        Height = 17
        Caption = '(matching case)'
        Checked = True
        Enabled = False
        State = cbChecked
        TabOrder = 32
        OnClick = GUIControl
      end
      object Chk10: TCheckBox
        Left = 264
        Top = 544
        Width = 97
        Height = 17
        Caption = '(as whole words)'
        Enabled = False
        TabOrder = 33
        OnClick = GUIControl
      end
      object Opt13: TRadioButton
        Left = 8
        Top = 584
        Width = 169
        Height = 17
        Caption = 'Split line/s after the characters '
        TabOrder = 34
        OnClick = GUIControl
      end
      object SpltTxt: TEdit
        Left = 176
        Top = 581
        Width = 49
        Height = 21
        Enabled = False
        TabOrder = 35
        OnChange = GUIControl
      end
      object Opt14: TRadioButton
        Left = 8
        Top = 664
        Width = 153
        Height = 17
        Caption = 'Incremental number insertion'
        TabOrder = 36
        OnClick = GUIControl
      end
      object Chk11: TCheckBox
        Left = 168
        Top = 664
        Width = 137
        Height = 17
        Caption = 'and with the character/s'
        Enabled = False
        TabOrder = 37
        OnClick = Chk11Click
      end
      object LeadChars: TEdit
        Left = 307
        Top = 661
        Width = 25
        Height = 21
        Enabled = False
        MaxLength = 1
        TabOrder = 38
        Text = 'C0'
        OnChange = GUIControl
      end
      object Chk12: TCheckBox
        Left = 228
        Top = 584
        Width = 237
        Height = 17
        Caption = 'only if more characters exist after split position'
        Checked = True
        Enabled = False
        State = cbChecked
        TabOrder = 39
        OnClick = GUIControl
      end
      object Opt15: TRadioButton
        Left = 8
        Top = 624
        Width = 177
        Height = 17
        Caption = 'Split line/s before the characters'
        TabOrder = 40
        OnClick = GUIControl
      end
      object SpltTxt2: TEdit
        Left = 184
        Top = 623
        Width = 49
        Height = 21
        Enabled = False
        TabOrder = 41
        OnChange = GUIControl
      end
      object Opt16: TRadioButton
        Left = 8
        Top = 704
        Width = 89
        Height = 17
        Caption = 'Remove every'
        TabOrder = 42
        OnClick = GUIControl
      end
      object LineCount: TSpinEdit
        Left = 104
        Top = 704
        Width = 65
        Height = 22
        Enabled = False
        MaxValue = 0
        MinValue = 0
        TabOrder = 43
        Value = 2
        OnChange = LineCountChange
        OnClick = LineCountChange
        OnEnter = LineCountChange
      end
      object Opt17: TRadioButton
        Left = 8
        Top = 744
        Width = 257
        Height = 17
        Caption = 'Remove line/s that do not contain the characters'
        TabOrder = 44
        OnClick = GUIControl
      end
      object KeepChars: TEdit
        Left = 264
        Top = 742
        Width = 121
        Height = 21
        Enabled = False
        TabOrder = 45
        OnChange = GUIControl
      end
      object Opt18: TRadioButton
        Left = 8
        Top = 784
        Width = 217
        Height = 17
        Caption = 'Remove line/s that contain the characters'
        TabOrder = 46
        OnClick = GUIControl
      end
      object RmvChars: TEdit
        Left = 232
        Top = 782
        Width = 121
        Height = 21
        TabOrder = 47
        OnChange = GUIControl
      end
      object Opt19: TRadioButton
        Left = 8
        Top = 824
        Width = 129
        Height = 17
        Caption = 'Remove duplicate lines'
        TabOrder = 48
        OnClick = GUIControl
      end
      object Opt20: TRadioButton
        Left = 8
        Top = 864
        Width = 201
        Height = 17
        Caption = 'Remove all characters on line/s up to'
        TabOrder = 49
        OnClick = GUIControl
      end
      object RmvCharsToChars: TEdit
        Left = 208
        Top = 864
        Width = 121
        Height = 21
        Enabled = False
        TabOrder = 50
        OnChange = GUIControl
      end
      object Opt21: TRadioButton
        Left = 8
        Top = 904
        Width = 129
        Height = 17
        Caption = 'Remove all line breaks'
        TabOrder = 51
      end
      object Opt22: TRadioButton
        Left = 8
        Top = 944
        Width = 49
        Height = 17
        Caption = 'Break'
        TabOrder = 52
      end
      object brklnchr: TComboBox
        Left = 232
        Top = 941
        Width = 81
        Height = 21
        ItemIndex = 0
        TabOrder = 53
        Text = 'Uppercase'
        Items.Strings = (
          'Uppercase'
          'Lowercase')
      end
      object Chk13: TCheckBox
        Left = 320
        Top = 944
        Width = 137
        Height = 17
        Caption = 'and including numerals.'
        TabOrder = 54
      end
      object BrkPos: TComboBox
        Left = 59
        Top = 941
        Width = 57
        Height = 21
        ItemIndex = 0
        TabOrder = 55
        Text = 'Before'
        Items.Strings = (
          'Before'
          'After')
      end
    end
  end
end

Open in new window


only 3 event handlers remain.
the common guicontrol and 2 others
main form ... you have a form resize ... odd one.

add a TPanel
Put the progressbar inside it
set panel align = alBottom
alignwithmargins = true
set all margins to 10

set progressbar to align to alClient

set richedit to align = alClient

now, no more resize code is needed.
your richedit grows with your form as does the progressbar
The DoIt code should by in unit2
after moving it, your unit1 looks like this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Gauges, ComCtrls, Menus, StdCtrls, StrUtils;

type
  TMain = class(TForm)
    Notes: TRichEdit;
    Menu: TMainMenu;
    Menu1: TMenuItem;
    Stat: TStatusBar;
    Menu2: TMenuItem;
    pnlBar: TPanel;
    pBar: TGauge;
    procedure FormResize(Sender: TObject);
    procedure Menu2Click(Sender: TObject);
    procedure Menu1Click(Sender: TObject);
  private
    fOpts: TForm;
    procedure CallbackMsg(Sender: TObject; PanelMsg: string; AddMsg: boolean = False);
    procedure CallbackProgress(Sender: TObject; Progress: Integer = 1; Max: Integer = 0);
  public
    constructor Create(aOwner: TComponent); override;
  end;

var
  Main: TMain;

const Capt: string = 'Notepad tool    ';

implementation

uses Unit2;

{$R *.dfm}

constructor TMain.Create(aOwner: TComponent);
begin
  inherited Create(aOwner);
  fOpts := nil;
  CreateOptions;
end;

procedure TMain.CreateOptions;
begin
  if fOpts = nil then
    fOpts := TnOpts.Create(Self, Notes, CallbackMsg, CallbackProgress);
end;

procedure TMain.CallbackMsg(Sender: TObject; PanelMsg: string; AddMsg: boolean = False);
begin
  if not AddMsg then
    Stat.Panels[PanelId] := PanelMsg
  else
    Stat.Panels[PanelId] := Stat.Panels[PanelId] + PanelMsg;
  Stat.Update;
  // Application.ProcessMessages;
end;

procedure TMain.CallbackProgress(Sender: TObject; Progress: Integer = 1; Max: Integer = 0);
begin
  // Max = -1 > Progress = position
  if Max = -1 then
    pbar.Progress Progress
  else if Max = 0 then // add progress
    pBar.Progress := pBar.Progress + Progress
  else if Max > 0 then
  begin
    pBar.Progress := 0;
    pBar.Max := Max;
    pBar.Progress := Progress;
  end;
  pBar.Update;
  // Application.ProcessMessages;
end;

procedure TMain.FormResize(Sender: TObject);
begin
end;

procedure TMain.Menu2Click(Sender: TObject);
begin
  CreateOptions;
  fOpts.Show;
end;

procedure TMain.Menu1Click(Sender: TObject);
begin
  // CreateOptions;
  if fOpts <> nil then
    fOpts.DoIt;
end;

end.

Open in new window

the ncanc all of the place is confusing ...

it's a lot easier to add the line :

if not ncanc  then exit
off course the procedure DoIt is slow ...
why ?
well for every line it passes in the richedit ... it does the following :

wait for main thread > this is implicit
step the progressbar
redraw the progress  >> wait for a draw lock, draw, unlock

disabling the feedback, might be your best performance gain !
and disabling the richedit from redrawing itself after each line change !

i bumped into some compilation errors in earlier post code ... hadn't compiled yet
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A massive thanks I must hear by send to you Geert!, in fact I would be willing to send you money if I could!, this is a small project that I wrote many, many years ago (and yes I have been adding little bits in the options over the years, hence the reason it is soo large and has become so complicated).
I am certain that with your help that I will be very much more informed and will be a better programmer!, I have never really asked for help before I just merely persisted with things until such a point that I got them to work (albeit perhaps not in the most desirable fashion of programming lol)
And sorry for the late reply too, I have been out of town and traveling about the last two weeks but I will now start to take note of all of your suggestions and of your help!.
But wouldn't you say or admit that the options that I have made for alterations in the notepad (richedit) quite unique? it is handy for lining up chunks of code and to break down large clumped sources (say from webpages), I also will of course allow you to comment out entire sections of code in a matter of clicks and yeah with such features I would very much like to get it all working spic and spec, to run without any bug or malfunction, im sure you understand :)
Well I am unsure how I can thank you anymore and I am thinking I should close this question, I might do the changes you have offered first and then come back to close the question (just in case you would like to add any further comments) but please give me a couple of days to do this little job, I will look through your source tonight but i will get to work on adding the changes to my code in the next couple of days, im a busy man at the moment (plus I am drunk as well at the moment, 3/4 of a bottle of vodka is currently being processed by my stomach, liver and intestines lol)
But in any effect Geert, you are a bloody legend!, a legend for giving me the help I asked for and a legend for being understanding with my drunken self lol :)
a legend ? not really :)
http://support.experts-exchange.com/customer/portal/articles/962258
but thanks for the kudos

only A3 has passed the 2/5 mark for the legend status
getting to legend will not be for me: at my current rate of 300k per year, ... i'm not gonna live around another 270 years

besides, legends only become legends after their passing