git-svn-id: https://192.168.0.254/svn/Proyectos.AbetoDesign_FactuGES/trunk@2 93f398dd-4eb6-7a46-baf6-13f46f578da2
93 lines
2.5 KiB
ObjectPascal
93 lines
2.5 KiB
ObjectPascal
unit uReferenciasUtils;
|
|
|
|
interface
|
|
|
|
|
|
{ Si ARef1 < ARef2 -> Result := -1
|
|
Si ARef1 = ARef2 -> Result := 0
|
|
Si ARef1 > ARef2 -> Result := 1 }
|
|
function CompararReferencias(const ARef1, ARef2 : String) : Integer;
|
|
|
|
function DarReferenciaSiguiente(const Referencia: String): String;
|
|
|
|
implementation
|
|
|
|
uses
|
|
JclAnsiStrings, cxVariants, SysUtils;
|
|
|
|
function CompararReferencias(const ARef1, ARef2 : String) : Integer;
|
|
var
|
|
Aux1, Aux2 : String;
|
|
AuxInt1, AuxInt2: Double;
|
|
Rpl : Char;
|
|
begin
|
|
Rpl := ' ';
|
|
Aux1 := StrReplaceButChars(ARef1, AnsiDecDigits, Rpl);
|
|
Aux1 := StrRemoveChars(Aux1, AnsiWhiteSpace);
|
|
Aux2 := StrReplaceButChars(ARef2, AnsiDecDigits, Rpl);
|
|
Aux2 := StrRemoveChars(Aux2, AnsiWhiteSpace);
|
|
|
|
if StrIsDigit(Aux1) and StrIsDigit(Aux2) then
|
|
begin
|
|
AuxInt1 := StrToFloatSafe(Aux1);
|
|
AuxInt2 := StrToFloatSafe(Aux2);
|
|
Result := VarCompare(AuxInt1, AuxInt2)
|
|
end
|
|
else
|
|
Result := VarCompare(Aux1, Aux2)
|
|
end;
|
|
|
|
|
|
{ Se utiliza en las reglas de negocio del servidor y
|
|
devuelve la conexión utilizada por el BusinessProcessor para
|
|
procesar los deltas. }
|
|
function DarReferenciaSiguiente(const Referencia: String): String;
|
|
var
|
|
ParteEntera, ParteCaracter: String;
|
|
Semaforo: Boolean;
|
|
i, LongitudParteEntera: Integer;
|
|
begin
|
|
//Por defecto la parte caracter será todo
|
|
ParteCaracter := Copy(Referencia, 1, length(Referencia));
|
|
Semaforo:= false;
|
|
for i := 0 to length(Referencia) do
|
|
begin
|
|
if (Referencia[i] in ['0','1','2','3','4','5','6','7','8','9']) then
|
|
begin
|
|
if not Semaforo then
|
|
begin
|
|
//Cogemos el resto de la cadena suponiendo que no hay más caracter
|
|
ParteEntera := Copy(Referencia, i, length(Referencia)+1);
|
|
Semaforo := true;
|
|
end;
|
|
end
|
|
else
|
|
begin
|
|
//Volvemos a asignar la parte caracter ya que hemos encontrado otro
|
|
//e inicializamos el semáforo para volver a coger la parte entera si encontramos
|
|
//algún número
|
|
ParteCaracter := Copy(Referencia, 1, i);
|
|
Semaforo := False;
|
|
end;
|
|
end;
|
|
|
|
LongitudParteEntera := Length(ParteEntera);
|
|
//Si no tenemos ningún número en parte entera asignamos 1 por defecto
|
|
try
|
|
i := StrToInt(ParteEntera);
|
|
except
|
|
i := 1;
|
|
end;
|
|
|
|
//Incrementamos y rellenamos con ceros, en el caso de ser necesario
|
|
Inc(i);
|
|
ParteEntera := IntToStr(i);
|
|
for i:=Length(ParteEntera) to LongitudParteEntera-1 do
|
|
ParteEntera := '0' + ParteEntera;
|
|
|
|
Result := ParteCaracter + ParteEntera;
|
|
end;
|
|
|
|
|
|
end.
|