怎样把一个结构数据读入到动态数组中(100分)

  • 主题发起人 主题发起人 ylp1998
  • 开始时间 开始时间
Y

ylp1998

Unregistered / Unconfirmed
GUEST, unregistred user!
我在一个程序中把一个结构数据存入文件中,然后把文件中的结构数据读入到
一个数组中程序如下:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
EventArr:array[0..1000] of EVENTMSG;
RecallDate:EVENTMSG;
DateFile:file of EVENTMSG;
EventLog:Integer;
PlayLog:Integer;
hHook,hPlay:Integer;
recOK:Integer;
canPlay:Integer;
bDelay:Bool;

implementation

{$R *.dfm}
function PlayProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
begin
canPlay:=1;
Result:=0;
if iCode < 0 then //必须将消息传递到钩子链的下一个处理程序
Result := CallNextHookEx(hPlay,iCode,wParam,lParam)
else if iCode = HC_SYSMODALON then canPlay:=0
else if iCode = HC_SYSMODALOFF then canPlay:=1
else if ((canPlay =1 )and(iCode=HC_GETNEXT)) then begin
if bDelay then begin
bDelay:=False;
Result:=50;
end;
pEventMSG(lParam)^:=EventArr[PlayLog];
end
else if ((canPlay = 1)and(iCode = HC_SKIP))then begin
bDelay := True;
PlayLog:=PlayLog+1;
end;
if PlayLog>=EventLog then begin
UNHookWindowsHookEx(hPlay);
end;
end;
function HookProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
begin
recOK:=1;
Result:=0;
if iCode < 0 then
Result := CallNextHookEx(hHook,iCode,wParam,lParam)
else if iCode = HC_SYSMODALON then recOK:=0
else if iCode = HC_SYSMODALOFF then recOK:=1
else if ((recOK>0) and (iCode = HC_ACTION)) then begin
RecallDate:=pEventMSG(lParam)^;
Seek(DateFile,FileSize(DateFile));
Write(DateFile,RecallDate);
EventLog:=EventLog+1;
if EventLog>=1000 then begin
UnHookWindowsHookEx(hHook);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption:='纪录';
Button2.Caption:='停止';
Button3.Caption:='回放';
Button2.Enabled:=False;
Button3.Enabled:=False;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
EventLog:=0;
//建立键盘、鼠标操作消息纪录链
AssignFile(DateFile,'c:/windows/RecallDate.dat');
Reset(DateFile);
hHook:=SetwindowsHookEx(WH_JOURNALRECORD,HookProc,HInstance,0);
Button2.Enabled:=True;
Button1.Enabled:=False;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
UnHookWindowsHookEx(hHook);
hHook:=0;
Button1.Enabled:=True;
Button2.Enabled:=False;
Button3.Enabled:=True;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
PlayLog:=0;
EventLog:=0;
//建立键盘鼠标操作消息纪录回放链
Reset(DateFile);
While not Eof(DateFile) do
begin
Read(DateFile,RecallDate);
EventArr(EventLog):=RecallDate;// 这一句出错Missing Operator or semicolon;Incompatible types:'Array' and 'tagEventmsg'
EventLog:=EventLog+1;
end;
hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc,HInstance,0);
Button3.Enabled:=False;
end;
我试着用指针,也不行.请各位大虾看看小弟的问题.


end.
 
后退
顶部