Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   funcion que me regresa un arreglo (https://www.clubdelphi.com/foros/showthread.php?t=69520)

julyus 24-08-2010 00:27:14

funcion que me regresa un arreglo
 
hola amigo hace 3 años no programo en delphi algunas cosas las he olvidado quiero crear una function que me regrese un array

ejemplo
Código Delphi [-]
type
    TEventslistArray = array[0..58] of string;



Código Delphi [-]
function TFMListenerService.SearchEvents( NewEventlistArray: TEventslistArray);
var
count : integer;
begin
end;

mi pregunta es que tengo que enviarle 25 parametros a esta funcion para evaluarlos dentro de esta debo nombrar los 25 parametro y sus tipos de campo diciendo que NewEventlistArray me devolvera mi arreglo ya evaluado??

asi??

Código Delphi [-]
function TFMListenerService.SearchEvents(a : integer,b : string ,d... NewEventlistArray: TEventslistArray);
var
count : integer;
begin
end;

gracias si alguien me explica :D:D:D

ecfisa 24-08-2010 01:32:23

Hola julyus.

Primero te comento que las funciones declaradas así:
Código Delphi [-]
function TFMListenerService.SearchEvents( NewEventlistArray: TEventslistArray);
te van a dar error de sintáxis. Tendrías que declararlas así:
Código Delphi [-]
function TFMListenerService.SearchEvents( NewEventlistArray: TEventslistArray): Resultado;

Ahora, si lo que enviás es un arreglo de strings y la función devuelve el mismo arreglo modificado, me parece,
que te conviene usar TStrings.

Por ejemplo esta función te devuelve los strings sin el primer caracter:
Código Delphi [-]
function TForm1.FuncionDemo(Lista: TStrings): TStrings;
var
  i: Integer;
begin
  for i:= 0 to Lista.Count - 1 do
   Lista[i]:= Copy(Lista[i],2,Length(Lista[i]));
  Result:= Lista;
end;

Un ejemplo de llamada:
Código Delphi [-]
var
  Ts: TStrings;
begin
  Ts:= TStringList.Create;
  try
    Ts.Add('Uno');    
    Ts.Add('Dos');
    Ts.Add('Tres'); 
    Ts:= FuncionDemo(Ts);
    ListBox1.Items:= Ts;
  finally
    Ts.Free;
  end;

Espero que sea eso lo que andas buscando... :)

Saludos.

julyus 24-08-2010 18:51:06

confused ??
 
no se si te entendi bien
Código Delphi [-]type TEventslistArray = array[0..58] of string; function SearchEvents(sIMEI: string; iCompanyId : integer; sVehicleId : string; iCurrSpeed,iCurrRPM,iAccDeccValue :integer; bDIN1, bDIN2, bDIN3, bDIN4 : Boolean; fAIN1, fAIN2, fAIN3, fAIN4 : Extended; iGSMSignal, iCurrentProfile : integer; fAcelerometerData, fGPSSpeed, fPowerSuplyVoltage, fBatteryVoltage, fBatteryCurrent, fGPSPower, fPCBTemperature, fTempSensor1, fTempSensor2, fTempSensor3, fFuelCounter, sButtonInput, fCan0, fCan1, fCan2, fCan3, fCan4, fCan5, fCan6, fCan7, fCan8, fCan9 : Extended; bGeoZone1, bGeoZone2, bGeoZone3, bGeoZone4, bGeoZone5, bGeoZone6, bGeoZone7, bGeoZone8, bGeoZone9, bGeoZone10, bGeoZone11, bGeoZone12, bGeoZone13, bGeoZone14, bGeoZone15, bGeoZone16, bGeoZone17, bGeoZone18, bGeoZone19, bGeoZone20 : Boolean; fVirtualOdometer : string; sCurrOperatorCode : Extended; bMovement : Bool ) :TEventslistArray;


nose si mi :TEventslistArray; devolvera mi arreglo ??
esto es un web service por eso no lo he probado en forms no se si funciones la otra duda es si tipo los campos se genere algun problema gracias...:confused::confused::confused::confused:

julyus 24-08-2010 19:05:52

confused ??
 
no se si te entendi bien
Código Delphi [-]
Código Delphi type     TEventslistArray = array[0..58] of string;



function SearchEvents(sIMEI: string; iCompanyId : integer;  sVehicleId : string;
            iCurrSpeed,iCurrRPM,iAccDeccValue :integer;
            bDIN1, bDIN2, bDIN3, bDIN4 : Boolean;
            fAIN1, fAIN2,  fAIN3, fAIN4 : Extended;
            iGSMSignal, iCurrentProfile : integer;
            fAcelerometerData, fGPSSpeed,  fPowerSuplyVoltage, fBatteryVoltage, fBatteryCurrent,
            fGPSPower, fPCBTemperature, fTempSensor1, fTempSensor2,
            fTempSensor3, fFuelCounter, sButtonInput, fCan0, fCan1,
            fCan2, fCan3, fCan4, fCan5, fCan6, fCan7, fCan8,  fCan9 : Extended;
            bGeoZone1, bGeoZone2, bGeoZone3,
            bGeoZone4, bGeoZone5, bGeoZone6, bGeoZone7,
            bGeoZone8, bGeoZone9, bGeoZone10, bGeoZone11,
            bGeoZone12, bGeoZone13, bGeoZone14, bGeoZone15,
            bGeoZone16, bGeoZone17, bGeoZone18, bGeoZone19, bGeoZone20 : Boolean;
            fVirtualOdometer : string; sCurrOperatorCode : Extended; bMovement : Bool ) :TEventslistArray; [-]
