Solved

Array Pointer

Posted on 2006-11-13
1
4,556 Views
Last Modified: 2008-01-09
I have the following code in a compiled delphi dll.  

library wavelet;

uses
  SysUtils,math,Windows;

type
     aa1=array[0..1000000] of single;
     ar=^ aa1;
var
  MyArr:ar;

function RUNWVL(a:ar; nscales:word; ttc:single):single;stdcall;
begin
     // Do Some work and return a single
end;


I need to access this dll and call RUNWVL from another app.  I'm trying to do like below, but I'm having trouble getting the syntax correct to pass the pointer in. Can someone show me how to pass the pointer to my array into the function?

program testapp;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Unit1 in 'Unit1.pas';

procedure  RUNWVL( ptrArray:pointer; scales:Integer; stddev:double) ;  stdcall;far;external 'wavelet.dll';
procedure  GETALLVALUES( something:Integer; somethingelse:Integer) ;  stdcall;far;external 'wavelet.dll';

type
    aa1= array of double;
    pcloseList=^ aa1;

var
    f: TextFile;
    line:string;
    date:string;
    time:string;
    close:string;
    scale:string;
    scales:Integer;
    count:Integer;
    start:Integer;
    stop:Integer;
    closeList: aa1;
    scaleList: array of double;
    t: double;
    y: double;procedure ExecuteProgram;



  begin
      scales := 9;


          // Open file for reading
          AssignFile(f, 'c:\wavelet\testdata');
          Reset(f);

          count := 0;
          ReadLn(f, line);
          SetLength(closeList, scales * scales);
          SetLength(scaleList, scales * scales);

          // Read each line
          while not Eof(f) do
          begin
            if count = ( scales * scales ) then
            begin
              // Run Wavelet
              t := RUNWVL(closeList, scales, 3);
              for count := 1 to scales do
                begin
                  // Get the wavelet values
                  y := GETALLVALUES(1, count);
                end;


              count:=0;


            end
            else
            begin
            // Fill array with data from file
             ReadLn(f, line);

             stop:= pos(',', line);
             date:= copy(line, 0, stop - 1);
             line := copy(line, stop + 1);

             stop:= pos(',', line);
             time:= copy(line, 0, stop - 1);
             line := copy(line, stop + 1);

             stop:= pos(',', line);
             close:= copy(line, 0, stop - 1);
             line := copy(line, stop + 1);

             scale := line;

             scaleList[count] := StrToFloat(scale);
             closeList[count] := StrToFloat(close);

             count:= count + 1;

            end;





          end;

          CloseFile(f);
//           Close(f);

         WriteLn('running proggy');
  end;

begin
      try
        ExecuteProgram;
      except
        WriteLn('WTF');


      end;
      ExitCode := 1;
end.





0
Comment
Question by:darthg8r
1 Comment
 
LVL 28

Accepted Solution

by:
2266180 earned 50 total points
ID: 17932838
first add to the library wavelet the following:

exports RUNWVL, GETALLVALUES;

at the end.

then call the function like:

t := RUNWVL(@closeList, scales, 3);

then declare your aa1 as array of single and not double. single is 4 bytes. double is 8 bytes. same goes for all other doble/single variables in your code.

that's what I see for now.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Wininet read php file from internet issue 6 81
proper way to parse text with delphi 7 101
QRReport  TQrmemo vertical stretching 1 42
creating threads in delphi 1 82
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now