unit MyUtils;

INTERFACE

USES SysUtils, Dialogs;

function  StripTrailingSlash(DirName : string) : string;
procedure MyDeleteFiles(FSpec : string);
function  SingleToE13Pt6E2(X : single) : string;
function  REqual(R1, R2 : single) : boolean;


IMPLEMENTATION

{$RANGECHECKS OFF}

//--------------------------------------------------------------------------
function StripTrailingSlash(DirName : string) : string;
var
  I : integer;
  S : string;
begin
  I := Length(DirName);

  if (I <= 0) then begin
     StripTrailingSlash := DirName;
     exit;
  end;

  if (DirName[I] = '\') then I := I - 1;
  S := Copy(DirName, 0, I);
  StripTrailingSlash :=  S;
end;

//--------------------------------------------------------------------------
procedure MyDeleteFiles(FSpec : string);
var
   I : integer;
   P, S : string;
   SearchRec : TSearchRec;
begin
   P := ExtractFilePath(FSpec);
   I := SysUtils.FindFirst(FSpec, faAnyFile, SearchRec);
   while (I = 0) do begin
      S := P + SearchRec.Name;
      SysUtils.DeleteFile(S);
      I := SysUtils.FindNext(SearchRec);
   end;
   SysUtils.FindClose(SearchRec);
end;

//------------------------------------------------------------------------
function SingleToE13Pt6E2(X : single) : string;
begin
   Result := FormatFloat('#0.000000E+00;#0.000000E+00', X);
end;

// ----------------------------------------------------------
function REqual(R1, R2 : single) : boolean;
var
   S1, S2 : string;
begin
   S1 := FormatFloat(' 0.0000000E+00;-0.0000000E+00', R1);    // string of form '-1.2345678E+12'
   S2 := FormatFloat(' 0.0000000E+00;-0.0000000E+00', R2);    // string of form '-1.2345678E+12'
   Result := FALSE;
   if (CompareText(S1,S2) = 0) then Result := TRUE;
end;


END.