[-][/delphi]


nose si mi :TEventslistArray; devolvera mi arreglo ??
esto es un web service por eso no lo he probado en forms no se si funciones la otra duda es si tipo los campos se genere algun problema gracias...:confused::confused::confused::confused:

ecfisa 24-08-2010 19:36:12

Hola julyus.

Si la función SearchEvents la declaraste para que devuelva un TEventslistArray y dentro de ella
asignas a la variable Result un TEventsListArray, te va a devolver eso sin duda alguna.

Si no comprendí bién tu duda, por favor hacemelo saber.

Saludos.

julyus 24-08-2010 21:06:31

hola amigo por la ayuda
 
la duda que me queda es si miras los campos que envio tienen tipo, el
array es de tipo string esto me daria errores?
ahora lo que quiero es lo siguiente NewArrayData es un array que va a recibir los resultados de SearchEvents el resultado del array lo voy a pasar a este para hacer un ulitimo proceso
Código Delphi [-]
NewArrayData := SearchEvents(sIMEI, iCompanyId, sVehicleId,
            iCurrSpeed,iCurrRPM,iAccDeccValue,
            bDIN1, bDIN2, bDIN3, bDIN4,
            fAIN1, fAIN2,  fAIN3, fAIN4,
            iGSMSignal, iCurrentProfile ,
            fAcelerometerData, fGPSSpeed,  fPowerSuplyVoltage, fBatteryVoltage, fBatteryCurrent,
            fGPSPower, fPCBTemperature, fTempSensor1, fTempSensor2,
            fTempSensor3, fFuelCounter, sButtonInput, fCan0, fCan1,
            fCan2, fCan3, fCan4, fCan5, fCan6, fCan7, fCan8,  fCan9,
            bGeoZone1, bGeoZone2, bGeoZone3,
            bGeoZone4, bGeoZone5, bGeoZone6, bGeoZone7,
            bGeoZone8, bGeoZone9, bGeoZone10, bGeoZone11,
            bGeoZone12, bGeoZone13, bGeoZone14, bGeoZone15,
            bGeoZone16, bGeoZone17, bGeoZone18, bGeoZone19, bGeoZone20,
fVirtualOdometer, sCurrOperatorCode, bMovement); gracias por tu tiempo :confused::confused::eek::D

ecfisa 24-08-2010 21:24:54

No tenés nada que agradecer.

A ver si con esto solucionamos algo...
Código Delphi [-]
type
  RecSearchEvents = record
    sIMEI: string;
    iCompanyId : integer;
    sVehicleId : string;
    iCurrSpeed,iCurrRPM,iAccDeccValue :integer;
    bDIN1, bDIN2, bDIN3, bDIN4 : Boolean;
    fAIN1, fAIN2,  fAIN3, fAIN4 : Extended;
    iGSMSignal, iCurrentProfile : integer;
    fAcelerometerData, fGPSSpeed,  fPowerSuplyVoltage,
    fBatteryVoltage, fBatteryCurrent, fGPSPower, fPCBTemperature,
    fTempSensor1, fTempSensor2, fTempSensor3, fFuelCounter,
    sButtonInput, fCan0, fCan1, fCan2, fCan3, fCan4, fCan5,
    fCan6, fCan7, fCan8,  fCan9 : Extended;
    bGeoZone1, bGeoZone2, bGeoZone3,
    bGeoZone4, bGeoZone5, bGeoZone6, bGeoZone7,
    bGeoZone8, bGeoZone9, bGeoZone10, bGeoZone11,
    bGeoZone12, bGeoZone13, bGeoZone14, bGeoZone15,
    bGeoZone16, bGeoZone17, bGeoZone18, bGeoZone19,
    bGeoZone20 : Boolean;
    fVirtualOdometer : string;
    sCurrOperatorCode : Extended;
    bMovement : Bool
  end;
  TForm1 = class(TForm)
  private
  public
    function SearchEvents(Param: RecSearchEvents): RecSearchEvents;
  end;


var
  Form1: TForm1;

implementation {$R *.dfm}

function TForm1.SearchEvents(Param: RecSearchEvents): RecSearchEvents;
begin
   // Operaciones de la funcion
  Result:= Param;
end;

En este caso pasas y recibis un RecSearchEvents. (o el nombre que quieras darle)
Tenés que cargar los valores en el record antes de llamar a la función por ej:
Código Delphi [-]
var
  rs:RecSearchEvents;
begin
  rs.sIMEI:= '1934102937340';
  rs.iCompanyID:= 11234; 
  ...
  rs:= SearchEvents(rs); // rs, ahora tiene los valores procesados en la función
end;

Nota: No es necesario, pero al ser tantos campos para una mayor claridad quizá te convenga
declarar el registro así:
Código Delphi [-]
  RecSearchEvents = record
    sIMEI: string;
    iCompanyId : integer;
    sVehicleId : string;
    iCurrSpeed, iCurrRPM, iAccDeccValue :integer;
    bDIN: array[1..4] of Boolean;
    bAIN: array[1..4] of Extended;
    iGSMSignal, iCurrentProfile : integer;
    fAcelerometerData, fGPSSpeed,  fPowerSuplyVoltage,
    fBatteryVoltage, fBatteryCurrent, fGPSPower, fPCBTemperature,
    fTempSensor1, fTempSensor2, fTempSensor3, fFuelCounter,
    sButtonInput: Extended;
    fCan: array[0..9] of Extended;
    bGeoZone: array[1..20] of Boolean;
    fVirtualOdometer : string;
    sCurrOperatorCode : Extended;
    bMovement : Bool
  end;

