V
vlike
Unregistered / Unconfirmed
GUEST, unregistred user!
使用一个外部的DLL保存StringGrid的内容,
但失败,log文件里什么也没有,
在DLL里的StringGrid
---------------------------dlldemo.dll------------------------------------
procedure savelog(sg: TstringGrid);
var
i: integer;
f: textFile;
fn: string;
begin
fn := 'log.txt';
AssignFile(f, fn);
i := 0;
if not fileExists(fn) then
rewrite(f)
else
append(f);
while i < sg.RowCountdo
///////sg.RowCount 为 0
begin
writeln(f, sg.cells[0, i]);
inc(i);
end;
CloseFile(f);
end;
---------------------------主程序------------------------------------
procedure TForm1.Button3Click(Sender: TObject);
type
dllpc = procedure(var sg: TstringGrid);
var
handle: thandle;
prc: dllpc;
begin
handle := loadlibrary('dlldemo.dll');
if handle <> 0 then
begin
@prc := GetProcAddress(handle, 'savelog');
if @prc <> nil then
prc(StringGrid1);//不知是不是这里带不过去
end;
end;
但失败,log文件里什么也没有,
在DLL里的StringGrid
---------------------------dlldemo.dll------------------------------------
procedure savelog(sg: TstringGrid);
var
i: integer;
f: textFile;
fn: string;
begin
fn := 'log.txt';
AssignFile(f, fn);
i := 0;
if not fileExists(fn) then
rewrite(f)
else
append(f);
while i < sg.RowCountdo
///////sg.RowCount 为 0
begin
writeln(f, sg.cells[0, i]);
inc(i);
end;
CloseFile(f);
end;
---------------------------主程序------------------------------------
procedure TForm1.Button3Click(Sender: TObject);
type
dllpc = procedure(var sg: TstringGrid);
var
handle: thandle;
prc: dllpc;
begin
handle := loadlibrary('dlldemo.dll');
if handle <> 0 then
begin
@prc := GetProcAddress(handle, 'savelog');
if @prc <> nil then
prc(StringGrid1);//不知是不是这里带不过去
end;
end;