home *** CD-ROM | disk | FTP | other *** search
- // ******************************************************************************** //
- // SQL Builder For Interbase 5.6 //
- // Author: ▄mit BAKAR //
- // eMail:ubakar@karnet.com.tr //
- // www.karnet.com.tr //
- // ! FREEWARE ! //
- // ******************************************************************************** //
- // Contents: //
- // 1.Graphic Query design sample (similar Access) //
- // 2.LineDDA using sample //
- // 3.Drawing something (lines, images etc.) over the MDI form's ClientHandle //
- // 4.Convert the query results to CSV (comma delimited) format //
- // 5.Convert the query results to XLS format //
- // 6.Convert the query results to RTF format //
- // 7.Drag and Drop sample between TCheckListBoxes (Tables) //
- // ******************************************************************************** //
- // Notes:
- // This program is FREEWARE and open source. You can develop as you want or we //
- // can develop together if you have different opinions for this subject.
- // I am waiting your suggestions, opinions, critiques.
- // Kind Regards.
- // ******************************************************************************** //
-
- unit Unit1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,checklst,
- StdCtrls,IB, ActnList, ImgList, Menus, IBDatabase, Db,
- ComCtrls, ToolWin, IBCustomDataSet, IBQuery,IBSQL, ExtCtrls,
- Grids, DBGrids, StdActns, DBCtrls, OleServer, Excel97;
-
-
-
- type
- PDATableOfJoins = ^DATableOfJoins;
- DATableOfJoins = record //Records of Join
- RN: string; //Join Name
- ST : string; //Source Table
- Tt : string; //Target table
- SI: integer; //source item index
- TI: integer; //target item index
- SIX : integer; //Source item X position
- SIY : integer; //Source item Y position
- TIX : integer; //Target item X position
- TIY : integer; //Target item Y position
- Del : char; //Record Delete flag
- JT : string; //Join type (Inner,full,left,Right)
- end;
- type
- TForm1 = class(TForm)
- IBD: TIBDatabase;
- IBT: TIBTransaction;
- MainMenu1: TMainMenu;
- Database1: TMenuItem;
- Open1: TMenuItem;
- k1: TMenuItem;
- N1: TMenuItem;
- StatusBar1: TStatusBar;
- ToolBar1: TToolBar;
- popJoin: TPopupMenu;
- Sil1: TMenuItem;
- Inner: TMenuItem;
- btndbConnect: TToolButton;
- btnCikis: TToolButton;
- ToolButton1: TToolButton;
- btnsqlrun: TToolButton;
- btnTables: TToolButton;
- Panel1: TPanel;
- MemoSQLstr: TMemo;
- Splitter1: TSplitter;
- popdbconnect: TPopupMenu;
- ToolButton2: TToolButton;
- btnDisconnect: TToolButton;
- Disconnect1: TMenuItem;
- btngetsqltext: TToolButton;
- ToolButton4: TToolButton;
- btnsqltextsave: TToolButton;
- popSQL: TPopupMenu;
- btnSQLOutBrowse: TToolButton;
- btnsqlouttext: TToolButton;
- ToolButton3: TToolButton;
- btnsqloutCSV: TToolButton;
- SQLBuild1: TMenuItem;
- ResultView1: TMenuItem;
- OpenSQLTextFile1: TMenuItem;
- SaveSQLText1: TMenuItem;
- RunSQL1: TMenuItem;
- Tables1: TMenuItem;
- N2: TMenuItem;
- Browse1: TMenuItem;
- Report1: TMenuItem;
- AsciTextCSV1: TMenuItem;
- actions: TActionList;
- actExit: TAction;
- actdbConnect: TAction;
- actDBDisconnect: TAction;
- actOpenSQLtext: TAction;
- actRunSql: TAction;
- actTables: TAction;
- Left: TMenuItem;
- Right: TMenuItem;
- Full: TMenuItem;
- N3: TMenuItem;
- actWindow: TActionList;
- WindowCascade1: TWindowCascade;
- WindowArrange1: TWindowArrange;
- WindowClose1: TWindowClose;
- WindowTileHorizontal1: TWindowTileHorizontal;
- WindowTileVertical1: TWindowTileVertical;
- Window1: TMenuItem;
- ArrangeAll1: TMenuItem;
- Cascade1: TMenuItem;
- Tile1: TMenuItem;
- TileVertically1: TMenuItem;
- Close1: TMenuItem;
- N4: TMenuItem;
- SaveResult1: TMenuItem;
- btnExcel: TToolButton;
- SendtoExcel1: TMenuItem;
- procedure CloseAllChildForm;
- procedure MouseClick(Sender: TObject);
- procedure CLBDragOver(Sender, Source: TObject; X,
- Y: Integer; State: TDragState; var Accept: Boolean);
- procedure CLBDragDrop(Sender, Source: TObject; X,
- Y: Integer);
- procedure ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
-
- procedure ConnectDB(Sender: TObject);
- procedure Line_ReDraw;
- procedure lbTableDblClick(Sender: TObject);
- procedure SQLStringReCreate(Sender: TObject);
- procedure ChildFormClose(Sender: TObject; var Action: TCloseAction);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure FormCreate(Sender: TObject);
- procedure SQLrun(Sender: TObject);
-
- procedure ChildMove(Sender: TObject);
- procedure k1Click(Sender: TObject);
- procedure Sil1Click(Sender: TObject);
- procedure btnTablesClick(Sender: TObject);
- procedure tempFormClose(Sender: TObject; var Action: TCloseAction);
- procedure btndbConnectClick(Sender: TObject);
- procedure ODiaDBCanClose(Sender: TObject; var CanClose: Boolean);
- procedure DisConnectDB(Sender: TObject);
- procedure popItemAdd(vdbname:string);
- procedure btngetsqltextClick(Sender: TObject);
- procedure btnsqltextsaveClick(Sender: TObject);
- procedure SaveSqltext(Sender: TObject);
- procedure popsqlitemekle(vsqlname:string);
- procedure SQLActive(Sender: TObject);
- procedure AnimateRun(v_animname:string;v_parent:TWinControl);
- procedure AnimateFree(v_animname:string;v_parent:TWinControl);
- procedure RichEditFormat(vrie:TrichEdit;vdataset:Tdataset);
- procedure RieOutRenk(vrie:TrichEdit;v_color:Tcolor);
- procedure Browse1Click(Sender: TObject);
- procedure Report1Click(Sender: TObject);
- procedure AsciTextCSV1Click(Sender: TObject);
- procedure actExitExecute(Sender: TObject);
- procedure MemoSQLstrChange(Sender: TObject);
- procedure PopJoinTypeClick(Sender: TObject);
- procedure CheckListBoxDblClick(Sender: TObject);
- procedure CheckListBoxKeyEnter(Sender: TObject;var Key: Char);
- procedure SaveResult1Click(Sender: TObject);
- procedure DBGridColEnter(Sender: TObject);
- procedure SendtoExcel1Click(Sender: TObject);
- procedure SendToExcel(v_Dset:Tdataset);
-
-
-
-
- private
- OWproc,NWproc:Pointer;
- Procedure NewWinP(var msg:Tmessage);
-
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
- Oc:Tcanvas;
- vmPoint:Tpoint;
- vmousemove:boolean;
- vselecteditem:integer;
- MainImage:TImage; // mainimage is a temp image that to draw the join lines
- // between tables on the MDI form's ClientHandle
- vcurdir:string;
- v_DDAok:Boolean;
- vRlist:Tlist;
- DARR: PDATableOfJoins; // Pointer of Join records (vRlist)
- implementation
- uses frmCh; //Child form
- {$R *.DFM}
- {$R IBSBIMAGES.RES}
-
- //................................................................................//
- // This function is returns X,Y coordinates for a Join line's highlighted points
- //................................................................................//
- procedure JoinLineDDAFunction(X,Y: Integer; TheCanvas: TCanvas); stdcall;
- begin
- if (vmpoint.X = X) and (vmpoint.Y = Y) then
- v_DDAok:=True;
- end;
-
-
- procedure TForm1.FormCreate(Sender: TObject);
- var vpopdblist:TstringList;
- vi:integer;
- ImageList1:TimageList;
- begin
-
- vRList:=Tlist.Create; //Join Records
-
- // Load images from IBSBIMAGES.RES
- ImageList1:=Timagelist.Create(Self);
- with ImageList1 do
- begin
- Height:=32;
- width:=32;
- ResourceLoad(rtBitmap,'IMAGES', clbtnFace);
- geticon(11,application.icon);
- end;
- Toolbar1.Images:=imagelist1;
-
- mainImage:= TImage.create(self);
- with mainImage do
- begin
- parent:=form1;
- Align:=alClient;
- transparent:=true;
- onMouseMove:=ImageMouseMove;
- onClick:=MouseClick;
- end;
-
-
- NWproc:=MakeObjectInstance(NewWinP);
- OWproc:=Pointer(setWindowLong(Clienthandle,gwl_wndproc,cardinal(NWproc)));
- OC:=Tcanvas.Create;
- //get current directory
- vcurdir:=trim(getcurrentdir);
-
- //Load Previous Database Connections
- if Fileexists(vcurdir+'\PopDbIt.dat') then
- begin
- vpopdblist:=tstringlist.Create;
- vpopdblist.LoadFromFile(vcurdir+'\popDbIt.dat');
- for vi:=0 to vpopdblist.Count-1 do
- begin
- if Fileexists(vpopdblist.Strings[vi]) then
- popdbconnect.Items.Add(NewItem(vpopdblist.Strings[vi],TextToShortCut('') ,False, True, connectdb, 0, 'mi_db'+inttostr(popdbconnect.Items.Count)) );
- end;
- vpopdblist.Free;
- end;
-
- //Load previous SQL Commands Which has been executed and saved.
- if Fileexists(vcurdir+'\PopSQL.dat') then
- begin
- vpopdblist:=tstringlist.Create;
- vpopdblist.LoadFromFile(vcurdir+'\popSQL.dat');
- for vi:=0 to vpopdblist.Count-1 do
- begin
- if Fileexists(vpopdblist.Strings[vi]) then
- popSQL.Items.Add(NewItem(vpopdblist.Strings[vi],TextToShortCut('') ,False, True, btngetsqltextclick, 0, 'mi_sql'+inttostr(popsql.Items.Count)) );
- end;
- vpopdblist.Free;
- end;
-
- end;
-
- // .............................................................................. //
- // New WinProc For drawing ClientHandle
- // .............................................................................. //
- procedure TForm1.NewwinP(var msg:Tmessage);
- begin
- msg.Result:=CallWindowProc(OWproc,clientHandle,msg.msg,msg.Wparam,msg.lParam);
- if msg.msg=wm_EraseBkgnd then
- begin
- OC.handle:=msg.WParam;
- oc.CopyMode:= cmsrcand;
- oc.CopyRect(mainimage.ClientRect,mainimage.Canvas,mainimage.ClientRect);
- end;
- end;
-
-
- procedure TForm1.lbTableDblClick(Sender: TObject);
- var vform:TfrmChild;
- vclb:TcheckListBox;
- vitemname:string;
- vleft,vtop:integer;
- Qrelf:TibSQL;
- begin
- if (sender is TcheckListbox) then
- begin
- vitemname:=(sender as tchecklistbox).items[(sender as tchecklistbox).itemindex];
- if not (sender as tchecklistbox).checked[(sender as tchecklistbox).itemindex]
- then
- begin
- if (application.findcomponent(vitemname) is TfrmChild) then
- (application.findcomponent(vitemname) as TfrmChild).Close;
- exit;
- end;
- end
- else
- if (sender is Tlistbox) then
- vitemname:=(sender as tlistbox).items[(sender as tlistbox).itemindex]
- else
- exit;
-
- if findComponent('Clb_'+vitemname)<>nil then
- begin
- showmessage('Table Already Exist') ;
- exit;
- end;
-
-
-
- if mdiChildCount>1 then
- begin
- vleft:= mdiChildren[1].BoundsRect.Right ;
- vtop:= mdiChildren[1].BoundsRect.top;
- end
- else
- begin
- vleft:= mdiChildren[0].BoundsRect.Right;
- vtop:= mdiChildren[0].BoundsRect.top;
- end;
-
-
- vform:=TfrmChild.Create(application);
- with vform do
- begin
- width:=80;
- height:=120;
- formstyle:=fsMDIChild;
- name:=vitemname;
- caption:=vitemname;
- DragMode:=dmAutomatic;
- left:=vleft;
- top:=vtop;
- OnClose:=ChildFormClose;
- OnPaint:=ChildMove;
- visible:=true;
- end;
-
-
- vclb:=TcheckListBox.Create(self);
- with vclb do
- begin
- Parent:=ActiveMDIChild;
- name:='Clb_'+vitemname;
- Visible:=True;
- align:=alClient;
- Dragmode:=dmAutomatic;
- OnDragDrop:=CLBDragDrop;
- OnDragOver:= CLBDragOver;
- OnClickCheck:=SQLStringReCreate;
- onDblClick:=CheckListBoxDblClick;
- onkeyPress:= CheckListBoxKeyEnter;
-
- end;
- //? Read Columns of the table
- Qrelf:=TibSQL.Create(self);
- with qrelf do
- begin
- database:=ibd;
- transaction:=ibt;
- SQL.Clear;
- SQL.add('Select rdb$field_name as fname from rdb$relation_fields where rdb$relation_name="'+vitemname+'" ');
- ExecQuery;
- end;
- while not Qrelf.Eof do
- begin
- vclb.Items.add(trim(Qrelf.Fields[0].asstring));
- Qrelf.next;
- end;
-
- (application.findcomponent('Tables') as tform).show; //tables mdiChildForm setfocus
-
- qrelf.Free;
- end;
-
-
- procedure TForm1.ChildMove(Sender: TObject);
- begin
- Line_ReDraw; //? Join lines Redraw, because Child Form moved etc.
- end;
-
- procedure TForm1.ChildFormClose(Sender: TObject; var Action: TCloseAction);
- var vs:Integer;
- vtablescheckfalse:TchecklistBox;
- begin
- action:=caFree;
- for vs:=0 to vRlist.count-1 do
- begin
- DARR:=vRlist.Items[vs];
- if (DARR^.ST='Clb_'+(sender as tform).caption) or (DARR^.TT='Clb_'+(sender as tform).caption)
- then
- DARR^.Del:='D';
- end;
- Line_ReDraw;
- (sender as tform).controls[0].Free;
- SQLStringReCreate(sender);
- if (findComponent('checkListBoxTables')<>nil) then
- begin
- vtablescheckFalse:=(findcomponent('checkListBoxTables') as tchecklistbox) ;
- vtablescheckFalse.Checked[vtablescheckFalse.items.indexof((sender as tform).caption)]:=false;
- vtablescheckFalse:=nil;
- end;
-
- end;
-
- procedure Tform1.CloseAllChildForm;
- var v_sayac:integer;
- begin
- for v_sayac:=0 to MDIChildCount-1 do
- begin
- mdiChildren[v_sayac].close;
- end;
- end;
-
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- var v_sayac:integer;
- vpopdbitems:Tstringlist;
- begin
- CloseAllChildForm;
-
- if popdbconnect.Items.Count>0 then
- begin
- vpopdbitems:=tstringlist.Create;
- for v_sayac:=0 to popdbconnect.Items.Count-1 do
- begin
- vpopdbitems.Add(popdbconnect.items[v_sayac].Caption);
- end;
-
- vpopdbitems.SaveToFile(vcurdir+'\popdbit.dat');
- vpopdbitems.Free;
- end;
- if popsql.Items.Count>0 then
- begin
- vpopdbitems:=tstringlist.Create;
- for v_sayac:=0 to popsql.Items.Count-1 do
- begin
- vpopdbitems.Add(popsql.items[v_sayac].Caption);
- end;
-
- vpopdbitems.SaveToFile(vcurdir+'\popsql.dat');
- vpopdbitems.Free;
- end;
-
- for v_sayac:=0 to vRlist.Count-1 do
- begin
- DARR:=vRlist.Items[v_sayac];
- Dispose(DARR);
- end;
- vRList.free;
-
- end;
-
- procedure TForm1.SQLStringReCreate(Sender: TObject);
- var v_sayac,v_sayacclb,v_checkkontrol,v_sayac2:integer;
- vclbTemp:TcheckListBox;
- v_fromStr:Tstringlist;
- v_ST,v_TT:string;
- begin
- MemoSQLstr.Lines.text:='';
-
-
- v_fromstr:=Tstringlist.Create;
- MemoSqlStr.Lines.Add('Select ');
- v_sayac2:=0;
- for v_sayac:=0 to MDIChildCount-1 do
- begin
- if (mdiChildren[v_sayac].caption='Tables') or (copy(mdiChildren[v_sayac].name,1,12)='frmSQLresult') then
- continue;
- if (sender.classname='TForm') and (mdiChildren[v_sayac].Name=(Sender as Tform).name) then
- begin
- continue;
- end;
- if (mdiChildren[v_sayac].ControlCount=0) then continue;
- v_checkkontrol:=0;
- vclbTemp:=TcheckListbox(FindComponent('Clb_'+form1.mdiChildren[v_sayac].name));
- for v_sayacclb:=0 to vclbTemp.Items.Count-1 do
- begin
- if vclbTemp.Checked[v_sayacclb] then
- begin
- Inc(v_sayac2);
-
- if v_sayac2=1 then
- MemoSqlStr.Lines.Add(mdiChildren[v_sayac].name+'.'+vclbTemp.items.strings[v_sayacclb])
- else
- begin
- memoSqlstr.Lines.Strings[memoSqlstr.Lines.count-1]:=memoSqlstr.Lines.Strings[memoSqlstr.Lines.count-1]+',';
- MemoSqlStr.Lines.Add(mdiChildren[v_sayac].name+'.'+vclbTemp.items.strings[v_sayacclb]);
- end;
- v_checkkontrol:=1;
- end;
- end;
- if v_checkkontrol=1 then
- begin
- v_fromStr.Add(mdiChildren[v_sayac].name)
- end;
- vclbTemp:=nil;
- end;
-
- MemoSqlStr.Lines.Add('From ');
- v_sayac2:=0;
-
-
- if v_fromstr.Count=0 then
- MemoSqlStr.Lines.text:=''
- else
- begin
- // Joins
-
- if vRlist.count>0 then
- begin
- v_fromstr.Clear;
- for v_sayac:=0 to vRlist.count-1 do
- begin
- DARR:=vRlist.Items[v_sayac];
- v_ST:=copy(DARR^.ST,pos('_',DARR^.ST)+1,length(DARR^.ST));
- v_TT:=copy(DARR^.TT,pos('_',DARR^.TT)+1,length(DARR^.TT));
- if v_sayac=0 then
- MemoSqlStr.Lines.add(v_ST+' '+DARR^.JT+' join '+ V_Tt+' on '+ v_ST+'.'+copy(DARR^.RN,1,pos('_',DARR^.RN)-1)+'='+v_Tt+'.'+copy(DARR^.RN,pos('_',DARR^.RN)+1,length(DARR^.RN)))
- else
- MemoSqlStr.Lines.add(DARR^.JT+' join '+ v_Tt+' on '+ v_ST+'.'+copy(DARR^.RN,1,pos('_',DARR^.RN)-1)+'='+v_Tt+'.'+copy(DARR^.RN,pos('_',DARR^.RN)+1,length(DARR^.RN)));
- end; //for vRlist
-
-
- end
- else //if vRlistcount>0
- begin
- for v_sayac:=0 to v_fromStr.Count-1 do
- begin
- v_sayac2:=v_sayac2+1;
- if v_sayac2=1 then
- MemoSqlStr.Lines.Add(v_fromStr.Strings[v_sayac])
- else
- begin
- MemoSqlStr.Lines.strings[MemoSqlStr.Lines.count-1]:=MemoSqlStr.Lines.strings[MemoSqlStr.Lines.count-1]+',';
- MemoSqlStr.Lines.Add(v_fromStr.Strings[v_sayac]);
- end;
- end;
-
- end;// if vRlist.count>0
-
- end; //if v_fromstr.Count=0
-
- v_fromStr.Free;
- end;
-
-
-
- procedure TForm1.CLBDragOver(Sender, Source: TObject; X,
- Y: Integer; State: TDragState; var Accept: Boolean);
- begin
- Accept := Source is TCheckListBox;
- end;
-
- procedure TForm1.CLBDragDrop(Sender, Source: TObject; X, Y: Integer);
- var vpoint,vMoveP,vLineP:Tpoint;
- vtr:Trect;
- vtr1:Trect;
- vSender,vSource:TCheckListBox;
- begin
- if (Sender is TCheckListBox) and (Source is TCheckListBox) and ((Sender as TcheckListbox).name<>(Source as TcheckListBox).name)
- then
- begin
- vSource:=(Source as TcheckListBox);
- vSender:=(Sender as TcheckListBox);
- with vSender do
- begin
- vpoint.x:=x;
- vpoint.y:=y;
- if vSender.ItemAtPos(vpoint,true)<0 then
- begin
- vSender.items.Add(vSource.items.Strings[vSource.itemindex]);
- exit;
- end
- else
- begin
- with mainImage do
- begin
- vtr:=vSource.ItemRect(vSource.itemindex);
- vtr1:=vtr;
- vMoveP.x:=(vSource.Parent.BoundsRect.BottomRight.x);
- vMoveP.y:=(vSource.Parent.top)+vSource.top+vtr.BottomRight.y+20;
-
- vSender.itemindex:=vSender.ItemAtPos(vpoint,true);
- vtr:=vSender.ItemRect(vSender.itemindex);
- vLineP.x:=(vSender.Parent.BoundsRect.Left);
- vLineP.y:=(vsENDER.Parent.Top)+vSender.top+vtr.Bottom+20;
- canvas.Pen.color:=clSilver;
- canvas.Pen.width:=2;
-
- vMoveP.y:=vMoveP.y-1;
- vLineP.y:=vLineP.y-1;
- Canvas.polyline([vMoveP,vLineP]);
-
- vMoveP.y:=vMoveP.y+2;
- vLineP.y:=vLineP.y+2;
- Canvas.polyline([vMoveP,vLineP]);
-
- canvas.Pen.width:=1;
- canvas.Pen.color:=clBlack;
- vMoveP.y:=vMoveP.y-1;
- vLineP.y:=vLineP.y-1;
- Canvas.polyline([vMoveP,vLineP]);
-
- New(DARR);
- DARR^.RN:=vSource.items.Strings[vSource.itemindex]+'_'+Items.Strings[vSender.itemindex];
- DARR^.ST:=vSource.name;
- DARR^.Tt:=vSender.name;
- DARR^.SI:=vSource.itemindex;
- DARR^.TI:=vSender.itemindex;
- DARR^.SIX:=vMoveP.x;
- DARR^.SIY:=vMoveP.y;
- DARR^.TIX:=vLineP.x;
- DARR^.TIY:=vLineP.y;
- DARR^.Del:=#0;
- DARR^.JT:='Inner';
-
- vRlist.Add(DARR);
- vRlist.Capacity := vRlist.Count;
- InvalidateRect(ClientHandle, nil, True); //ClientHandle update
- SQLStringReCreate(self);
- end;
- end;
- end;
- end;
- end;
-
-
- procedure TForm1.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- var vsy:integer;
- begin
- vmpoint.x:=x;
- vmpoint.y:=y;
- v_DDAok:=False;
- statusbar1.Panels[0].Text:='';
-
- if (mainImage.Canvas.Pixels[X,Y]=clBlack) or (mainImage.Canvas.Pixels[X,Y]=clSilver) then
- begin
- For vsy:=0 to vRlist.Count-1 do
- begin
- DARR:=vRlist.Items[vsy];
- //..........................................................................//
- // The LineDDA function determines which pixels should be highlighted for a
- // line defined by the specified starting and ending points.
- //..........................................................................//
- LineDDA(DARR^.SIX,DARR^.SIY-1,DARR^.TIX,DARR^.TIY-1,@JoinLineDDAFunction,LongInt(MainImage.Canvas));
- if v_DDAok then break;
- LineDDA(DARR^.SIX,DARR^.SIY+2,DARR^.TIX,DARR^.TIY+1,@JoinLineDDAFunction,LongInt(MainImage.Canvas));
- if v_DDAok then break;
- LineDDA(DARR^.SIX,DARR^.SIY,DARR^.TIX,DARR^.TIY,@JoinLineDDAFunction,LongInt(MainImage.Canvas));
- if v_DDAok then break;
- end;
- if v_DDAok then
- statusbar1.Panels[0].Text:=DARR^.JT+' '+DARR^.RN ;
- end;
- end;
-
-
-
-
- procedure TForm1.MouseClick(Sender: TObject);
- var vsy:integer;
- begin
- v_DDAok:=False;
- statusbar1.Panels[0].Text:='';
-
- if (mainImage.Canvas.Pixels[vmpoint.x,vmpoint.y]=clBlack) or (mainImage.Canvas.Pixels[vmpoint.x,vmpoint.y]=clSilver) then
- begin
- For vsy:=0 to vRlist.Count-1 do
- begin
- DARR:=vRlist.Items[vsy];
- LineDDA(DARR^.SIX,DARR^.SIY-1,DARR^.TIX,DARR^.TIY-1,@JoinLineDDAFunction,LongInt(MainImage.Canvas));
- if v_DDAok then break;
- LineDDA(DARR^.SIX,DARR^.SIY+2,DARR^.TIX,DARR^.TIY+1,@JoinLineDDAFunction,LongInt(MainImage.Canvas));
- if v_DDAok then break;
- LineDDA(DARR^.SIX,DARR^.SIY,DARR^.TIX,DARR^.TIY,@JoinLineDDAFunction,LongInt(MainImage.Canvas));
- if v_DDAok then break;
- end;
- if v_DDAok then
- begin
- statusbar1.Panels[0].Text:=DARR^.JT+' '+DARR^.RN;
- (findcomponent(DARR^.JT) as TmenuItem).checked:=true;
- popJoin.Popup(vmpoint.x,mainimage.top+vmpoint.y) ;
- vselecteditem:=vsy; end;
- end;
-
- end;
-
-
-
-
-
- procedure TForm1.Line_ReDraw;
- var vsy,vsilinen:integer;
- vMoveP,vLineP:Tpoint;
- vSource,vSender:TcheckListbox;
- vtr,vtr1:Trect;
- begin
- mainimage.Picture.Graphic:=nil;
- try
- for vsy:=0 to vRlist.count-1 do
- begin
- DARR:=vRlist.items[vsy];
- if DARR^.Del='S' then continue;
-
- if DARR^.Del='D' then
- begin
- DARR^.Del:='S';
- continue;
- end;
-
-
- vSource:=(form1.findcomponent(DARR^.ST) as TcheckListBox);
- vSender:=(form1.findcomponent(DARR^.Tt) as TcheckListBox);
- vtr:=vSource.ItemRect(DARR^.SI);
- vtr1:=vSender.ItemRect(DARR^.TI);
-
- vMoveP.x:=(vSource.Parent.BoundsRect.BottomRight.x);
- if ((vtr.Bottom+20) > vSource.BoundsRect.Bottom) then
- vMoveP.y:=(vSource.Parent.BoundsRect.Bottom)
- else
- if ((vtr.Bottom+20) < vSource.BoundsRect.top) then
- vMoveP.y:=(vSource.Parent.top)+vSource.top
- else
- vMoveP.y:=(vSource.Parent.top)+vSource.top+vtr.BottomRight.y+20;
-
- vLineP.x:=(vSender.Parent.BoundsRect.Left);
- if ((vtr1.Bottom+20) > vsender.BoundsRect.Bottom) then
- vLineP.y:=(vsENDER.Parent.BoundsRect.Bottom)
- else
- if ((vtr1.Bottom+20) < vsender.BoundsRect.top) then
- vLineP.y:=(vsENDER.Parent.Top)+vSender.top
-
- else
- vLineP.y:=(vsENDER.Parent.Top)+vSender.top+vtr1.Bottom+20;
- MainImage.Canvas.pen.color:=clSilver;
- MainImage.canvas.Pen.width:=2;
- vMoveP.y:=vMoveP.y-1;
- vLineP.y:=vLineP.y-1;
- MainImage.canvas.polyline([vMoveP,vLineP]);
-
- vMoveP.y:=vMoveP.y+2;
- vLineP.y:=vLineP.y+2;
- MainImage.canvas.polyline([vMoveP,vLineP]);
- MainImage.Canvas.pen.color:=clBlack;
- MainImage.canvas.Pen.width:=1;
-
- vMoveP.y:=vMoveP.y-1;
- vLineP.y:=vLineP.y-1;
- MainImage.canvas.polyline([vMoveP,vLineP]);
- DARR^.SIX:= vMoveP.x;
- DARR^.SIY:= vMoveP.y;
- DARR^.TIX:= vLineP.x;
- DARR^.TIY:= vLineP.y;
- end; //for
- InvalidateRect(ClientHandle, nil, True); //ClientHandle update
- vSilinen:=0;
- for vsy:=0 to vRlist.Count-1 do
- begin
- DARR:=vRlist.items[vsy-vsilinen];
- if DARR^.Del = 'S' then
- begin
- Dispose(DARR);
- vRlist.Delete(vsy-vsilinen);
- vRlist.Capacity:=vRlist.Count;
- vsilinen:=vsilinen+1;
- end;
- end; //for (Deleted records)
- except
- exit;
- end;
- end;
-
- procedure TForm1.SQLRun(Sender: TObject);
- var vSQLfrm:Tform;
- vdbg:TdbGrid;
- vds:Tdatasource;
- vibq:Tibquery;
- vre:TrichEdit;
- begin
- try
- vSQLFrm:=tform.Create(application);
- vSQLfrm.name:='frmSQLresult'+inttostr(mdiChildCount) ;
-
- with Tbutton.create(self) do
- begin
- parent:=vSQLfrm;
- name:='btn_'+inttostr(mdiChildCount);
- Caption:='Refresh SQL';
- align:=alTop;
- onClick:=sqlActive;
- end;
-
-
- vibq:=tibquery.Create(vSQLfrm);
- vibq.name:='ibq_frmSQLresult'+ inttostr(mdiChildCount);
- vibq.Database:=ibd;
- vibq.Transaction:=ibt;
- vibq.SQL:=memoSQLStr.Lines;
- AnimateRun('sqlanim',form1);
- form1.Repaint;
- vSQLfrm.Caption:='(Start Time:'+timetostr(now);
- ibt.Active:=true;
- vibq.Prepare;
- vibq.Active:=true;
- if btnExcel.Down then
- begin
- SendToExcel(vibq);
- AnimateFree('sqlanim',form1);
- vsqlfrm.free;
- vibq.free;
- exit;
- end;
-
-
- vds:=tdatasource.Create(vSQLfrm);
- vds.name:='dssql_frmSQLresult' + inttostr(mdiChildCount);
- vds.DataSet:=vibq;
-
- with Tmemo.create(vSQLfrm) do
- begin
- parent:=vSQLfrm;
- name:='mem_frmSQLresult'+inttostr(mdiChildCount);
- lines:=memoSQLstr.Lines;
- align:=alTop;
- height:=80;
- scrollBars:=ssBoth;
- end;
-
- if btnSQLOutBrowse.Down then
- begin
- vdbg:=TdbGrid.Create(vSQLfrm);
- vdbg.parent:=vSQLfrm;
- vdbg.align:=alClient;
- vdbg.DataSource:=vds;
- vdbg.name:='dbg_frmSQLresult'+ inttostr(mdiChildCount);
- vdbg.Options:=[dgTitles,dgIndicator,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgConfirmDelete,dgCancelOnExit];
- end
- else
- begin
- vre:=TrichEdit.Create(vSQLfrm);
- with vre do
- begin
- parent:=vSQLfrm;
- align:=alClient;
- name:='rie_frmSQLresult'+ inttostr(mdiChildCount);
- HideScrollBars:=False;
- WantReturns:=True;
- ScrollBars:=ssboth;
- PlainText:=true;
- WordWrap:=false;
- Wanttabs:=false;
- Font.name:='Lucida Console';
- end;
- RichEditFormat(vre,vibq);
- end; //else browse=down
- AnimateFree('sqlanim',form1);
- vibq.Last;
- vibq.first;
- vSQLfrm.FormStyle:=fsMDIChild;
- vSQLfrm.Caption:=vSQLfrm.Caption+' End Time:'+timetostr(now)+ ') '+'Record Count:'+inttostr(vibq.recordcount);
- vsqlfrm.onclose:=tempformClose;
- vSqlFrm.Show;
- if btnSQLOutBrowse.Down then
- begin
- vdbg.SetFocus;
- vdbg.SelectedIndex:=0;
- dbGridColEnter(vdbg);
- vdbg.OnColEnter:=dbGridColEnter;
- end;
- ibt.CommitRetaining;
- except
- on E : EibInterbaseError do
- Begin
- showmessage(E.Message +' - '+inttostr(E.IBErrorCode));
- ibt.Rollback;
- AnimateFree('sqlanim',form1);
- vre.Free;
- vsqlfrm.free;
- vdbg.free;
- vds.free;
- vibq.free;
- ibt.active:=true;
- End;
- else
- ibt.Rollback;
- AnimateFree('sqlanim',form1);
- vre.Free;
- vsqlfrm.free;
- vdbg.free;
- vds.free;
- vibq.free;
- ibt.active:=true;
- end;
-
- end;
-
- procedure TForm1.RichEditFormat(vrie:TrichEdit;vdataset:Tdataset);
- var v_sql,v_labelsize,v_kayitsayi,v_datasize:integer;
- v_str,v_strciz,v_cizgi,v_cizdata:string;
- v_bos,v_ciz:string;
- begin
- v_bos:=' ';
- v_cizdata:='___________________________________________________________________________________________________________________________________';
- v_ciz:='======================================================================================================================================================================================================================';
-
- try
- v_str:='';
- v_cizgi:='';
- if btnSQLOutCsv.Down then
- vrie.Lines.clear // E≡er csv formatl² yaz²lacaksa ╟²kt²n²n yaz²laca≡² edit÷r temizleniyor
- else
- begin
- vrie.Lines.Clear;
- end;
-
- if btnSQLOutCsv.Down=false then
- begin
-
- for v_sql:=0 to vdataset.FieldCount -1 do
- begin
- v_labelsize:=length(vdataset.fields[v_sql].Fieldname);
-
- if vdataset.fields[v_sql].DataType= ftDate then // tarih alan²
- v_datasize:=10
- else
- v_datasize:=vdataset.fields[v_sql].DataSize;
-
- if vdataset.fields[v_sql].isBlob then // BLOB
- v_datasize:=8;
-
- v_str:=v_str+vdataset.fields[v_sql].Fieldname;
- if v_labelsize>v_datasize then
- begin
- v_str:=v_str+'ª';
- v_cizgi:=v_cizgi+ copy(v_ciz,1,v_labelsize)+'ª';
- end
- else
- begin
- v_str:=v_str+copy(v_bos,1,v_datasize-(v_labelsize))+'ª';
- v_cizgi:=v_cizgi+ copy(v_ciz,1,v_datasize)+'ª';
- end;
- end; //For
- end
- else
- begin
- for v_sql:=0 to vdataset.FieldCount -1 do
- begin
- if v_str='' then
- begin
- v_str:=v_str+'"'+vdataset.fields[v_sql].Fieldname+'"'
- end
- else
- v_str:=v_str+',"'+vdataset.fields[v_sql].Fieldname+'"';
- end; //For
-
-
- end; //if CSV
- RieOutRenk(vrie,clRed);
- if btnSQLOutCsv.Down=false then
- vrie.lines.add(v_cizgi);
- vrie.lines.add(v_str);
- if btnSQLOutCsv.Down=false then
- vrie.lines.add(v_cizgi);
- RieOutRenk(vrie,clBlack);
-
- v_kayitsayi:=0;
- while not vdataset.eof do
- begin
- v_str:='';
- v_strciz:='';
- for v_sql:=0 to vdataset.FieldCount -1 do
- begin
- v_labelsize:=length(vdataset.fields[v_sql].Fieldname);
- if vdataset.fields[v_sql].DataType = ftDate then // Date field
- v_datasize:=10
- else
- v_datasize:=vdataset.fields[v_sql].DataSize;
- if vdataset.fields[v_sql].isBlob then // BLOB
- v_datasize:=8;
-
- if btnSQLOutCsv.Down=false then
- begin
- if vdataset.fields[v_sql].isblob then // BLOB
- v_str:=v_str+'BLOB '
- else
- v_str:=v_str+vdataset.fields[v_sql].asstring;
- if vdataset.fields[v_sql].isBlob then // BLOB
- v_strciz:=v_strciz+copy(v_cizdata,1,8)
- else
- v_strciz:=v_strciz+copy(v_cizdata,1,length(vdataset.fields[v_sql].asstring));
- if v_labelsize>v_datasize then
- begin
- if vdataset.fields[v_sql].isBlob then // BLOB
- Begin
- v_str:=v_str+copy(v_bos,1,v_labelsize-(8))+'ª';
- v_strciz:=v_strciz+copy(v_cizdata,1,v_labelsize-(8))+'ª';
- end
- else
- Begin
- v_str:=v_str+copy(v_bos,1,v_labelsize-(LENGTH(vdataset.fields[v_sql].asstring)))+'ª';
- v_strciz:=v_strciz+copy(v_cizdata,1,v_labelsize-(LENGTH(vdataset.fields[v_sql].asstring)))+'ª';
- end; //blob
- end
- else
- begin
- v_str:=v_str+copy(v_bos,1,v_datasize-(LENGTH(vdataset.fields[v_sql].asstring)))+'ª';
- v_strciz:=v_strciz+copy(v_cizdata,1,v_datasize-(LENGTH(vdataset.fields[v_sql].asstring)))+'ª';
- end; // if v_labelsize
- end //if CSV
- else
- begin
- if v_str='' then
- v_str:=v_str+'"'+vdataset.fields[v_sql].asstring+'"'
- else
- v_str:=v_str+',"'+vdataset.fields[v_sql].asstring+'"';
- end; //if CSV
- end; //for
- v_kayitsayi:=v_kayitsayi+1;
- vrie.lines.add(v_str);
- if btnSQLOutCsv.Down=false then
- vrie.lines.add(v_strciz);
- vdataset.next;
- end; //for
- if btnSQLOutCsv.Down=false then
- begin
- RieOutRenk(vrie,clRed);
- vrie.lines.add(inttostr(v_kayitsayi)+' Records');
- RieOutRenk(vrie,clBlack);
- end;
-
- except
- end;
-
- end;
-
- procedure TForm1.AnimateRun(v_animname:string;v_parent:TWinControl);
- begin
- with Tanimate.Create(self) do
- begin
- parent:=v_parent;
- name:=v_parent.Name+'_'+v_animname;
- Align:=alclient;
- CommonAVI:=aviFindFolder;
- active:=true;
- end;
- end;
-
-
- procedure TForm1.AnimateFree(v_animname:string;v_parent:TWinControl);
- begin
- if (findComponent(v_parent.Name+'_'+v_animname) is Tanimate) then
- (findComponent(v_parent.Name+'_'+v_animname) as Tanimate).free;
- end;
-
- //////////////////////////////////////////////////////////////
- // TForm1.SQLActive = SQL Refresh in Result form
- //////////////////////////////////////////////////////////////
- procedure TForm1.SQLActive(Sender: TObject);
- var vfrmName:string;
- vmemo:Tmemo;
- vrie:TrichEdit;
- vdset:Tdataset;
- begin
-
- vfrmName:= (sender as tbutton).parent.Name;
- vmemo:=(activeMDIchild.findComponent('mem_'+vfrmName) as Tmemo);
- with (activeMDIchild.findComponent('ibq_'+vfrmName) as TIBQuery) do
- begin
- active:=false;
- SQL:=vmemo.Lines;
- AnimateRun('anim',(sender as Tbutton));
- active:=true;
- end; // with
-
- if (activeMDIchild.findComponent('rie_'+vfrmName) as TRichEdit) <>nil then
- begin
- vrie:=(activeMDIchild.findComponent('rie_'+vfrmName) as TRichEdit);
- vdset:=(activeMDIchild.findComponent('ibq_'+vfrmName) as TIBQuery);
- RichEditFormat(vrie,vdset);
- vdset:=nil;
- vrie:=nil
- end;
- AnimateFree('anim',(sender as Tbutton));
- vmemo:=nil;
- end; //TForm1.SQLActive(Sender: TObject)
- //////////////////////////////////////////////////////////////
-
-
-
- procedure TForm1.k1Click(Sender: TObject);
- begin
- close;
- end;
-
- procedure TForm1.Sil1Click(Sender: TObject);
- begin
- DARR:=vRlist.items[vselecteditem];
- DARR^.Del:='D';
-
- Line_Redraw;
- SQLStringReCreate(sender);
- vselecteditem:=0;
- end;
-
- procedure TForm1.CheckListBoxDblClick(Sender: TObject);
- begin
- if (sender is TcheckListBox) then
- begin
- (sender as Tchecklistbox).checked[(sender as Tchecklistbox).ItemIndex]:= not (sender as Tchecklistbox).checked[(sender as Tchecklistbox).ItemIndex];
- (sender as Tchecklistbox).onClickCheck(sender);
- end;
- end;
-
- procedure TForm1.CheckListBoxKeyEnter(Sender: TObject;var Key: Char);
- begin
- if (sender is TcheckListBox) and (key= #13) then
- begin
- CheckListBoxDblClick(sender);
- end;
- end;
-
- procedure TForm1.btnTablesClick(Sender: TObject);
- var vclbtablo:TcheckListBox;
- vtempform:Tform;
- v_sayac:integer;
- begin
-
- if application.findComponent('Tables')<>nil then exit;
-
- vtempform:=tform.create(application);
- with vtempform do
- begin
- formstyle:=fsMDIChild;
- width:=200;
- height:=200;
- onClose:=TempFormClose;
- caption:='Tables';
- name:='Tables';
- left:=0;
- top:=0;
-
- end;
- vclbTablo:=TcheckListBox.create(self);
-
- with vclbtablo do
- begin
- parent:=vtempform;
- name:='checkListBoxTables';
- align:=alClient;
- sorted:=true;
- onClickCheck:=lbTableDblClick;
- onDblClick:=CheckListBoxDblClick;
- onkeyPress:= CheckListBoxKeyEnter;
- end;
-
- ibd.GetTableNames(vclbTablo.items,False);
- for v_sayac:=0 to vclbTablo.items.count-1 do
- begin
- if (findcomponent('Clb_'+vclbtablo.Items.Strings[v_sayac])) <> nil then
- vclbtablo.Checked[v_sayac] :=true;
- end;
-
- end;
-
- procedure TForm1.tempFormClose(Sender: TObject; var Action: TCloseAction);
- begin
- action:=caFree;
- end;
-
- procedure TForm1.btndbConnectClick(Sender: TObject);
- var OdiaDB:TopenDialog;
- begin
- with tform.create(application) do
- begin
- formstyle:=fsMDIChild;
- onClose:=TempFormClose;
- caption:='Database';
- left:=0;
- top:=0;
- width:=300;
- height:=100;
- name:='FrmdbConnect';
- end;
- with Tedit.Create(self) do
- begin
- parent:=ActiveMDIChild;
- Width:=250;
- name:='edtDBName';
- text:='';
- end;
- with Tbutton.create(self) do
- begin
- parent:=ActiveMDIChild;
- top:=30;
- Caption:='Connect';
- OnClick:=ConnectDB;
- end;
- OdiaDb:=Topendialog.create(self);
- with OdiaDB do
- begin
- DefaultExt:='gdb';
- OncanClose:=OdiaDBCanClose;
- Execute;
- end;
- OdiaDB.free;
-
- end;
-
- procedure TForm1.DisConnectDB(Sender: TObject);
- begin
- ibd.connected:=false;
- actDBConnect.Enabled:=true;
- actDBDisconnect.enabled:=false;
- actOpenSQLtext.enabled:=false;
- actRunSQl.Enabled:=false;
- actTables.enabled:=false;
- resultview1.Enabled:=false;
- btnSQLoutBrowse.Enabled:=false;
- btnExcel.enabled:=false;
- btnSQLoutcsv.Enabled:=false;
- btnSQLoutText.Enabled:=false;
- statusbar1.Panels[1].Text:='';
- CloseAllChildForm;
- memoSQLstr.Lines.text:='';
- end;
-
- procedure TForm1.ConnectDB(Sender: TObject);
- begin
- if ibd.Connected then
- Disconnectdb(sender);
- if (sender is Tbutton) then
- ibd.databasename:=(findcomponent('edtDBName') as Tedit).text;
- if (sender is Tmenuitem) then
- ibd.databasename:=(sender as tmenuitem).caption;
- try
- ibd.Connected:=true;
- ibt.Active:=true;
- statusbar1.Panels[1].text:=ibd.databasename;
-
- actDBDisconnect.enabled:=true;
- actOpenSQLtext.enabled:=true;
- actTables.enabled:=true;
-
- resultview1.Enabled:=true;
- btnSQLoutBrowse.Enabled:=true;
- btnExcel.enabled:=true;
- btnSQLoutcsv.Enabled:=true;
- btnSQLoutText.Enabled:=true;
- actDBConnect.Enabled:=false;
- popItemAdd(ibd.databasename);
-
- except
- showmessage('Connect unsuccessful');
- statusbar1.Panels[1].text:='';
- end;
- if (sender is Tbutton) then
- ActiveMDIChild.close;
- end;
-
- procedure TForm1.ODiaDBCanClose(Sender: TObject; var CanClose: Boolean);
- begin
- if (sender as TopenDialog).defaultext='gdb' then
- (findcomponent('edtDBName') as Tedit).text:=(sender as TopenDialog).FileName;
- if (sender as TopenDialog).defaultext='sql' then
- memoSQlstr.Lines.LoadFromFile((sender as Topendialog).FileName);
- end;
-
- procedure tform1.popItemAdd(vdbname:string);
- var vi:integer;
- begin
- for vi:=0 to popdbconnect.Items.Count-1 do
- begin
- if vdbname= popdbconnect.items[vi].Caption then
- begin
- vdbname:='';
- break;
- end;
- end;
- if vdbname<>'' then
- popdbconnect.Items.Add(NewItem(vdbname,TextToShortCut('') ,False, True, connectdb, 0, 'mi_db'+inttostr(popdbconnect.Items.Count)) );
- end;
-
- procedure tform1.popsqlitemekle(vsqlname:string);
- var vi:integer;
- begin
- for vi:=0 to popsql.Items.Count-1 do
- begin
- if vsqlname= popsql.items[vi].Caption then
- begin
- vsqlname:='';
- break;
- end;
- end;
- if vsqlname<>'' then
- popsql.Items.Add(NewItem(vsqlname,TextToShortCut('') ,False, True, btngetsqltextclick, 0, 'mi_sql'+inttostr(popsql.Items.Count)) );
- end;
-
- procedure TForm1.btngetsqltextClick(Sender: TObject);
- var OdiaDB:TopenDialog;
- begin
-
- if (sender is Tmenuitem) and (copy((sender as Tmenuitem).name,1,2)='mi') then
- begin
- memoSqlstr.Lines.LoadFromFile((sender as tmenuitem).caption);
- end
- else
- begin
- OdiaDb:=Topendialog.create(self);
- with OdiaDB do
- begin
- DefaultExt:='sql';
- FileName:='';
- OncanClose:=OdiaDBCanClose;
- Execute;
- end;
- OdiaDB.free;
- end;
- end;
-
- procedure TForm1.btnsqltextsaveClick(Sender: TObject);
- var SaveDia:TSaveDialog;
- begin
- with tform.create(application) do
- begin
- formstyle:=fsMDIChild;
- onClose:=TempFormClose;
- caption:='Save SQL Text';
- left:=0;
- top:=0;
- width:=300;
- height:=100;
- name:='Frmsavesqltext';
- end;
- with Tedit.Create(self) do
- begin
- parent:=ActiveMDIChild;
- Width:=250;
- name:='edtsqltextfilename';
- text:='';
- end;
- with Tbutton.create(self) do
- begin
- parent:=ActiveMDIChild;
- top:=30;
- Caption:='Save';
- NAME:='btnsqlsave';
- OnClick:=SaveSQLText;
- end;
- SaveDia:=TSaveDialog.create(self);
-
- if SAVEdia.Execute then
- begin
- (findcomponent('edtsqltextfilename') as Tedit).text:=savedia.FileName;
- (findcomponent('btnsqlsave') as Tbutton).click;
- end;
- saveDia.free;
- end;
-
- procedure TForm1.SaveSqltext(Sender: TObject);
- begin
- try
- memoSQLstr.Lines.SaveToFile((findcomponent('edtsqltextfilename') as tedit).text);
- ActiveMDIChild.Close;
- popsqlitemekle((findcomponent('edtsqltextfilename') as tedit).text);
- except
-
- end;
- end;
- procedure Tform1.RieOutRenk(vrie:TrichEdit;v_color:Tcolor);
- begin
- vrie.SelStart:=vrie.GetTextLen;
- vrie.SelAttributes.color:=v_Color;
- end;
-
- procedure TForm1.Browse1Click(Sender: TObject);
- begin
- btnSQLoutBrowse.down:=true;
- end;
-
- procedure TForm1.Report1Click(Sender: TObject);
- begin
- btnSQLoutText.down:=true;
-
- end;
-
- procedure TForm1.AsciTextCSV1Click(Sender: TObject);
- begin
- btnSQLoutCSV.down:=true;
-
- end;
-
- procedure TForm1.actExitExecute(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TForm1.MemoSQLstrChange(Sender: TObject);
- begin
-
- if trim(memoSqlstr.text)='' then
- actRunSQl.Enabled:=false
- else
- actRunSQl.Enabled:=true;
-
- end;
-
- procedure TForm1.PopJoinTypeClick(Sender: TObject);
- begin
- if (sender is tmenUitem) then
- begin
- DARR:=vRlist.Items[vselecteditem];
- DARR^.JT:=(sender as tmenuitem).name;
- sqlStringReCreate(sender);
- end;
- end;
-
- procedure TForm1.SaveResult1Click(Sender: TObject);
- var SaveDia:TsaveDialog;
- begin
-
- if (FindComponent('rie_'+activeMdichild.name)<>nil) then
- begin
- SaveDia:=TSaveDialog.create(self);
- if savedia.Execute then
- begin
- (FindComponent('rie_'+activeMdichild.name) as TrichEdit).lines.savetoFile(savedia.filename);
- end;
- SaveDia.free;
- end;
- end;
-
- procedure TForm1.DBGridColEnter(Sender: TObject);
- begin
-
- if (FindComponent('dbIma_'+activeMdiChild.name)) <> nil then
- begin
- (FindComponent('dbIma_'+activeMdiChild.name)).free;
- end;
-
- if ((sender as tdbgrid).selectedfield.DataType=ftBlob) or ((sender as tdbgrid).selectedfield.DataType=ftmemo) then
- begin
- if FindComponent('dbIma_'+activeMdiChild.name) = nil then
- begin
- if ((sender as tdbgrid).selectedfield.DataType=ftBlob) then
- begin
- with tdbImage.create(self) do
- begin
- parent := activeMdiChild;
- name:='dbIma_'+activeMdiChild.name;
- align:=albottom;
- datasource:=(sender as tdbgrid).DataSource ;
- Datafield:=trim((sender as tdbgrid).selectedfield.DisplayName);
- Stretch:=true;
- end;
- end
- else
- begin
- with tdbmemo.create(self) do
- begin
- parent := activeMdiChild;
- name:='dbIma_'+activeMdiChild.name;
- align:=albottom;
- datasource:=(sender as tdbgrid).DataSource ;
- Datafield:=trim((sender as tdbgrid).selectedfield.DisplayName);
- end;
- end ;
-
- end;
- end
- else
- begin
- if (FindComponent('dbIma_'+activeMdiChild.name)) <> nil then
- begin
- (FindComponent('dbIma_'+activeMdiChild.name)).free;
- end;
- end;
-
- end;
-
-
-
- procedure TForm1.SendtoExcel1Click(Sender: TObject);
- begin
- btnExcel.Down:=true;
- end;
-
-
- procedure TForm1.SendToExcel(v_Dset:Tdataset);
- var WorkBk : _WorkBook; // Define a WorkBook
- WorkSheet : _WorkSheet; // Define a WorkSheet
- I, J, R, C : Integer;
- IIndex : OleVariant;
- TabGrid : Variant;
- vSg:TstringGrid;
- xlApp:TExcelApplication;
- begin
-
- xlApp:=TexcelApplication.create(self);
- xlApp.ConnectKind:= ckNewInstance;
- vsg:=TstringGrid.Create(self);
-
- v_dset.Last;
- with vsg do
- begin
- FixedCols:=0;
- FixedRows:=0;
- RowCount:=v_dset.RecordCount+1;
- ColCount:=v_dset.FieldCount;
- end; //with vsg do
- //Column labels
-
- For i:=0 to v_dset.FieldCount-1 do
- begin
- vsg.Cells[i,0]:=v_dset.Fields[i].DisplayName;
- end;
- //data
- v_dset.First;
- r:=1;
- While not v_dset.Eof do
- begin
- For i:=0 to v_dset.FieldCount-1 do
- begin
- if v_dset.Fields[i].IsBlob then
- vsg.Cells[i,r]:=v_dset.Fields[i].AsString
- else
- vsg.Cells[i,r]:=v_dset.Fields[i].AsString;
-
- end;
- r:=r+1;
- v_dset.Next;
- end;
- r:=0;
-
- if vsg.Cells[0,1] <> '' then
- begin
- IIndex := 1;
- R := vsg.RowCount;
- C := vsg.ColCount;
- // Create the Variant Array
- TabGrid := VarArrayCreate([0,(R - 1),0,(C - 1)],VarOleStr);
- I := 0;
- // Define the loop for filling in the Variant
- repeat
- for J := 0 to (C - 1) do
- TabGrid[I,J] := vsg.Cells[J,I];
- Inc(I,1);
- until
- I > (R - 1);
- try
- // Connect to the server TExcelApplication
- XLApp.Connect;
- // Add WorkBooks to the ExcelApplication
- XLApp.WorkBooks.Add(xlWBatWorkSheet,0);
- // Select the first WorkBook
- WorkBk := XLApp.WorkBooks.Item[IIndex];
- // Define the first WorkSheet
- WorkSheet := WorkBk.WorkSheets.Get_Item(1) as _WorkSheet;
- // Assign the Delphi Variant Matrix to the Variant associated with the WorkSheet
- Worksheet.Range['A1',Worksheet.Cells.Item[R,C]].Value := TabGrid;
- // Quit and Disconnect the Server
- XLApp.Quit;
- XLApp.Disconnect;
- showmessage(inttostr(v_dset.RecordCount)+' Records Send to Excel') ;
- except
- end;
- // Unassign the Delphi Variant Matrix
- TabGrid := Unassigned;
- end;
-
- vsg.free;
- vsg:=nil;
- xlApp.free;
- xlApp:=nil;
- end;
-
-
-
- end.
-