Es mas o ménos lo que buscabas ?

Saludos.

julyus 25-08-2010 01:02:10

script completo
 
te lo voy a explicar mejor tengo una funcion lacual recibe estos parameros y devuelve un booleano
dentro de esta funcion envian un array "cAVLDataFM4" luego se debe descomponer en varables para un query update

mi primer paso es pasar a variables luego enviarlas a mi funtion array
evaluo y luego le paso el retorno de mi funtion array a un array final
para hacer un insert te preguntaras para que mi funtion array me generara mas rows para mi array final luego con eso hare el insert es por cuestion de manejo que se hace eso mi duda ahora es como paso el resultado de mi funcion a un nuevo array ??:confused:

aca es donde estoy usando lo que te he preguntado eficsa
Código Delphi [-]
function TFMListenerService.UpdateCurrentVehicleData(sIMEI: string;
         cAVLDataFM4: TAVLDataFM4;
         iCompanyId : integer;
         sVehicleId : string;
         iMessageId : integer;
         dCurrOdometer : Double;
         var sErrMess: string): boolean;
var

  iCount: Integer;
  bDIN1,bDIN2,bDIN3,bDIN4 : Boolean;
  fAIN1,fAIN2,fAIN3,fAIN4 : Extended;
  iGSMSignal,iCurrentProfile : integer;
  fAcelerometerData, fGPSSpeed, fPowerSuplyVoltage,
  fBatteryVoltage, fBatteryCurrent,
  fGPSPower, fPCBTemperature,
  fTempSensor1,fTempSensor2,fTempSensor3,
  fFuelCounter,
  fCan0,fCan1,fCan2,fCan3,fCan4,fCan5,fCan6,
  fCan7,fCan8,fCan9,fVirtualOdometer : Extended;
  bGeoZone1,bGeoZone2,bGeoZone3,bGeoZone4,bGeoZone5,
  bGeoZone6,bGeoZone7,bGeoZone8,bGeoZone9,bGeoZone10,
  bGeoZone11,bGeoZone12,bGeoZone13,bGeoZone14,bGeoZone15,
  bGeoZone16,bGeoZone17,bGeoZone18,bGeoZone19,bGeoZone20 : Boolean;
  sButtonInput, sCurrOperatorCode,
  sTimeZone,sParams : string;
  bMovement : Boolean;
  Conn: IConnection;
  sqlQuery : TADOQuery;
  sdUTCPosTimeStamp, sdLocalPosTimeStamp : TSystemTime;
  tTimeZone : TTimeZoneInformation;
  dPositionDate,dPositionTime : TDateTime;
  iEventCode,iHeading,
  iDriveType,iNeedService,
  iCurrSpeed,iCurrRPM,
  iAccDeccValue,iSatellites,
  iHardwareVer,iSoftVer,
  iBateryLevel : integer;
  sDriverId,sChargeId,sGPSsStatus,sEventInfo : string;
  dLatitude,dLongitude : Double;
  NewArrayData :TNewArrayData;
