{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
ShareMem,
SysUtils,
Classes,
UtFind in 'UtFind.pas' {FindFrm};
//定義出口函數
function FindShow(H:THandle;TName:string):string;stdcall;
implementation
{$R *.dfm}
function FindShow(H:THandle;TName:string):string;
var
FindFrm: TFindFrm;
begin
application.Handle:=H;
FindFrm:=TFindFrm.Create(application);
try
FindFrm.Query1.SQL.Clear;
FindFrm.Query1.SQL.Add(TName);
FindFrm.ShowModal;
Result:=FindFrm.FindSqlString;
finally
FindFrm.Free;
end;
end;
procedure TFindFrm.Button1Click(Sender: TObject);
var aa,bb :string;
var c:integer;
begin
if RichEdit1.Lines.Text='' then
aa:=''
else
begin
if RadioButton1.Checked=True then
aa:='AND'
else
aa:='OR';
end;
c:=Pos(' ',ComboBox1.Text);
RichEdit2.Text:=RichEdit2.Text+' '+aa+' '+'('+copy(ComboBox1.Text,1,c-1)+' '+ComboBox2.Text+' '+''''+Edit1.Text+''')';
RichEdit1.Text:=RichEdit1.Text+' '+aa+' '+'('+copy(ComboBox1.Text,c+1,Length(ComboBox1.Text)-c-1)+' '+ComboBox2.Text+' '+''''+Edit1.Text+''')';
end;
procedure TFindFrm.Button3Click(Sender: TObject);
var i,n:integer;
var OrderStr,ListStr:string;
begin
//把生成的sql語句添加到FindSqlString中
if RichEdit1.Lines.Text<>'' then
FindSqlString:='SELECT * FROM '+trim(TBname)+' WHERE '+trim(RichEdit2.Text)
else
FindSqlString:='SELECT * FROM '+trim(TBname);
//加orderby
if ListBox2.Items.Text<>'' then
for i:=0 to ListBox2.Items.Count-1 do
begin
n:=Pos(' ',ListBox2.Items.Strings[i]);
ListStr:=copy(ListBox2.Items.Strings[i],1,n-1);
if i=0 then
OrderStr:=ListStr
else
OrderStr:=OrderStr+','+ListStr;
end;
//加dsc
if OrderStr<>'' then
begin
if RadioButton3.Checked=True then
OrderStr:=' ORDER BY '+OrderStr+' ASC'
else
OrderStr:=' ORDER BY '+OrderStr+' DESC';
end;
FindSqlString:=FindSqlString+OrderStr;
self.Close;
end;
procedure TFindFrm.Button4Click(Sender: TObject);
begin
FindSqlString:='';
self.Close;
end;
procedure TFindFrm.FormShow(Sender: TObject);
var i:integer;
var a:Tobject;
begin
TBname:=Query1.SQL.Text;
Query1.SQL.Clear;
Query1.SQL.Add('SELECT MA003,MA004 FROM XADMA WHERE MA001='''+Trim(TBname)+'''');
RichEdit1.Lines.Text:='';
if Query1.Active=False then Query1.Open;
while not Query1.Eof do
begin
ComboBox1.AddItem(trim(Query1.FieldValues['MA003'])+' '+Query1.FieldValues['MA004'],a);
ListBox1.AddItem(trim(Query1.FieldValues['MA003'])+' '+Query1.FieldValues['MA004'],a);
Query1.Next;
end;
Query1.Close;
ComboBox1.ItemIndex:=0;
end;
procedure TFindFrm.Button2Click(Sender: TObject);
begin
RichEdit2.Text:='';
RichEdit1.Text:='';
end;
procedure TFindFrm.ListBox1DblClick(Sender: TObject);
var a:Tobject;
begin
if ListBox1.ItemIndex<>-1 then
begin
ListBox2.AddItem(ListBox1.Items.Strings[ListBox1.ItemIndex],a);
ListBox1.DeleteSelected;
end;
end;
procedure TFindFrm.ListBox2DblClick(Sender: TObject);
var a:Tobject;
begin
if ListBox2.ItemIndex<>-1 then
begin
ListBox1.AddItem(ListBox1.Items.Strings[ListBox2.ItemIndex],a);
ListBox2.DeleteSelected;
end;
end;
procedure TFindFrm.SpeedButton1Click(Sender: TObject);
begin
ListBox1DblClick(Sender);
end;
procedure TFindFrm.SpeedButton2Click(Sender: TObject);
begin
ListBox2DblClick(Sender);
end;