library Project2;
uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {DataModule1: TDataModule};{$R *.res}
function GetValues(name:string):boolean;stdcall;
begin
DataModule1.Query1.Close;
DataModule1.Query1.RequestLive:=true;
DataModule1.Query1.SQL.Text:='select *from TPower ';
DataModule1.Query1.Open;
if DataModule1.Query1.RecordCount>0 then
begin
Result:=true;
end
else begin
Result:=false;
endend;
exports
GetValues;
begin
end.
----------------------------------
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function GetValues(name:string): boolean; stdcall;
var
Form1: TForm1;implementation
{$R *.dfm}
function GetValues; external 'D:\testforPower\1_2\Project2.dll' name 'GetValues';
procedure TForm1.Button1Click(Sender: TObject);
begin
if GetValues('aaa')=true then
begin
Edit1.Text:='right';
end
else begin
Edit1.Text:='false';
end
end;end.
------------------
可是一点按钮就提示:Access violation at address 0027BD85 in module 'project2.dll',Read of address 00000058,这要怎莫改呀?
uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {DataModule1: TDataModule};{$R *.res}
function GetValues(name:string):boolean;stdcall;
begin
DataModule1.Query1.Close;
DataModule1.Query1.RequestLive:=true;
DataModule1.Query1.SQL.Text:='select *from TPower ';
DataModule1.Query1.Open;
if DataModule1.Query1.RecordCount>0 then
begin
Result:=true;
end
else begin
Result:=false;
endend;
exports
GetValues;
begin
end.
----------------------------------
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function GetValues(name:string): boolean; stdcall;
var
Form1: TForm1;implementation
{$R *.dfm}
function GetValues; external 'D:\testforPower\1_2\Project2.dll' name 'GetValues';
procedure TForm1.Button1Click(Sender: TObject);
begin
if GetValues('aaa')=true then
begin
Edit1.Text:='right';
end
else begin
Edit1.Text:='false';
end
end;end.
------------------
可是一点按钮就提示:Access violation at address 0027BD85 in module 'project2.dll',Read of address 00000058,这要怎莫改呀?
uses
ActiveX,
//...
//...
uDMPSet in 'uDMPSet.pas' {DMPrintSet: TDataModule};{$R *.res}var
NewHandle,OldHandle:TApplication;procedure tSet(Proc: DWord);
begin
case Proc of
DLL_PROCESS_ATTACH:
begin
CoInitialize(nil);
DMPrintSet := TDMPrintSet.Create(nil);
NewHandle := nil;
OldHandle := Application;
end;
DLL_PROCESS_DETACH:
begin
CoUnInitialize;
DMPrintSet.Free ;
Application := OldHandle;
end;
DLL_THREAD_ATTACH:
begin end;
DLL_THREAD_DETACH:
begin end;
end;
end;
//...//...begin
DllProc := @tSet;
tSet(DLL_PROCESS_ATTACH);
end.
[Error] Project2.dpr(34): Missing operator or semicolon
uses
ActiveX,SysUtils,
Classes,
Unit1 in 'Unit1.pas' {DataModule1: TDataModule};{$R *.res}
function GetValues(name:string):boolean;stdcall;
begin
CoInitialize(nil);DataModule1.Query1.Close;
DataModule1.Query1.RequestLive:=true;
DataModule1.Query1.SQL.Text:='select *from TPower ';
DataModule1.Query1.Open;
if DataModule1.Query1.RecordCount>0 then
begin
Result:=true;
end
else begin
Result:=false;
end
activex.CoUninitialize;end;
exports
GetValues;
beginend.
不过还是上边的错误!
我讨厌你的名字!