begin
  Result := False;
  try
    sqlQuery := TADOQuery.Create(Self);
    try
      Conn := ConnPool.GetConnection;
      sqlQuery.Connection := Conn.Connection;

      for iCount := 0 to cAVLDataFM4.NumberOfData - 1 do
      begin
        bDIN1 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(1) = 1);
        bDIN2 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(2) = 1);
        bDIN3 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(3) = 1);
        bDIN4 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(4) = 1);
        fAIN1 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(9);
        fAIN2 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(10);
        fAIN3 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(11);
        fAIN4 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(19);
        iGSMSignal := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(21);
        iCurrentProfile := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(22);
        fAcelerometerData := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(23);
        fGPSSpeed := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(24);
        fPowerSuplyVoltage := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(66);
        fBatteryVoltage := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(67);
        fBatteryCurrent := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(68);
        fGPSPower := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(69);
        fPCBTemperature := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(70);
        fTempSensor1 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(72);
        fTempSensor2 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(73);
        fTempSensor3 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(74);
        fFuelCounter := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(76);
        sButtonInput := IntToStr(cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(78));
        fCan0 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(145);
        fCan1 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(146);
        fCan2 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(147);
        fCan3 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(148);
        fCan4 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(149);
        fCan5 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(150);
        fCan6 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(151);
        fCan7 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(152);
        fCan8 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(153);
        fCan9 := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(154);
        bGeoZone1 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(155) = 1);
        bGeoZone2 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(156) = 1);
        bGeoZone3 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(157) = 1);
        bGeoZone4 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(158) = 1);
        bGeoZone5 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(159) = 1);
        bGeoZone6 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(160) = 1);
        bGeoZone7 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(161) = 1);
        bGeoZone8 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(162) = 1);
        bGeoZone9 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(163) = 1);
        bGeoZone10 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(164) = 1);
        bGeoZone11 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(165) = 1);
        bGeoZone12 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(166) = 1);
        bGeoZone13 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(167) = 1);
        bGeoZone14 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(168) = 1);
        bGeoZone15 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(169) = 1);
        bGeoZone16 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(170) = 1);
        bGeoZone17 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(171) = 1);
        bGeoZone18 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(172) = 1);
        bGeoZone19 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(173) = 1);
        bGeoZone20 := (cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(174) = 1);
        fVirtualOdometer := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(199); //Metros
        sCurrOperatorCode := IntToStr(cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(241));
        bMovement := cAVLDataFM4.AVLDataArray[iCount].IOData.ElementValue(240) = 1;

        dPositionDate := DateOf(cAVLDataFM4.AVLDataArray[iCount].TimeStamp);
        dPositionTime := TimeOf(cAVLDataFM4.AVLDataArray[iCount].TimeStamp);

        //  Se obtienen los Eventos Basicos
        iEventCode:= GetEventCode(cAVLDataFM4.AVLDataArray[iCount].IOData);

        // Envio de datos al elvaluador de Eventos
        //Retorno los datos del evaluador a otro arreglo
        NewArrayData := SearchEvents(sIMEI, iCompanyId, sVehicleId,
            iCurrSpeed,iCurrRPM,iAccDeccValue,
            bDIN1, bDIN2, bDIN3, bDIN4,
            fAIN1, fAIN2,  fAIN3, fAIN4,
            iGSMSignal, iCurrentProfile ,
            fAcelerometerData, fGPSSpeed,  fPowerSuplyVoltage, fBatteryVoltage, fBatteryCurrent,
            fGPSPower, fPCBTemperature, fTempSensor1, fTempSensor2,
            fTempSensor3, fFuelCounter, sButtonInput, fCan0, fCan1,
            fCan2, fCan3, fCan4, fCan5, fCan6, fCan7, fCan8,  fCan9,
            bGeoZone1, bGeoZone2, bGeoZone3,
            bGeoZone4, bGeoZone5, bGeoZone6, bGeoZone7,
            bGeoZone8, bGeoZone9, bGeoZone10, bGeoZone11,
            bGeoZone12, bGeoZone13, bGeoZone14, bGeoZone15,
            bGeoZone16, bGeoZone17, bGeoZone18, bGeoZone19, bGeoZone20,
            fVirtualOdometer, sCurrOperatorCode, bMovement);


        sqlQuery.SQL.Text := 'UPDATE [IMEIDataServices] WITH (ROWLOCK) ' +
        'SET [LastTx] = :LastTx ' +
        ',[MessageId] = :MessageId ' +
        ',[Moving] = :Moving ' +
        ',[Connected] = :Connected ' +
        ',[DIN1] = :DIN1 ' +
        ',[DIN2] = :DIN2 ' +
        ',[DIN3] = :DIN3 ' +
        ',[DIN4] = :DIN4 ' +
        ',[AIN1] = :AIN1 ' +
        ',[AIN2] = :AIN2 ' +
        ',[AIN3] = :AIN3 ' +
        ',[AIN4] = :AIN4 ' +
        ',[GSMSignalStrength] = :GSMSignalStrength ' +
        ',[CurrentProfile] = :CurrentProfile ' +
        ',[AcelerometerData] = :AcelerometerData ' +
        ',[GPSSpeed] = :GPSSpeed ' +
        ',[PowerSupplyVoltage] = :PowerSupplyVoltage ' +
        ',[BatteryVoltage] = :BatteryVoltage ' +
        ',[BatteryCurrent] = :BatteryCurrent ' +
        ',[GPSPower] = :GPSPower ' +
        ',[PCBTemperature] = :PCBTemperature ' +
        ',[TemperatureSensor1] = :TemperatureSensor1 ' +
        ',[TemperatureSensor2] = :TemperatureSensor2 ' +
        ',[TemperatureSensor3] = :TemperatureSensor3 ' +
        ',[FuelCounter] = isnull([FuelCounter],0) + :FuelCounter ' +
        ',[iButtonInput] = :iButtonInput ' +
        ',[CAN0] = :CAN0 ' +
        ',[CAN1] = :CAN1 ' +
        ',[CAN2] = :CAN2 ' +
        ',[CAN3] = :CAN3 ' +
        ',[CAN4] = :CAN4 ' +
        ',[CAN5] = :CAN5 ' +
        ',[CAN6] = :CAN6 ' +
        ',[CAN7] = :CAN7 ' +
        ',[CAN8] = :CAN8 ' +
        ',[CAN9] = :CAN9  ' +
        ',[GeoZone1] = :GeoZone1 ' +
        ',[GeoZone2] = :GeoZone2 ' +
        ',[GeoZone3] = :GeoZone3 ' +
        ',[GeoZone4] = :GeoZone4 ' +
        ',[GeoZone5] = :GeoZone5 ' +
        ',[GeoZone6] = :GeoZone6 ' +
        ',[GeoZone7] = :GeoZone7 ' +
        ',[GeoZone8] = :GeoZone8 ' +
        ',[GeoZone9] = :GeoZone9 ' +
        ',[GeoZone10] = :GeoZone10 ' +
        ',[GeoZone11] = :GeoZone11 ' +
        ',[GeoZone12] = :GeoZone12 ' +
        ',[GeoZone13] = :GeoZone13 ' +
        ',[GeoZone14] = :GeoZone14 ' +
        ',[GeoZone15] = :GeoZone15 ' +
        ',[GeoZone16] = :GeoZone16 ' +
        ',[GeoZone17] = :GeoZone17 ' +
        ',[GeoZone18] = :GeoZone18 ' +
        ',[GeoZone19] = :GeoZone19 ' +
        ',[GeoZone20] = :GeoZone20 ' +
        ',[VirtualOdometer] = :VirtualOdometer ' +
        ',[CurrentOperatorCode] = :CurrentOperatorCode ' +
        'WHERE [IMEI] = :Imei';

        sqlQuery.Parameters.ParamByName('Imei').Value := sIMEI;
        sqlQuery.Parameters.ParamByName('LastTx').Value := Now;
        sqlQuery.Parameters.ParamByName('MessageId').Value := iMessageId;
        sqlQuery.Parameters.ParamByName('Moving').Value := bMovement;
        sqlQuery.Parameters.ParamByName('Connected').Value := True;
        sqlQuery.Parameters.ParamByName('DIN1').Value := bDIN1;
        sqlQuery.Parameters.ParamByName('DIN2').Value := bDIN2;
        sqlQuery.Parameters.ParamByName('DIN3').Value := bDIN3;
        sqlQuery.Parameters.ParamByName('DIN4').Value := bDIN4;
        sqlQuery.Parameters.ParamByName('AIN1').Value := fAIN1;
        sqlQuery.Parameters.ParamByName('AIN2').Value := fAIN2;
        sqlQuery.Parameters.ParamByName('AIN3').Value := fAIN3;
        sqlQuery.Parameters.ParamByName('AIN4').Value := fAIN4;
        sqlQuery.Parameters.ParamByName('GSMSignalStrength').Value := iGSMSignal;
        sqlQuery.Parameters.ParamByName('CurrentProfile').Value := iCurrentProfile;
        sqlQuery.Parameters.ParamByName('AcelerometerData').Value := fAcelerometerData;
        sqlQuery.Parameters.ParamByName('GPSSpeed').Value := fGPSSpeed;
        sqlQuery.Parameters.ParamByName('PowerSupplyVoltage').Value := fPowerSuplyVoltage;
        sqlQuery.Parameters.ParamByName('BatteryVoltage').Value := fBatteryVoltage;
        sqlQuery.Parameters.ParamByName('BatteryCurrent').Value := fBatteryCurrent;
        sqlQuery.Parameters.ParamByName('GPSPower').Value := fGPSPower;
        sqlQuery.Parameters.ParamByName('PCBTemperature').Value := fPCBTemperature;
        sqlQuery.Parameters.ParamByName('TemperatureSensor1').Value := fTempSensor1;
        sqlQuery.Parameters.ParamByName('TemperatureSensor2').Value := fTempSensor2;
        sqlQuery.Parameters.ParamByName('TemperatureSensor3').Value := fTempSensor3;
        sqlQuery.Parameters.ParamByName('FuelCounter').Value := fFuelCounter;
        sqlQuery.Parameters.ParamByName('iButtonInput').Value := sButtonInput;
        sqlQuery.Parameters.ParamByName('CAN0').Value := fCan0;
        sqlQuery.Parameters.ParamByName('CAN1').Value := fCan1;
        sqlQuery.Parameters.ParamByName('CAN2').Value := fCan2;
        sqlQuery.Parameters.ParamByName('CAN3').Value := fCan3;
        sqlQuery.Parameters.ParamByName('CAN4').Value := fCan4;
        sqlQuery.Parameters.ParamByName('CAN5').Value := fCan5;
        sqlQuery.Parameters.ParamByName('CAN6').Value := fCan6;
        sqlQuery.Parameters.ParamByName('CAN7').Value := fCan7;
        sqlQuery.Parameters.ParamByName('CAN8').Value := fCan8;
        sqlQuery.Parameters.ParamByName('CAN9').Value := fCan9;
        sqlQuery.Parameters.ParamByName('GeoZone1').Value := bGeoZone1;
        sqlQuery.Parameters.ParamByName('GeoZone2').Value := bGeoZone2;
        sqlQuery.Parameters.ParamByName('GeoZone3').Value := bGeoZone3;
        sqlQuery.Parameters.ParamByName('GeoZone4').Value := bGeoZone4;
        sqlQuery.Parameters.ParamByName('GeoZone5').Value := bGeoZone5;
        sqlQuery.Parameters.ParamByName('GeoZone6').Value := bGeoZone6;
        sqlQuery.Parameters.ParamByName('GeoZone7').Value := bGeoZone7;
        sqlQuery.Parameters.ParamByName('GeoZone8').Value := bGeoZone8;
        sqlQuery.Parameters.ParamByName('GeoZone9').Value := bGeoZone9;
        sqlQuery.Parameters.ParamByName('GeoZone10').Value := bGeoZone10;
        sqlQuery.Parameters.ParamByName('GeoZone11').Value := bGeoZone11;
        sqlQuery.Parameters.ParamByName('GeoZone12').Value := bGeoZone12;
        sqlQuery.Parameters.ParamByName('GeoZone13').Value := bGeoZone13;
        sqlQuery.Parameters.ParamByName('GeoZone14').Value := bGeoZone14;
        sqlQuery.Parameters.ParamByName('GeoZone15').Value := bGeoZone15;
        sqlQuery.Parameters.ParamByName('GeoZone16').Value := bGeoZone16;
        sqlQuery.Parameters.ParamByName('GeoZone17').Value := bGeoZone17;
        sqlQuery.Parameters.ParamByName('GeoZone18').Value := bGeoZone18;
        sqlQuery.Parameters.ParamByName('GeoZone19').Value := bGeoZone19;
        sqlQuery.Parameters.ParamByName('GeoZone20').Value := bGeoZone20;
        sqlQuery.Parameters.ParamByName('VirtualOdometer').Value := dCurrOdometer;
        sqlQuery.Parameters.ParamByName('CurrentOperatorCode').Value := sCurrOperatorCode;
        sqlQuery.ExecSQL;

       if iEventCode > -1 then
        begin
          if not InsertTrip(iCompanyId, sVehicleId,
                iMessageId, dPositionDate,
                dPositionTime, iEventCode,
                sDriverId, sChargeId,
                sGPSsStatus, dLatitude,
                dLongitude, iHeading, iDriveType,
                iNeedService,
                (dCurrOdometer / 1000), //Kilometros
                iCurrSpeed, iCurrRPM,
                iAccDeccValue, iSatellites,
                iHardwareVer, iSoftVer, iBateryLevel,fAIN4,
                sEventInfo, sErrMess) then
          begin
            WriteLog(1,'ERR',0,sVehicleId,sErrMess);
          end;
        end
        else
        begin
          WriteLog(4,'INF',0,'0','Vehicle turned off, record was not inserted');
        end;
      end;
      Result := true;
    finally
      sqlQuery.Free;
      //sqlCommand.Free;
      //sqlConn.Close;
      //sqlConn.Free;
    end;
  except
    on e: Exception do
    begin
      sErrMess :=  'Error in UpdateCurrentVehicleData ' + e.Message;
    end;
  end;
