I am converting an old Delphi application to Lazarus. All has gone well until I had to start dealing with pointers in one unit. The unit works in Delphi mode {$MODE Delphi} but I would like it to work in {$mode objfpc}{$H+} mode. The application uses Windows MMSystem and :
TMidiHdr = record
lpData: pchar; { pointer to locked data block }
dwBufferLength: Longint; { length of data in data block }
dwBytesRecorded: Longint; { used for input only }
dwUser: Longint; { for client's use }
dwFlags: Longint; { assorted flags (see defines) }
lpNext: PMidiHdr; { reserved for driver }
reserved: Longint; { reserved for driver }
and
midioutprepareheader(HMIDIOOUT hmo, LPMIDIHDR lpMidiOutHdr, UINT cbMidiOutHdr)
The following works fine
unit sysex;
{$MODE Delphi}
interface
uses MMSystem…..;
type
PMidiHdr = ^TMidiHdr;
procedure SendSysex(sysexdata:string);
implementation
procedure SendSysex(sysexdata:string);
var
midih:PMidiHdr;
rc:integer;
Psysex:^Pchar;
begin
//sysexdata is in the form #$F0#$00#$F7.....
//lphmo is the address of a handle
Psysex:=@sysexdata;
new(midih);
GetMem(midih.lpData, length(sysexdata)+1);
StrMove(midih.lpData, Psysex^, length(sysexdata)+1);
midih^.dwBufferLength := length(sysexdata);
midih^.dwFlags := 0;
rc := midiOutPrepareHeader(lphmo, @midih.lpData, sizeof(Tmidihdr));
If rc<>0 then ShowMessage('Header Not Prepared');
rc := midiOutLongMsg(lphmo, @midih.lpData, sizeof(Tmidihdr));
IF rc<>0 then Showmessage('Sysex Data Not Sent');
rc := midiOutUnprepareHeader(lphmo, @midih.lpData, sizeof(Tmidihdr));
FreeMem(midih.lpData);
dispose(midih);
sysexdata:='';
end;
I have tried many changes to get the above to work under FPC mode but always get the error "may be pointer derefence is missing" and Fatal: Syntax error, ")" expected but "identifier LPDATA" found.
I would be grateful if someone could explain what the problem is. Thanks