?
Solved

useing readfileEx in Delphi 5

Posted on 2009-02-18
10
Medium Priority
?
1,152 Views
Last Modified: 2013-11-23
Hi there
I want to use simple overlapped I/O in Delphi 5
I've done it numerous times in Vs C++ so I know what to do,
I'm relatively in Delphi
And I have a syntax problem
compiler complains about  "not enough actual parameters"
See code below
I can't see the problem, can you ?
Regards Lars




type
  Tbuffer = packed array[0..1024] of byte;
 
type
    TMyoverlapped = class(Tobject)
    Data:tbuffer;
    overlapped:TOverlapped;
end;
 
// when posting a read  
// the Buffer will be deleted on completion
    Buffer:= TMyoverlapped.create;
    ReadFileEx(handle,@Buffer.data,1024,@buffer.overlapped,_onSerialData);
 
//completion routine
procedure Tmainwindow._onSerialdata(Errorcode:integer; NumberOfbytesReceived:integer; overlapped:TOverlapped);

Open in new window

0
Comment
Question by:lhl60
  • 4
  • 3
  • 3
10 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 23669312
is _onSerialdata a method of Tmainwindow? If so, it can't be, it has to be a 'normal' function.
0
 
LVL 4

Author Comment

by:lhl60
ID: 23669462
Thanks,

Now I moved the onSerialdata to "global" scope, but I still get the "not enough parameters error"  on the ReadfileEx call

I count and I count but I see enough parameter of correct types

0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 23669678
did you add stdcall ?

procedure _onSerialdata(Errorcode:integer; NumberOfbytesReceived:integer; overlapped:TOverlapped); stdcall;
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 23669709
does it work without the completion routine ?
like this:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20053566.html?qid=20053566

and what line does the compiler give an error on ...
it may the error is in the line above sometimes
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 23669730
may this declaration will help in this reference:
http://ftp.escom.bg/Windows/winsite/JCL/jvcl/source/JvHidControllerClass.pas

look for ReadFileEx, you should find:

var
  // counter to prevent a second TJvHidDeviceController instance
  GlobalInstanceCount: Integer = 0;
 
//== these are declared inconsistent in Windows.pas ============================
 
function ReadFileEx(hFile: THandle; var Buffer; nNumberOfBytesToRead: DWORD;
  var Overlapped: TOverlapped; lpCompletionRoutine: TPROverlappedCompletionRoutine): BOOL; stdcall;
  external 'kernel32.dll' name 'ReadFileEx';
function WriteFileEx(hFile: THandle; var Buffer; nNumberOfBytesToWrite: DWORD;
  var Overlapped: TOverlapped; lpCompletionRoutine: TPROverlappedCompletionRoutine): BOOL; stdcall;
 external 'kernel32.dll' name 'WriteFileEx';

Open in new window

0
 
LVL 4

Author Comment

by:lhl60
ID: 23669769
Stdcall now added ( what was i thinking ?)
but still no change
And the error seems to be here

   ReadFileEx(handle,@Buffer.data,1024,@buffer.overlapped,onSerialData)
error:
"not enough actual parameters"

and without completion:

    ReadFile(handle,@Buffer.data,1024,@buffer.overlapped)
error:
"types of actual and formal parameters must be identical"
I suspect it has to do with the  @'s, My Delphi skills aren't that good
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 23669775
If you change the 'layout' of your code to like below, you might get more details on where in the arguments the compiler gives the error:
    ReadFileEx(handle,
               @Buffer.data,
               1024,
               @buffer.overlapped,
               _onSerialData);

Open in new window

0
 
LVL 19

Accepted Solution

by:
MerijnB earned 2000 total points
ID: 23669789
It could be either

@Buffer.data[0] in stead of @Buffer.data
or
@_onSerialData in stead of _onSerialData
0
 
LVL 4

Author Comment

by:lhl60
ID: 23669898
Changing the line to :

    ReadFileEx(ComHandle,@Buffer.data,1024,@buffer.overlapped,@onSerialData);

fixed the compilations errors:

Now I just have to make it work

Closing the thread now
Thanks for you interest
rgds. Lars


0
 
LVL 4

Author Closing Comment

by:lhl60
ID: 31548206
yes thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

864 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