end;

ecfisa 25-08-2010 02:52:59

Hola julyus.

Confieso que me había embarullado un poco con el tema, ahora que veo la función mucho más :D.

Pero me doy cuenta que quizá la respuesta sea más sencilla de lo que pensé...

Por que tu preguntas es esta no ?
Cita:

Empezado por julyus (Mensaje 374359)
la duda que me queda es si miras los campos que envio tienen tipo, el array es de tipo string esto me daria errores?

Y sobre eso ya te puedo dar una respuesta y es: Si, te vá a dar error cuando quieras hacer la asignación.

Pero podrías intentar con un arreglo de tipo Variant, es decir reemplazar:
Código Delphi [-]
type
    TEventslistArray = array[0..58] of string;

Por:
Código Delphi [-]
type
   TEventsListArray = array[0..58] of Variant;
El tipo Variant te admite cualquier tipo de variable.

Espero que te sirva.

Saludos :).

julyus 25-08-2010 17:01:29

hola eficsa gracias por tu colaboracion
 
todavia tengo una duda o un error cunado compilo me sale un error incompatible types extended and string ???:confused::confused:

ecfisa 25-08-2010 17:48:37

Hola julyus.

Con los tipo Variant podes hacer lo siguiente:
Código Delphi [-]
var
  va: Variant;
  ext: Extended;
  str: string;
