Ir para conteúdo

Manoel010953

Members
  • Total de itens

    1
  • Registro em

  • Última visita

Posts postados por Manoel010953


  1. Bom Dia pessoal, tudo bom? Sou novo em programação e estou tentando criar uma dll no delphi. 

    Essa dll vai ser usada em uma aplicação do delphi também.

    Queria saber se é possível utilizar vetores e matrizes e como fazer isso pois eu tentei declarar como um array of array of (um tipo), mas dá erro (essas matrizes seriam parâmetros da função). Colocando só como array of (um tipo) funciona, mas ao tentar acessar a função na dll dá um access violation. Eu já havia criado essa função dentro da minha aplicação e estava funcionando, mas na dll da esse erro. Eu tentei usar um ponteiro também, mas continua dando o erro. Por favor me ajudem.

    Segue o código:

     

    library NDC_Generator;
    
    uses
      SysUtils,
      Dialogs,
      Classes;
    
      Type
      Matriz = Array of array of string;
      P1 = ^Matriz;
    
    {$R *.res}
    
    procedure MensagemConfirmacao(AMensagem: WideString); stdcall;
    begin
      MessageDlg(AMensagem, mtInformation, [mbOk], 0);
    end;
    
    function gerarcombinacoes(Mat: P1; Xb, Total, np,
      NumCri: integer; mp, bud: Double; Pointer: P1): string; stdcall;
    var
      i, j, k, T, a, p: integer;
      aux1: string;
      R0: Double;
      vetop, vmax: array of integer;
      matrizaj: array of array of integer;
      vetmax, vetmin: array of Double;
      vet_aux, Vetname: array of string;
      matrizaux1 : array of array of Double;
      matriz_result: array of array of String;
    
    begin
      setlength(vetop, np);
      setlength(vmax, np);
      setlength(matrizaj, T, np);
      setlength(vetmax, NumCri);
      setlength(vetmin, NumCri);
      setlength(vet_aux, T);
    
      p := 0;
    
      for i := 0 to np - 1 do
      begin
        vmax[np - i - 1] := Xb - i;
      end;
    
      for i := 0 to np - 1 do
        vetop := i + 1;
      vetop[np - 1] := np - 1;
    
      for i := 0 to NumCri - 1 do
      begin
        vetmin := 100000;
        vetmax := -1;
      end;
      i := 0;
      T := 0;
    
      while (T < Total) do // Gerar as combinações com np elementos
      begin
        if T <> 1 then
          i := np;
    
        while (i > 0) do // Verifica se alguma das posições já atingiu seu máximo
        begin
          if (i - 1) <> 0 then // Verifica se não se trata da primeira posição que atingiu seu máximo
          begin
            if (vetop[i - 1] = vmax[i - 1]) and (vetop[i - 2] < vmax[i - 2]) then
            begin
              vetop[i - 2] := vetop[i - 2] + 1;
              vetop[i - 1] := vetop[i - 2]; ;
              if (i < np) then
                for j := i to np - 1 do
                  vetop[j - 1] := vetop[j - 2] + 1;
              vetop[np - 1] := vetop[np - 2];
              break;
            end; // vetop
          end; // 0
          i := i - 1;
        end; // while i>0
        vetop[np - 1] := vetop[np - 1] + 1;
    
        R0 := 0;
        for k := 0 to np - 1 do
          R0 := R0 + StrToFloat(
            Mat^[vetop[k] - 1, NumCri + 1]);
    
        if R0 <= bud then 
        begin
          p := p + 1;
          setlength(matrizaux1, p, NumCri + 1);
          setlength(Vetname, p);
          for a := 0 to NumCri - 1 do
          begin
            for k := 0 to np - 1 do
              matrizaux1[p - 1, a] := matrizaux1[p - 1, a] + StrToFloat(
                 Mat^[vetop[k] - 1, a + 1] );
    
    
            if (matrizaux1[p - 1, a] > vetmax[a]) then
              vetmax[a] := matrizaux1[p - 1, a];
            if (matrizaux1[p - 1, a] < vetmin[a]) then
              vetmin[a] := matrizaux1[p - 1, a];
          end;
          matrizaux1[p - 1, NumCri] := R0;
    
         a:= 0;
    
          for k := 0 to np - 1 do
            Vetname[p - 1] := Vetname[p - 1] +
            Mat^[ vetop[k] - 1,a]  + ' ';
        end; // R0 <= Bud
    
        T := T + 1;
      end; // While
    
    
      a := 0;
      k := 0;
      for i := 0 to p - 1 do
      begin
        if mp <> 0 then
          for j := 0 to NumCri - 1 do
          begin
            if vetmax[j] <> vetmin[j] then
            begin
              R0 := (matrizaux1[i, j] - vetmin[j]) / (vetmax[j] - vetmin[j]);
            end
            else
              R0 := 1;
            if R0 >= mp then
            begin
              a := a + 1;
            end
            else
              break;
          end
          else
            a := NumCri;
        if a = NumCri then
        begin
          k := k + 1;
          for j := 0 to NumCri do
          begin
            setlength(matriz_result, k, NumCri + 2);
            matriz_result[k - 1, j+1] := floattostr( matrizaux1[i, j]);
          end;
          matriz_result[k - 1, 0]:= Vetname;
        end;
        a := 0;
      end;
      for I := 0 to k - 1 do
        for j := 0 to numcri + 1 do
          Pointer^[i,j]:= matriz_result[i,j];
    
      MensagemConfirmacao('Foram geradas' + inttostr(k) + 'combinações!');
      Result := '0';
    end;
    
    exports
    gerarcombinacoes;
    
    end. 

     

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.