参数形式传进来的ibsql是否无法在dll中使用?(100分)

  • 主题发起人 主题发起人 ufo!
  • 开始时间 开始时间
U

ufo!

Unregistered / Unconfirmed
GUEST, unregistred user!
我在主程序中把ibsql2当参数传给dll,执行ibsql2.exequery时候提示访问内存错误。
而同样方式使用ibquery却正常。
我已经添加了sharemem单元。
interface

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

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Label4: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Label5: TLabel;
Label6: TLabel;
Edit1: TEdit;
ComboBox1: TComboBox;
Label7: TLabel;
Button5: TButton;
procedure FormShow(Sender: TObject);
procedure StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
ibsql1: tibsql;//声明一个变量,以接受传入的对象参数
ibquery1: tibquery;
zhiduan1,zdnr1: string; //接受传入的参数
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var i: integer;
begin
i:= 1;
ibsql1.Close;
ibsql1.SQL.Clear;
ibsql1.SQL.Add('update ddb set khtel= ''567'' where ddh= '+'''' + zdnr1 +'''');
ibsql1.ExecQuery;
while not ibsql1.Eof do
begin
stringgrid1.Cells[0,i]:= ibsql1.fieldbyname('cph').AsString;
stringgrid1.Cells[1,i]:= inttostr(ibsql1.fieldbyname('shul').AsInteger);
stringgrid1.Cells[2,i]:= formatfloat('0.00',ibsql1.fieldbyname('djia').AsFloat);
stringgrid1.Cells[3,i]:= ibsql1.fieldbyname('miaos').AsString;
ibsql1.next;
i:= i+1;
stringgrid1.RowCount:= i;
stringgrid2.RowCount:= i;
end;

(* ibquery1.Close; //注释掉的这段可以正常运行
ibquery1.SQL.Clear;
ibquery1.SQL.Add('select cph,miaos,shul,djia from ddwp where ddh= '+'''' + zdnr1 +'''');
ibquery1.Open;
ibquery1.Last;
for i:= 1 to ibquery1.RecordCount do
begin
ibquery1.RecNo:= i;
stringgrid1.Cells[0,i]:= ibquery1.fieldbyname('cph').AsString;
stringgrid1.Cells[1,i]:= inttostr(ibquery1.fieldbyname('shul').AsInteger);
stringgrid1.Cells[2,i]:= formatfloat('0.00',ibquery1.fieldbyname('djia').AsFloat);
stringgrid1.Cells[3,i]:= ibquery1.fieldbyname('miaos').AsString;
//ibsql1.next;
//i:= i+1;
stringgrid1.RowCount:= i+2;
stringgrid2.RowCount:= i+2;
end; *)
end;
 
我自己解决了此问题,若也碰到同样问题的请留个名,我把答案贴上来。
 
别卖关子了!
 
我的解决方法是: 在dll内的窗体上放一个ibsql控件,然后把通过参数传递来的ibsql的
database属性赋给dll内的ibsql控件。就解决了内存访问错误的问题。
library fapiao;

uses
Sharemem,
SysUtils,
Classes,
IBQuery,
ibsql,
forms,
Unitzxd in 'Unitzxd.pas' {zhuangxiang},
Unit1 in 'Unit1.pas' {Form1};

{$R *.res}
function showreport(gjzd,gjzhi,gjzdt,gjzhit:pchar; quy8: tibquery; sql8: tibsql): integer; stdcall;
var zhuangxiang: Tzhuangxiang;
begin
zhuangxiang:= Tzhuangxiang.Create(nil);
zhuangxiang.query1:= quy8;
zhuangxiang.query1.Close;
zhuangxiang.query1.SQL.Clear;
zhuangxiang.query1.SQL.Add('select * from ddb');
zhuangxiang.query1.Open;
zhuangxiang.QuickRep1.DataSet:= zhuangxiang.query1;
zhuangxiang.qrdbtext1.DataSet:= zhuangxiang.query1;
zhuangxiang.qrdbtext1.DataField:= 'ddh';
zhuangxiang.qrdbtext2.DataSet:= zhuangxiang.query1;
zhuangxiang.qrdbtext2.DataField:= 'khh';

zhuangxiang.QuickRep1.PreviewModal;
result:= 1;
zhuangxiang.Free;
end;

function dingdanbiangeng(gjzd,gjzhi,gjzdt,gjzhit:pchar; quy8: tibquery; sql8: tibsql): integer; stdcall;
var form1: Tform1;
begin
form1:= Tform1.Create(nil); //订单变更单
form1.ibsql1.Database:= sql8.Database;//sql8为传进来的参数
form1.ibsql1.Transaction:= sql8.Transaction;
form1.ibquery1:= quy8;
if gjzdt= 'ufo' then
begin
form1.Label7.Visible:= false;
form1.ComboBox1.Visible:= false;
form1.Button5.Visible:= false;
end;
form1.zhiduan1:= string(gjzd);
form1.zdnr1:= string(gjzhi);
result:= form1.ShowModal;
form1.Free;
end;

exports
showreport,
dingdanbiangeng;
begin
end.
 
在interbase数据库中
sql语句的where 后面的条件,是从左到右执行的,还是从右到左执行的?
比如:select * from table1 where name= 'kk' and city= 'hangzhou';
哪个条件会被先检索?
 
根据观察,发现interbase数据库的sql语句where后的条件判断是从左到右的。
不知其它数据库的sql解释是什么顺序的?
 
多人接受答案了。
 
InterBase 使这个有意思的冬冬阿/
 
后退
顶部