begin
   ext:= 3.141592654;
   str:= 'Número PI';
   va:= ext; 
   str:= va; 
   ShowMessage(str); 
end;

¿ En que parte del código te salta el error ?

Saludos.

julyus 25-08-2010 21:12:08

este es el codigo mas o menos
 
aqui es donde llamo el array para pasarlo a otro array creo que esta mal
la sintaxis de como hacerlo


Código Delphi [-]
type
    TEventslistArray = array[0..58] of variant;
    TNewArrayData = array[0..58] of variant;

declaracion de la funcion
Código Delphi [-]
 function SearchEvents(sIMEI: string; iCompanyId : integer;  sVehicleId : string;
            iCurrSpeed,iCurrRPM,iAccDeccValue :integer;
            bDIN1, bDIN2, bDIN3, bDIN4 : Boolean;
            fAIN1, fAIN2,  fAIN3, fAIN4 : Extended;
            iGSMSignal, iCurrentProfile : integer;
            fAcelerometerData, fGPSSpeed,  fPowerSuplyVoltage, fBatteryVoltage, fBatteryCurrent,
            fGPSPower, fPCBTemperature, fTempSensor1, fTempSensor2,
            fTempSensor3, fFuelCounter, sButtonInput, fCan0, fCan1,
            fCan2, fCan3, fCan4, fCan5, fCan6, fCan7, fCan8,  fCan9 : Extended;
            bGeoZone1, bGeoZone2, bGeoZone3,
            bGeoZone4, bGeoZone5, bGeoZone6, bGeoZone7,
            bGeoZone8, bGeoZone9, bGeoZone10, bGeoZone11,
            bGeoZone12, bGeoZone13, bGeoZone14, bGeoZone15,
            bGeoZone16, bGeoZone17, bGeoZone18, bGeoZone19, bGeoZone20 : Boolean;
            fVirtualOdometer : Extended; sCurrOperatorCode : string; bMovement : Bool ) :TEventslistArray;

funcion

uso de la funcion aqui es donde me marca el error
Código Delphi [-]

  NewArrayData := SearchEvents(sIMEI, iCompanyId, sVehicleId,
            iCurrSpeed,iCurrRPM,iAccDeccValue,
            bDIN1, bDIN2, bDIN3, bDIN4,
            fAIN1, fAIN2,  fAIN3, fAIN4,
            iGSMSignal, iCurrentProfile ,
            fAcelerometerData, fGPSSpeed,  fPowerSuplyVoltage, fBatteryVoltage, fBatteryCurrent,
            fGPSPower, fPCBTemperature, fTempSensor1, fTempSensor2,
            fTempSensor3, fFuelCounter, sButtonInput, fCan0, fCan1,
            fCan2, fCan3, fCan4, fCan5, fCan6, fCan7, fCan8,  fCan9,
            bGeoZone1, bGeoZone2, bGeoZone3,
            bGeoZone4, bGeoZone5, bGeoZone6, bGeoZone7,
            bGeoZone8, bGeoZone9, bGeoZone10, bGeoZone11,
            bGeoZone12, bGeoZone13, bGeoZone14, bGeoZone15,
            bGeoZone16, bGeoZone17, bGeoZone18, bGeoZone19, bGeoZone20,
            fVirtualOdometer, sCurrOperatorCode, bMovement);

