home *** CD-ROM | disk | FTP | other *** search
- unit uEQueryForm;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Grids, ExtCtrls, Db, DBTables, StdCtrls, Buttons, Spin, Mask, ComCtrls;
-
- type
- TF_EQRef = class(TForm)
- Panel1: TPanel;
- StringGrid1: TStringGrid;
- Panel2: TPanel;
- SpeedButton1: TSpeedButton;
- ListBox1: TListBox;
- Panel3: TPanel;
- Button1: TButton;
- Button2: TButton;
- Label1: TLabel;
- Label2: TLabel;
- procedure FormActivate(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure SpeedButton1Click(Sender: TObject);
- procedure Label2DblClick(Sender: TObject);
- procedure ListBox1DblClick(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- private
- fCancel:boolean;
- fActive:boolean;
- fFirst:boolean;
- fQ:TQuery;
- oForm:TForm;
- fS:TStringList;
- procedure MyList;
- procedure Zapis;
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- F_EQRef: TF_EQRef;
-
- procedure Execute_EQRef(pQ:TQuery; pS:TStringList );
- procedure Execute_EQOpen(pQ:TQuery; pS:TStringList);
- procedure Execute_EQClose;
-
- implementation
-
- {$R *.DFM}
-
- procedure Execute_EQRef(pQ:TQuery; pS:TStringList);
- begin
- if F_EQRef=nil then Application.CreateForm(TF_EQRef,F_EQRef) else begin
- if F_EQRef.fActive then begin
- F_EQRef.Close;
- F_EQRef.Free;
- F_EQRef:=nil;
- Application.CreateForm(TF_EQRef,F_EQRef)
- end;
- end;
- try
- F_EQRef.fActive:=false;
- F_EQRef.ModalResult:=mrCancel;
- F_EQRef.fQ:=pQ;
- F_EQRef.fS:=pS;
- F_EQRef.oForm:=TForm(pQ.Owner);
- F_EQRef.fQ:=pQ;
- F_EQRef.ShowModal;
- finally
- F_EQRef.Free;
- F_EQRef:=nil;
- end;
- end;
-
- procedure Execute_EQOpen(pQ:TQuery; pS:TStringList);
- begin
- if F_EQRef=nil then Application.CreateForm(TF_EQRef,F_EQRef);
- F_EQRef.fQ:=pQ;
- F_EQRef.fS:=pS;
- F_EQRef.oForm:=TForm(pQ.Owner);
- F_EQRef.fFirst:=true;
- F_EQRef.fActive:=true;
- F_EQRef.Show;
- end;
-
- procedure Execute_EQClose;
- begin
- if Assigned(F_EQRef) then begin
- F_EQRef.fActive:=false;
- F_EQRef.Close;
- end;
- end;
-
- procedure TF_EQRef.FormActivate(Sender: TObject);
- begin
- if fFirst then begin
- fFirst:=false;
- MyList;
- end;
- end;
-
- procedure TF_EQRef.MyList;
- var i,j,k:integer;
- mS,mT1,mT2:string;
- mB:Boolean;
- begin
- if fQ=nil then begin
- ShowMessage('EQuery?Dialog - EQuery is nil');
- Postmessage(Handle,wm_close,0,0);
- exit;
- end;
- if oForm=nil then begin
- ShowMessage(fQ.Name+'Dialog - Form=nil');
- Postmessage(Handle,wm_close,0,0);
- exit;
- end;
- if fS=nil then begin
- ShowMessage(fQ.Name+'Dialog - StringList=nil');
- Postmessage(Handle,wm_close,0,0);
- exit;
- end;
- ListBox1.Clear;
- ListBox1.Items.Add('');
- for i:=0 to oForm.componentCount-1do begin
- if (oForm.Components[i] is Tedit) or
- (oForm.Components[i] is TComboBox) or
- (oForm.Components[i] is TSpinEdit) or
- (oForm.Components[i] is TMemo) or
- (oForm.Components[i] is TMaskedit) or
- (oForm.Components[i] is TdateTimePicker) or
- (oForm.Components[i] is TCheckBox) then begin
- ListBox1.Items.Add(oForm.Components[i].name);
- end;
- end;
- ListBox1.Items.Add('{Another}');
- ListBox1.ItemIndex:=0;
- with StringGrid1 do begin
- cells[0,0]:='Query Fields';
- cells[1,0]:='Ref. Components';
- mB:=fQ.Active;
- try
- fQ.Active:=true;
- for i:=0 to fS.Count-1 do begin
- mS:=trim(fS.Strings[i]); mT1:=''; mT2:='';
- if mS<>'' then begin
- j:=Pos('=',mS);
- if j>1 then begin
- mT1:=copy(mS,1,j-1); mT2:=copy(mS,j+1,255);
- end else begin
- mT2:=mS;
- if mT2[1]='=' then delete(mT2,1,1);
- end;
- mT1:=Trim(mT1); mT2:=Trim(mT2);
- end;
- if trim(mT1)='' then continue;
- if fQ.FindField(mT1)=nil then Cells[0,i+1]:='? '+mT1 else Cells[0,i+1]:=mT1;
- if Pos('{',mT2)>0 then Cells[1,i+1]:=mT2 else begin
- if Trim(mT2)='' then cells[1,i+1]:='' else begin
- if oForm.FindComponent(mT2)=nil then Cells[1,i+1]:='? '+mT2 else Cells[1,i+1]:=mT2;
- end;
- end;
- end;
- j:=fS.Count;
- for i:=0 to fQ.Fields.count-1 do begin
- k:=fS.IndexOfName(fQ.Fields[i].FieldName);
- if k>-1 then begin
- cells[0,k+1]:=fQ.Fields[i].FieldName;
- continue;
- end;
- inc(j);
- cells[0,j]:=fQ.Fields[i].FieldName;
- end;
- finally
- if not fQ.active then begin
- ShowMessage(fQ.Name+' query - open error');
- Postmessage(Handle,wm_close,0,0);
- end;
- if not mB then fQ.Active:=false;
- end;
- end;
- end;
-
- procedure TF_EQRef.FormCreate(Sender: TObject);
- begin
- fFirst:=true;
- //fS:=TStringList.Create;
- //fS.Clear;
- //fForm:=self;
- end;
-
- procedure TF_EQRef.SpeedButton1Click(Sender: TObject);
- begin
- if StringGrid1.cells[1,StringGrid1.row]<>'' then Label2.caption:=StringGrid1.cells[1,StringGrid1.row];
- StringGrid1.cells[1,StringGrid1.row]:=ListBox1.Items[ListBox1.ItemIndex];
- end;
-
- procedure TF_EQRef.Label2DblClick(Sender: TObject);
- begin
- StringGrid1.cells[1,StringGrid1.row]:=Label2.caption;
- end;
-
- procedure TF_EQRef.ListBox1DblClick(Sender: TObject);
- begin
- SpeedButton1Click(sender);
- end;
-
- procedure TF_EQRef.Button1Click(Sender: TObject);
- begin
- fCancel:=false;
- close;
- end;
-
- procedure TF_EQRef.Button2Click(Sender: TObject);
- begin
- fCancel:=true;
- close;
- end;
-
- procedure TF_EQRef.Zapis;
- var i:integer;
- mT1,mt2,mS:String;
- begin
- fS.Clear; mS:='';
- with StringGrid1 do begin
- for i:=1 to RowCount-1 do begin
- mT1:=cells[0,i];
- mT2:=cells[1,i];
- while Pos('?',mT1)>0 do delete(mt1,Pos('?',mt1),1);
- while Pos('?',mT2)>0 do delete(mt2,Pos('?',mt2),1);
- mT1:=Trim(mT1); mT2:=Trim(mT2);
- if mT1<>'' then mS:=mS+mT1+'='+mT2+#13#10;
- end;
- end;
- fS.text:=mS;
- end;
-
- procedure TF_EQRef.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- if not fCancel then Zapis;
- end;
-
- end.
-
-