la funcion no esta terminada lo que quiero de esta funcion es que me ingrese unos datos y si hay unos casos cumplidos me genere un array con
el registro primero ingresado y luego los casos cunplidos me generelos unos
nuevos rows repetidos solo con los casos cumplidos afectaran unas variables y generaran un nuevo row

ejemplo

a,b,c insert row en el array

entran a b y c
si c = 0 se evaluan
si c= o tonces escribe a,b y c= '123' en el array
fin

si c= 1
si c= o tonces escribe a,b y c= '321' en el array a regresar

alfinal

deben quedarme 3 rows
1 original
2 cambiado
3 cambiado

fin de la funcion


Código Delphi [-]
function TFMListenerService.SearchEvents(sIMEI: string; iCompanyId : integer;  sVehicleId : string;
            iCurrSpeed,iCurrRPM,iAccDeccValue :integer;
            bDIN1, bDIN2, bDIN3, bDIN4 : Boolean;
            fAIN1, fAIN2,  fAIN3, fAIN4 : string;
            iGSMSignal, iCurrentProfile : integer;
            fAcelerometerData, fGPSSpeed,  fPowerSuplyVoltage, fBatteryVoltage, fBatteryCurrent,
            fGPSPower, fPCBTemperature, fTempSensor1, fTempSensor2,
            fTempSensor3, fFuelCounter, sButtonInput, fCan0, fCan1,
            fCan2, fCan3, fCan4, fCan5, fCan6, fCan7, fCan8,  fCan9 : string;
            bGeoZone1, bGeoZone2, bGeoZone3,
            bGeoZone4, bGeoZone5, bGeoZone6, bGeoZone7,
            bGeoZone8, bGeoZone9, bGeoZone10, bGeoZone11,
            bGeoZone12, bGeoZone13, bGeoZone14, bGeoZone15,
            bGeoZone16, bGeoZone17, bGeoZone18, bGeoZone19, bGeoZone20 : Boolean;
            fVirtualOdometer : string; sCurrOperatorCode : string; bMovement : Bool ) :TEventslistArray;
var
count : integer;
Conn: IConnection;
sqlQuery : TADOQuery;
ADOSP: TADOStoredProc;
EvenType : string;
EvenCode  : integer;
begin




  // consulto datos
  if iCurrSpeed then
  begin

  //ejecuto el storeprocedure
  ADOSP.Connection := Conn; // paso el string de conexion
  ADOSP.ProcedureName := 'GetOverSpeed'; // pongo el nombre del SP que voy a utilizar
  ADOSP.Parameters.Refresh; // creo los parametros que espera el SP
  ADOSP.Parameters.ParamByName('@CompanyId').Value  := iCompanyId;
  ADOSP.Parameters.ParamByName('@CarNumber').Value  := sVehicleId;
  ADOSP.Parameters.ParamByName('@Speed').Value  := iCurrSpeed;
  ADOSP.Parameters.ParamByName('@EventType').Direction := EvenType;
  ADOSP.Parameters.ParamByName('@EventCode').Direction :=  EvenCode;


  end;
  ADOSP.Close;
  ADOSP.Free;
  //asigno a el arreglo


  ADOSP.Connection := Conn; // paso el string de conexion
  ADOSP.ProcedureName := 'GetOverRpm'; // pongo el nombre del SP que voy a utilizar
  ADOSP.Parameters.Refresh; // creo los parametros que espera el SP
  ADOSP.Parameters.ParamByName('@CompanyId').Value  := iCompanyId;
  ADOSP.Parameters.ParamByName('@CarNumber').Value  := sVehicleId;
  ADOSP.Parameters.ParamByName('@Factor').Value  := iCurrSpeed;
  ADOSP.Parameters.ParamByName('@EventType').Direction := EvenType;
  ADOSP.Parameters.ParamByName('@EventCode').Direction := EvenCode;
  //consuto datos


  if iCurrRPM   then
  begin

  end;
  //asigno a el arreglo


  ADOSP.Connection := Conn; // paso el string de conexion
  ADOSP.ProcedureName := 'GetOverSpeed'; // pongo el nombre del SP que voy a utilizar
  ADOSP.Parameters.Refresh; // creo los parametros que espera el SP
  ADOSP.Parameters.ParamByName('@CompanyId').Value  := iCompanyId;
  ADOSP.Parameters.ParamByName('@CarNumber').Value  := sVehicleId;
  ADOSP.Parameters.ParamByName('@AccelDecel').Value  := iCurrSpeed;
  ADOSP.Parameters.ParamByName('@EventType').Direction := EvenType;
  ADOSP.Parameters.ParamByName('@EventCode').Direction :=  EvenCode;
  //consulto
  if iAccDeccValue then
  begin

  end;
  //asigno a el arreglo


end;

ecfisa 25-08-2010 21:48:19

Hola julyus.

Claro, por que estás intentando asignar una funcion a un array of variant:
Cita:

NewArrayData := SearchEvents(...
Tendrías que declarar un puntero a método de este modo:
Código Delphi [-]
type
 TListArray = array[0..58] of Variant;
 TFuncionPtr = function (sIMEI: string; iCompanyId : integer;  sVehicleId : string;
            iCurrSpeed,iCurrRPM,iAccDeccValue :integer;
            bDIN1, bDIN2, bDIN3, bDIN4 : Boolean;
            fAIN1, fAIN2,  fAIN3, fAIN4 : string;
            iGSMSignal, iCurrentProfile : integer;
            fAcelerometerData, fGPSSpeed,  fPowerSuplyVoltage, fBatteryVoltage, fBatteryCurrent,
            fGPSPower, fPCBTemperature, fTempSensor1, fTempSensor2,
            fTempSensor3, fFuelCounter, sButtonInput, fCan0, fCan1,
            fCan2, fCan3, fCan4, fCan5, fCan6, fCan7, fCan8,  fCan9 : string;
            bGeoZone1, bGeoZone2, bGeoZone3,
            bGeoZone4, bGeoZone5, bGeoZone6, bGeoZone7,
            bGeoZone8, bGeoZone9, bGeoZone10, bGeoZone11,
            bGeoZone12, bGeoZone13, bGeoZone14, bGeoZone15,
            bGeoZone16, bGeoZone17, bGeoZone18, bGeoZone19, bGeoZone20 : Boolean;
            fVirtualOdometer : string; sCurrOperatorCode :
            string; bMovement : Bool ) :TListArray  of object;
 TForm1: class(TForm)   
 public
    FuncionPtr : TFuncionPtr;
    ...
 private
   ...
 end; 

...

Entonces la asignación sería:
Código Delphi [-]
   FuncionPtr := SearchEvents(...


Saludos.

julyus 27-08-2010 22:57:00

segunda pregunta
 
eficsa gracias por tu explicacion me ayudo mucho el tema y un poco de ver codigo basico :confused::confused::confused:

ahora tengo otra pregunta cree dentro de esta funcion que retorna un array tipo variant otro array para irle asignando unos valores en los campos
mi pregunta es el array ListArray es igual de tipo variant no se si debo crearlo asi
i:interger
i = 0;
....
ListArray[i] := valor;
i := i +1

para ir incrementado la posicion que solo tiene un valor

ver parte del código

Código Delphi [-]
function TFMListenerService.GetEventCodeArray(cIOElement : TIOElement): TArrayList;
var
i:integer;
ADOSP : TADOStoredProc;
Conn: Iconnection;
sVehicleId, iCompanyId : string;
Factor, AccelDecel, iCurrSpeed : double;
ListArray : TArrayList; //para ir acumulando  listado array que de sebe regresar de la funcion
begin

  //rrecorrido de eventos
  //try
     if (cIOElement.ElementEvent.iEventIOId = 0) then  //No hay evento significativo
      begin

        // Se verifica Conexion Desconexion
         if cIOElement.ElementValue(66) >= 6000 then
         begin
             ListArray[i] := 24;//System Connect.

         end
         else
         Begin
             ListArray[i] := 25; //System Disconnect.

         end;
        //----------------------------------------------------------------------

        //Se verifica si hay evento de Boton de Panico

        if cIOElement.ElementValue(1) =1 then
        begin
            ListArray[i] := 31 // Alert Button

        end;
        //----------------------------------------------------------------------


        //Se debe verificar si el vehiculo está encendido.
        if cIOElement.ElementValue(10) >= 2000 then

        begin
          if cIOElement.ElementValue(240) = 0 then //Si no está en movimiento
            ListArray[i] := 3 //Time Passed
          else
            ListArray[i] := 4; //Distance Passed
         end;
         //----------------------------------------------------------------------

         //iCurrSpeed := cIOElement.ElementEvent.aElements[0];
         //----------------------------------------------------------------------
         //
         try
         Conn := ConnPool.GetConnection;
         //ejecuto el storeprocedure
         ADOSP.Connection := Conn.Connection; // paso el string de conexion
         ADOSP.ProcedureName := 'GetOverRpm'; // pongo el nombre del SP que voy a utilizar
         ADOSP.Parameters.Refresh; // creo los parametros que espera el SP
         ADOSP.Parameters.ParamByName('@CompanyId').Value  := iCompanyId;
         ADOSP.Parameters.ParamByName('@CarNumber').Value  := sVehicleId;
         ADOSP.Parameters.ParamByName('@Factor').Value  := Factor;
         ADOSP.Parameters.ParamByName('@EventType').Direction := pdInputOutput;
         ADOSP.Parameters.ParamByName('@EventCode').Direction :=  pdInputOutput;
         ADOSP.Open;
         factor:= pdInputOutput[0];

         finally
         ADOSP.Close;
         ADOSP.Free;
         end;
        //asigno a el arreglo

        if cIOElement.ElementValue(11) = 0 then //Si no está en movimiento
         begin
           ListArray[i] := 21 //OverRpm

          //----------------------------------------------------------------------
         end;
       Result:= ListArray;

ecfisa 27-08-2010 23:49:01

Hola Julyus.

Si, es correcto. Funciona como cualquier array; te vas desplazando por él incrementando o decrementando el subíndce.

Ya sea utilizando una variable tipo contador, como pusiste en el post:
Código Delphi [-]
   i:= 0;
   ListArray[i] := valor; 
   i := i +1

O con el uso de for:
Código Delphi [-]
   for i:= 0 to ...
    ListArray[i]:= valor;

Eso depende de como estructures el código.

Saludos. :)


La franja horaria es GMT +2. Ahora son las 11:07:17.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi