Advertisement
DmitriyKim

oracle console

Jun 22nd, 2016
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 76.96 KB | None | 0 0
  1. unit Unit2;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, Grids, DBGrids, debuge, DB, ADODB, ExtCtrls, GridsEh, DBGridEh,
  8.   DGRiOP, variants , dbctrls,  DBTables, types, Provider,comctrls, dblookupeh,
  9.   DBClient,menus,ActiveX, actnlist,  inifiles,math, Mask,
  10.   dbgridehimpexp,  DBCtrlsEh,comobj, ImgList, shellapi,popum,zbutton;
  11.  
  12.                                        
  13. const
  14.    TRMSG = WM_USER+5000;
  15.  
  16.    FL_LDIR = 'c:\tmpbk';
  17.    FL_BK = 'c:\tmpbk\bk.log';
  18.    FL_SYS = 'c:\tmpbk\sys.log';
  19.  
  20. type
  21.   prgbarray=^trgbarray;
  22.   trgbarray=array[0..1] of trgbtriple;
  23.  
  24.   trefr=class;
  25.   tbkt=class;
  26.  
  27.    tvob=class(tobject)
  28.    public
  29.       filpath:string;
  30.       isfil:integer;
  31.    end;
  32.  
  33.    ftgre= record
  34.       num:string;
  35.       servnam:string;
  36.       login:string;
  37.       pass:string;
  38.       coname:string;
  39.    end;
  40.    tftgarr=array of ftgre;
  41.  
  42.    tform2 = class;
  43.  
  44.    tdlo=class(tdblookupcomboboxeh)
  45.    protected
  46.       procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  47.       X, Y: Integer);override;
  48.    end;
  49.  
  50.    tcofi = class
  51.       private
  52.          mast:tform2;
  53.          qu:tadoquery;
  54.          ds:tdatasource;
  55.          co:tdlo;
  56.          bu:tdebuge;
  57.          //----------------------
  58.          gri:tdbgridop;
  59.          adc:tadoconnection;
  60.          ncol:integer;
  61.          isact:boolean;
  62.  
  63.       public
  64.          procedure inico(incol:integer);
  65.          procedure upfipo;
  66.          constructor create(inadc:tadoconnection;ingri:tdbgridop;
  67.          inbu:tdebuge; inmast:tform2);
  68.          destructor destroy;
  69.    end;
  70.  
  71.    thagro=class(tradiogroup)
  72.    private
  73.       procedure WMa(var msg:twmmouseactivate);message WM_MOUSEACTIVATE;
  74.    public
  75.       inmodo:procedure of object;
  76.    published
  77.       property caption;
  78.       property onmousedown; //ftg
  79.    end;
  80.  
  81.   thagrid=class(tdbgridop);
  82.  
  83.   //---------------------------------popup bk thread win
  84.   {thlfo=class(tform)
  85.   private
  86.      procedure drawme;
  87.      procedure WMPaint(var msg:TWMPaint); message WM_PAINT;
  88.   public
  89.      txtout:array of string;
  90.   end;}
  91.  
  92.   TForm2 = class(TForm)
  93.     DataSource1: TDataSource;
  94.     Button2: TButton;
  95.     ADOConnection1: TADOConnection;
  96.     ADOQuery1: TADOQuery;
  97.     Panel2: TPanel;
  98.     Panel3: TPanel;
  99.     Splitter1: TSplitter;
  100.     Panel4: TPanel;
  101.     Splitter2: TSplitter;
  102.     Panel1: TPanel;
  103.     bu: tdebuge;
  104.     RxDBGrid1: TDBGridOP;
  105.     Panel5: TPanel;
  106.     Memo1: TMemo;
  107.     il: TImageList;
  108.     ADOQuery2: TADOQuery;
  109.  
  110.     procedure RxDBGrid1HScro(rez_val: Integer);
  111.     procedure RxDBGrid1ColWidthsChanged(Sender: TObject);
  112.     procedure FormResize(Sender: TObject);
  113.  
  114.     //-----------------
  115.     procedure WndProc(var msg:tmessage);override;
  116.  
  117.     procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
  118.       Shift: TShiftState; X, Y: Integer);
  119.     procedure ADOQuery1BeforeClose(DataSet: TDataSet);
  120.     procedure FormCreate(Sender: TObject);
  121.     procedure FormShow(Sender: TObject);
  122.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  123.     procedure Button1Click(Sender: TObject);
  124.     procedure Button2Click(Sender: TObject);
  125.     procedure RxDBGrid1DblClick(Sender: TObject);
  126.    
  127.   private
  128.     fkarr:array of integer;
  129.     colresize:boolean;
  130.     refrall:boolean;
  131.     refr:trefr;
  132.     bkt:tbkt;                                  
  133.     hbkt:cardinal;
  134.     grih:hwnd;
  135.     oldwpro:pointer;
  136.     newwpro:pointer;
  137.     lokpli:tlist;
  138.  
  139.     lock_upd:boolean;
  140.  
  141.     wmsgstr,statusstr{,dopstr}:string;
  142.     ismaz:boolean;
  143.  
  144.     deltax,deltay:integer;
  145.  
  146.     refmode:boolean;
  147.  
  148.     function dtype(f:tfield):integer;
  149.  
  150.     procedure fkcolupd;
  151.     procedure replgrwinpro;
  152.     procedure newwndpro(var msg:tmessage);//ftg
  153.     //procedure cloneme;
  154.     procedure fpai(var msg:twmncpaint);message WM_NCPAINT;
  155.     //procedure chi(var msg:twmmouseactivate{ftg});message WM_MOUSEACTIVATE;
  156.     procedure chi(var msg:twmncrbuttondown);message WM_NCRBUTTONDOWN;
  157.     //WM_NCHITTEST
  158.   public
  159.     is_upd:boolean;
  160.     is_inter:boolean;
  161.     tmp_owner:string;
  162.     tmp_data:TADOQuery;
  163.     cnt_a:integer;
  164.     in_server:string;
  165.     in_comms:string;
  166.     tmpfname:string;
  167.     //------------------------------
  168.     tmp_baseq:string;
  169.     tmp_filst:string;
  170.     tmp_sortli:string;
  171.     glocol:tcolumneh;
  172.     //------------------------------
  173.     gl_ragro:thagro;
  174.     gl_lv:tlistview;
  175.     ftgarr:tftgarr; //FTG
  176.  
  177.     pom,pom4,pom6:tpopupmenu;
  178.     pom5,pom9,pom8:tpopum;
  179.     zbu:tzbutton;
  180.     //tpa:tpanel;
  181.     liob:tlist;
  182.  
  183.     curzapfile:string;
  184.     gtv:ttreeview;
  185.  
  186.     procedure defaulthandler(var message);override;
  187.     function noad(instr:string):string;
  188.     function adno(instr:string; goo:boolean):string;
  189.     function noad9(instr:string):string;
  190.     procedure mkradgro;
  191.     procedure mkzapgri;
  192.     procedure mkutree;
  193.     procedure mkrg;
  194.     procedure termrefr;
  195.  
  196.     procedure grchcli(sender:tobject);
  197.     procedure grdrova(sender,source:tobject;x,y:integer;state:tdragstate;
  198.     var accept:boolean);
  199.     procedure grdrop(sender,source:tobject;x,y:integer);
  200.     procedure tvdrop(sender,source:tobject;x,y:integer);
  201.     procedure grmodon(sender:tobject; var dragobject:tdragobject);
  202.  
  203.     procedure spli(pare:twincontrol);
  204.     function  pane(innam:string;ha:integer;ali:talign;pare:twincontrol):tpanel;
  205.     function arrchecks:tlist;
  206.     procedure redrtree;
  207.  
  208.     procedure execomm(incom:string);
  209.     procedure shopo9;
  210.  
  211.   published
  212.      procedure closup(Sender: TObject; Accept: Boolean);
  213.      procedure cmbcle(sender: tobject);
  214.      procedure cmbbdo(sender:tobject;topbutton:boolean;
  215.      var autorepeat:boolean; var handled:boolean);
  216.  
  217.      //--------------------
  218.      procedure dropdon(Sender: TObject);
  219.  
  220.      //---------------------------
  221.      procedure refredata;
  222.      procedure ftgrgproc(sender:tobject);
  223.      procedure modo(isedit:boolean);
  224.      procedure bktterm(sender:tobject);
  225.      procedure updfilters;
  226.      //----------------------------
  227.      procedure chaque;
  228.      procedure gricop4excel;
  229.      procedure menucli(sender:tobject);
  230.      function memofo(var inst:string):integer;
  231.  
  232.      procedure rgmmove(sender:tobject;shift:tshiftstate;x,y:integer);
  233.  
  234.      procedure menuou(sender:tobject;acol:integer;column:tcolumneh);
  235.      procedure updstate(sender:tobject);
  236.      procedure onlvcli(sender:tobject);
  237.      procedure lvmodon(sender:tobject;button:tmousebutton;
  238.      shift:tshiftstate;x,y:integer);
  239.      procedure tvmodon(sender:tobject;button:tmousebutton;
  240.      shift:tshiftstate;x,y:integer);
  241.  
  242.      procedure refmodcha(sender:tobject);
  243.      //-----------------------------------------
  244.      procedure tvonkli(sender:tobject);
  245.   end;
  246.                  
  247.   //----------------------------------
  248.   trefr=class(tthread)
  249.   private
  250.      mymast:tform;
  251.   protected
  252.      sync_exec:tmethod;
  253.      procedure Execute;override;
  254.   public
  255.      
  256.      constructor create(createsuspended:boolean;mast:tform);
  257.   end;
  258.  
  259.   //------------------------------------
  260.   tbkt=class(tthread)
  261.   private
  262.      mymast:tform;
  263.      {function processmsg(msg:tmsg):boolean;
  264.      procedure processmsgs;  }
  265.  
  266.   protected
  267.      bk_term:tmethod;
  268.      procedure execute;override;
  269.   public
  270.      //hlo:thlfo;
  271.      hlo,hlo9:twndclass;
  272.      hloh,hl9:hwnd;
  273.      z_counter:integer;
  274.      constructor create(createsuspended:boolean;mast:tform);
  275.   end;
  276.  
  277.   //------------------------------------------------------------
  278.   //------------------------------------------------------------
  279.  
  280. var
  281.   Form2: TForm2;
  282.   txtout:array of string;
  283.   debu:tmemorystream;
  284.   crise:trtlcriticalsection;
  285.   inb,inb9:graphics.tbitmap;
  286.   grib:graphics.tbitmap;
  287.   KICKM:integer;
  288.   rndcol:tcolor;
  289.   ibfkcode:boolean;
  290.  
  291. //---------------------------------------------------
  292. implementation
  293.  
  294. uses asfo, Unit1;
  295.  
  296. //{$R menus.rc}
  297. {$R *.DFM}
  298.  
  299.  
  300. procedure tdlo.MouseDown(Button: TMouseButton; Shift: TShiftState;
  301. X, Y: Integer);
  302. begin
  303. //
  304. end;
  305.  
  306. //-------------------------------------------------------
  307. constructor tcofi.create(inadc:tadoconnection;ingri:tdbgridop;
  308. inbu:tdebuge;inmast:tform2);
  309. begin
  310.    inherited create;
  311.  
  312.    mast:=inmast;
  313.    adc:=inadc;
  314.    gri:=ingri;
  315.    isact:=false;
  316.    bu:=inbu;
  317.    qu:=tadoquery.Create(nil);
  318.    qu.Connection:=adc;
  319.    ds:=tdatasource.Create(nil);
  320.    ds.DataSet:=qu;
  321.  
  322.    co:=tdlo.Create(nil);
  323.    co.Parent:=gri;
  324.    co.Top:=1;
  325.    co.Visible:=false;
  326.    co.ListSource:=ds;
  327.    co.DropDownbox.rows:=30;
  328.    co.DropDownbox.Sizable:=true;
  329.    co.DropDownBox.Width:=300;
  330.    co.OnDropDown:=mast.dropdon;
  331.    co.OnCloseUp:=mast.closup;
  332.    co.OnClick:=mast.cmbcle;
  333.    co.OnButtondown:=mast.cmbbdo;
  334.    co.Tag:=5;
  335.  
  336. end;
  337. destructor tcofi.destroy;
  338. begin
  339.    qu.Close;
  340.    co.Free;
  341.    ds.Free;
  342.    qu.Free;
  343.  
  344.    inherited destroy;
  345. end;
  346. //----------------------------------------init filter
  347. procedure tcofi.inico(incol:integer);
  348. var
  349.    s1:string;
  350. begin
  351.    if gri.Columns.Count-1<incol then
  352.       exit;
  353.    //endif
  354.    s1:=gri.Columns[incol].FieldName;
  355.    {qu.SQL.text:='select '+s1+' from ('+tmp_baseq+') '+
  356.    ' group by '+s1+' order by 1';}
  357.    if s1<>co.KeyField then
  358.       qu.close;
  359.    //endif
  360.  
  361.    co.ListField:=s1;
  362.    co.KeyField:=s1;
  363.    ncol:=incol;
  364.    //qu.open;
  365.    isact:=true;
  366.    upfipo;
  367.  
  368.    co.Visible:=true;
  369. end;
  370. //-----------------------------update filter position
  371. procedure tcofi.upfipo;
  372. var
  373.   di:tgriddrawinfoeh;
  374.   lcol,i,lpos:integer;
  375.  
  376.  
  377. begin
  378.    //exit;
  379.    if not(isact) then
  380.       exit;
  381.    //endif
  382.  
  383.    gri.OCalcDrawInfo(di);
  384.    lcol:=di.Horz.FirstGridCell;
  385.    {bu.wrln('-----------');
  386.    bu.wrln(lcol);
  387.    bu.wrln(ncol);
  388.    bu.wrln(gri.Columns.count);  }
  389.  
  390.    if ((ncol+1)<lcol) then
  391.       begin
  392.          co.Visible:=false;
  393.          exit;
  394.       end
  395.    else
  396.       if gri.Columns.Count<(ncol+1) then
  397.          begin
  398.             co.Visible:=false;
  399.             exit;
  400.          end
  401.       else
  402.          if (gri.columns[ncol].width<20) then
  403.             begin
  404.                co.Visible:=false;
  405.                exit;
  406.             end
  407.          else
  408.             co.Visible:=true;
  409.          //endif
  410.       //endif
  411.    //endif
  412.  
  413.    lpos:=15;
  414.    for i:=lcol-1 to ncol-1 do
  415.       lpos:=lpos+gri.Columns[i].Width+1;
  416.    //endfor
  417.    co.Left:=lpos+1;
  418.    co.Width:=gri.Columns[ncol].Width-6;
  419.  
  420. end;
  421.  
  422.  
  423.  
  424. //-------------------------------------------------------
  425. procedure thagro.WMa(var msg:twmmouseactivate);
  426.  
  427. function bitst(inva:integer):string;
  428. function h(inv:integer):string;
  429. begin
  430.    if inv=0 then
  431.       result:='+'
  432.    else
  433.       result:='I';
  434.    //endif
  435. end;
  436. begin
  437.  
  438.    result:=h(inva and 128)+h(inva and 64)+h(inva and 32)+
  439.    h(inva and 16)+h(inva and 8)+h(inva and 4)+h(inva and 2)+
  440.    h(inva and 1);
  441.  
  442.    inva:=(inva shr 8);
  443.    result:=h(inva and 128)+h(inva and 64)+h(inva and 32)+
  444.    h(inva and 16)+h(inva and 8)+h(inva and 4)+h(inva and 2)+
  445.    h(inva and 1)+result;
  446. end;
  447.  
  448. begin
  449.    caption:= bitst(msg.MouseMsg);
  450.    if msg.MouseMsg=516 then
  451.       begin
  452.          if assigned(inmodo) then
  453.             inmodo
  454.          //enif
  455.       end
  456.    else
  457.       if msg.MouseMsg=519 then
  458.          begin
  459.             {deletefile(extractfilepath(application.ExeName)+'\ftg.ini');
  460.             form2.mkradgro;         }
  461.          end;
  462.       inherited;
  463.    //endif
  464.  
  465.    
  466. end;
  467.  
  468. //---------------------------------------------------
  469. constructor trefr.create(createsuspended:boolean;mast:tform);
  470. begin
  471.    inherited create(true);
  472.    mymast:=mast;
  473.    with sync_exec do
  474.       begin
  475.          data:=mymast;
  476.          code:=mymast.ClassType.MethodAddress('refredata');
  477.       end;
  478.    //endwith
  479.    if not(createsuspended) then
  480.       resume;
  481.    //endif
  482. end;
  483.  
  484. //---------------------------------------------------
  485. procedure trefr.Execute;
  486. begin
  487.    while not(terminated) do
  488.       begin
  489.          synchronize(tthreadmethod(sync_exec));
  490.          sleep(500);
  491.       end;
  492.    //wend
  493. end;
  494.  
  495. //-------------------------------------------Win Proc
  496. function windowproc(inhw:hwnd; msge, wparam:word;
  497. lparam:longint): longint;stdcall;
  498. //-----------------------------------
  499. procedure drawme;
  500. var
  501.    i:integer;
  502.    curect:trect;
  503.    indc:hdc;
  504.    //ps:tpaintstruct;
  505.  
  506. begin
  507.    getwindowrect(inhw,curect);
  508.    inb.Width:=curect.Right-curect.left;
  509.    inb.Height:=curect.Bottom-curect.top;
  510.    with inb.Canvas do
  511.       begin
  512.          font.Size:=8;
  513.          font.Name:='lucida console';
  514.          font.color:=clwhite;
  515.          font.Style:=[fsbold];
  516.          brush.Style:=bssolid;
  517.          brush.Color:=rgb(0,0,40);
  518.          fillrect(cliprect);
  519.  
  520.          brush.Style:=bsclear;
  521.          for i:=0 to min(0,length(txtout)-1) do
  522.             begin
  523.                textout(10,6+15*i,txtout[i]);
  524.             end;
  525.          //endfor
  526.       end;
  527.    //endwith
  528.  
  529.    indc:=getwindowdc(inhw);
  530.    bitblt(indc,0,0,inb.Width,inb.Height,inb.Canvas.Handle,0,0,srccopy);
  531.    releasedc(inhw,indc);
  532.  
  533. end;
  534.  
  535. //-----------------------------------------
  536. begin
  537.    //windowproc:=0;
  538.    case msge of
  539.    //wm_erasebkgnd, wm_vscroll:
  540.       //invagri;
  541.  
  542.    wm_hscroll:
  543.       begin
  544.          //invagri;
  545.          invalidaterect(inhw,nil,true);
  546.       end;
  547.  
  548.    wm_paint:
  549.       begin
  550.          //log_msg(' winproc got wm_paint');
  551.          drawme;
  552.       end;
  553.    wm_rbuttondown:
  554.       begin
  555.          sendmessage(HWND_BROADCAST,KICKM,0,0);
  556.       end;
  557.  
  558.    wm_destroy:
  559.       begin
  560.          //log_msg('_____________GOT WM_DESTROY');
  561.       end;
  562.    end;
  563.  
  564.    windowproc:=defwindowproc(inhw,msge,wparam,lparam);
  565. end;
  566.  
  567. //-----------------------------------Win Proc for popup wins
  568. function windowproc9(inhw:hwnd; msge, wparam:word;
  569. lparam:longint): longint;stdcall;
  570. //-----------------------------------
  571. procedure drawme9;
  572. var
  573.    i:integer;
  574.    curect:trect;
  575.    indc9:hdc;
  576.    //ps:tpaintstruct;
  577.  
  578. begin
  579.    getwindowrect(inhw,curect);
  580.    inb9.Width:=curect.Right-curect.left;
  581.    inb9.Height:=curect.Bottom-curect.top;
  582.    with inb9.Canvas do
  583.       begin
  584.          font.Size:=8;
  585.          font.Name:='lucida console';
  586.          font.color:=clwhite;
  587.          font.Style:=[fsbold];
  588.          brush.Style:=bssolid;
  589.          brush.Color:=rndcol;
  590.          fillrect(cliprect);
  591.  
  592.          brush.Style:=bsclear;
  593.          for i:=0 to min(0,length(txtout)-1) do
  594.             begin
  595.                textout(10,6+15*i,txtout[i]);
  596.             end;
  597.          //endfor
  598.       end;
  599.    //endwith
  600.  
  601.    indc9:=getwindowdc(inhw);
  602.    bitblt(indc9,0,0,inb9.Width,inb9.Height,inb9.Canvas.Handle,0,0,srccopy);
  603.    releasedc(inhw,indc9);
  604.  
  605. end;
  606.  
  607. //-----------------------------------------
  608. begin
  609.    case msge of
  610.    wm_hscroll:
  611.       begin
  612.          invalidaterect(inhw,nil,true);
  613.       end;
  614.    wm_paint:
  615.       begin
  616.          drawme9;
  617.       end;
  618.    end;
  619.    windowproc9:=defwindowproc(inhw,msge,wparam,lparam);
  620. end;
  621.  
  622. //---------------------------------------------------
  623. constructor tbkt.create(createsuspended:boolean;mast:tform);
  624.  
  625. begin
  626.    inherited create(true);
  627.    z_counter:=0;
  628.    mymast:=mast;
  629.    with bk_term do
  630.       begin
  631.          data:=mymast;
  632.          code:=mymast.classtype.MethodAddress('bktterm');
  633.       end;
  634.    //endwith
  635.    onterminate:=TNotifyEvent(bk_term);
  636.  
  637.    with hlo do
  638.       begin
  639.          style:=cs_hredraw or cs_vredraw;
  640.          lpfnwndproc:=@windowproc;
  641.          cbclsextra:=0;
  642.          cbwndextra:=0;
  643.          hinstance:=0;
  644.          hicon:=loadicon(0,IDI_APPLICATION);
  645.          hcursor:=loadcursor(0,IDC_ARROW);
  646.          lpszclassname:='AsInfo';
  647.       end;
  648.    //endwith
  649.    with hlo9 do
  650.       begin
  651.          style:=cs_hredraw or cs_vredraw;
  652.          lpfnwndproc:=@windowproc9;
  653.          cbclsextra:=0;
  654.          cbwndextra:=0;
  655.          hinstance:=0;
  656.          hicon:=loadicon(0,IDI_APPLICATION);
  657.          hcursor:=loadcursor(0,IDC_ARROW);
  658.          lpszclassname:='AsZInfo';
  659.       end;
  660.    //endwith
  661.  
  662.    windows.registerclass(hlo);
  663.    windows.registerclass(hlo9);
  664.    //hloh:=createwindowEX(WS_EX_TOPMOST,'AsInfo','AsInfo',
  665.    //WS_POPUPWINDOW
  666.    //,50,300,150,40,0{hwnd_desktop},0,hinstance,nil);
  667.  
  668.    {hloh:=createwindowEX(WS_EX_TOPMOST,'AsInfo','AsInfo',
  669.    WS_POPUPWINDOW  
  670.    ,400,screen.Height-20,
  671.    200,20,0{hwnd_desktop,0,hinstance,nil);  }
  672.  
  673.    hloh:=createwindowEX(0{WS_EX_TOPMOST},'AsInfo','AsInfo',
  674.    WS_POPUPWINDOW  
  675.    ,0,0,
  676.    200,20,mymast.handle{hwnd_desktop},0,hinstance,nil);
  677.  
  678.    {setwindowlong(hloh, GWL_EXSTYLE,
  679.    getwindowlong(hloh,GWL_EXSTYLE) or WS_EX_LAYERED);
  680.    setlayeredwindowattributes(hloh,0,200,LWA_ALPHA);   }
  681.  
  682.    showwindow(hloh,SW_SHOWNORMAL);
  683.    updatewindow(hloh); // sends WM_PAINT
  684.  
  685.    if not(createsuspended) then
  686.       resume;
  687.    //endif
  688.  
  689. end;
  690.  
  691.  
  692. //----------------------------------------------------
  693. procedure tbkt.Execute;
  694. var
  695.   tp:tzbutton;
  696.   r:trect;
  697.   rp:prect;
  698.   {drifo:tgriddrawinfoeh;
  699.   inmsg:tagmsg;
  700.   tmprow:longint;
  701.   curect:trect;     }
  702.   prevss:string;
  703.  
  704. //------------------------------------------------
  705. procedure set_pars;
  706. var
  707.    excapp,wb,ws:variant;
  708.  
  709. begin
  710.    with (mymast as tform2) do
  711.       begin
  712.          if length(txtout)<1 then
  713.             begin
  714.                setlength(txtout,3);
  715.                txtout[0]:='';
  716.                txtout[1]:='';
  717.                txtout[2]:='';
  718.             end;
  719.          //endif
  720.          txtout[0]:='tm:'+formatdatetime('hh:mm:ss.zzz',time);
  721.          {if (txtout[1]<>statusstr) and (z_counter=0) then
  722.             begin
  723.                txtout[1]:=statusstr;
  724.                z_counter:=100;
  725.                randomize;
  726.                rndcol:=rgb(random(200),random(200),random(200));  }
  727.                {hl9:=createwindowEX(0,'AsZInfo','AszInfo',
  728.                WS_POPUPWINDOW,random(500),random(500),400,50,0,0,hinstance,nil);}
  729.                //hl9:=createwindow('AsZInfo','zinfo',WS_BORDER,
  730.                //random(500),random(500),400,50,0,0,hinstance,nil);
  731.  
  732.                {setwindowlong(hl9, GWL_EXSTYLE,
  733.                getwindowlong(hl9,GWL_EXSTYLE) or WS_EX_LAYERED);
  734.                setlayeredwindowattributes(hl9,rndcol,128,LWA_ALPHA);   }
  735.                 //FTG
  736.               { showwindow(hl9,SW_SHOWNORMAL);
  737.                updatewindow(hl9); // sends WM_PAINT
  738.             end;        }
  739.          //enndif
  740.  
  741.          sendmessage(hloh,WM_PAINT,0,0);
  742.          if z_counter>0 then
  743.             sendmessage(hl9,WM_PAINT,0,0);
  744.          //endif
  745.          //updatewindow(hloh);
  746.          //hlo.drawme;
  747.          //getwindowrect(hloh,curect);
  748.          //invalidaterect(hloh,@curect,true);
  749.  
  750.          if statusstr='excel plz wait' then
  751.             begin
  752.               excapp:=comobj.createoleobject('Excel.Application');
  753.               excapp.visible:=false;
  754.               wb:=excapp.workbooks.add;
  755.               ws:=excapp.workbooks[1].worksheets[1];
  756.  
  757.               synchronize(gricop4excel);
  758.  
  759.               ws.paste;
  760.               excapp.visible:=true;
  761.               statusstr:='excel ok';
  762.             end;
  763.          //endif
  764.          {if (statusstr<>prevss) and (statusstr<>'')  then
  765.             begin
  766.                prevss:=statusstr;
  767.                pom9.cleara;
  768.                pom9.appitem(statusstr,1,nil);
  769.                pom9.popup(100,100);
  770.             end;
  771.          //endif     }
  772.       end;
  773.    //endwith
  774. end;
  775.  
  776. //------------------------------------------------
  777. begin
  778.    prevss:='';
  779.    //---------------------test wcy pro
  780.    while (true) do
  781.       begin
  782.          set_pars;
  783.          if terminated then
  784.             exit;
  785.          //endif
  786.          tp:=(mymast as tform2).zbu;
  787.          r:=rect(0,0,tp.Width-2,tp.Height-2);
  788.          rp:=@r;
  789.          (mymast as tform2).zbu.tick;
  790.          invalidaterect(tp.Handle,rp,false);
  791.          //sendmessage(tp.Handle,wm_paint,0,0);
  792.          sleep(10);
  793.       end;
  794.    //wend
  795. end;
  796.  
  797. //-----------------------------Terminate back thread
  798. procedure tform2.bktterm(sender:tobject);
  799. begin
  800.    //log_msg('______________START SENDING WM_DESTROY',true);
  801.    destroywindow(bkt.hloh);
  802.    //sendmessage(bkt.hloh, WM_DESTROY,0,0);
  803.    //postmessage(bkt.hloh, WM_DESTROY,0,0);
  804.    
  805.    //log_msg('______________FINISH SENDING WM_DESTROY',true);
  806.    freeandnil(debu);
  807.  
  808. end;
  809.  
  810. //---------------------------------get data type
  811. function tform2.dtype(f:tfield):integer;
  812. begin
  813.    if (f.datatype=ftstring) or
  814.       (f.datatype=ftWideString) or
  815.       (f.DataType=ftmemo) then
  816.       dtype:=0
  817.    else
  818.    if (f.DataType=ftSmallint) or
  819.       (f.DataType=ftLargeint) or
  820.       (f.DataType=ftInteger) or
  821.       (f.DataType=ftWord) or
  822.       (f.DataType=ftCurrency) or
  823.       (f.DataType=ftFloat) then
  824.       dtype:=1
  825.    else
  826.    if (f.DataType=ftDate) or
  827.       (f.DataType=ftDatetime) then
  828.       dtype:=2
  829.    else
  830.       dtype:=3;
  831.    //endif
  832.  
  833. end;
  834.  
  835. //-----------------------------------change refresh mode of grid
  836. procedure tform2.refmodcha(sender:tobject);
  837. begin
  838.    refmode:=not refmode;
  839.    if refmode then
  840.       begin
  841.         zbu.ButtonColor:=clred;
  842.         execomm('refr');
  843.       end
  844.    else
  845.       begin
  846.          zbu.ButtonColor:=clblue;
  847.          execomm('norefr');
  848.       end;
  849.    //endif
  850.  
  851.  
  852. end;
  853.  
  854. //-------------------------------------refresh dataset
  855. procedure tform2.refredata;
  856. var
  857.    curnu:integer;
  858.    grinfo:tgriddrawinfoeh;
  859.    tmprow, tmpcol,tmplcol:longint;
  860.  
  861.    allrows:integer;
  862.    refrow:integer;
  863.    //tmpstr:string;
  864.    step1:integer;
  865.    j:integer;
  866.  
  867. //-----------------------------------------
  868. procedure movet(var step:integer);
  869. var
  870.    i:integer;
  871.  
  872. begin
  873.    if step>=0 then
  874.       for i:=1 to step do
  875.          begin
  876.             adoquery1.Next;
  877.             if adoquery1.Eof then
  878.                begin
  879.                   step:=i;
  880.                   break;
  881.                end;
  882.             //endif
  883.          end
  884.       //endfor
  885.    else
  886.       for i:=1 to -step do
  887.          begin
  888.             adoquery1.Prior;
  889.             if adoquery1.Bof then
  890.                begin
  891.                   step:=i;
  892.                   break;
  893.                end;
  894.             //endif
  895.          end;
  896.       //endfor
  897.    //endif
  898. end;
  899. //-----------------------------------------
  900. begin
  901.    if lock_upd then
  902.       exit;
  903.    //endif
  904.    is_upd:=true;
  905.    //lockwindowupdate(rxdbgrid1.Handle);
  906.    sendmessage(rxdbgrid1.Handle, WM_SETREDRAW,0,0);
  907.  
  908.    //-----------------------------
  909.    rxdbgrid1.OCalcDrawInfo(grinfo);
  910.    allrows:=grinfo.Vert.GridCellCount;
  911.    refrow:=allrows div 2;
  912.    tmprow:=rxdbgrid1.Row;
  913.    tmpcol:=rxdbgrid1.Col;
  914.    tmplcol:=rxdbgrid1.LeftCol;
  915.    step1:=refrow-tmprow;
  916.    movet(step1);
  917.  
  918.    curnu:=adoquery1.Fields[0].asinteger;
  919.    try
  920.       adoquery1.Close;
  921.       adoquery1.Open;
  922.    except
  923.       on e:exception do
  924.       begin
  925.          statusstr:=e.Message;
  926.          is_upd:=false;
  927.          exit;
  928.       end;
  929.  
  930.    end;
  931.  
  932.  
  933.    fkcolupd;
  934.    try
  935.       adoquery1.Filter:='rownum='+inttostr(curnu);
  936.       adoquery1.FindFirst;
  937.    except
  938.       //log_msg('invbk '+bkm,true);
  939.    end;    
  940.      { end
  941.    else
  942.       begin
  943.          log_msg('-------------error bkm');
  944.       end;
  945.    //endif   }
  946.  
  947.    step1:=-step1;
  948.    movet(step1);
  949.    rxdbgrid1.Col:=tmpcol;
  950.    rxdbgrid1.LeftCol:=tmplcol;
  951.  
  952.  
  953.    //lockwindowupdate(0);
  954.  
  955.    {redrawwindow(rxdbgrid1.Handle,nil,0,
  956.    RDW_FRAME+RDW_INVALIDATE);}
  957.  
  958.  
  959.    sendmessage(rxdbgrid1.Handle, WM_SETREDRAW,1,0);
  960.    {redrawwindow(rxdbgrid1.Handle,nil,0,
  961.    RDW_FRAME+RDW_INVALIDATE);}
  962.    //sendmessage(rxdbgrid1.Handle, WM_PAINT,1,0);
  963.  
  964.    rxdbgrid1.invalidate;
  965.    for j:=0 to rxdbgrid1.ControlCount-1 do
  966.       begin
  967.          rxdbgrid1.Controls[j].Invalidate;
  968.       end;
  969.    //endfor
  970.    is_upd:=false;
  971.  
  972.  
  973. end;
  974.  
  975. //--------------------------terminate refresh thread
  976. procedure tform2.termrefr;
  977. begin
  978.    if assigned(refr) then
  979.       begin
  980.          with refr do
  981.             begin
  982.                terminate;
  983.                waitfor;
  984.             end;
  985.          //endwith
  986.          freeandnil(refr);
  987.       end;
  988.    //endif
  989. end;
  990.  
  991.  
  992.  
  993. //-------------------------ckose if on title click
  994. procedure tform2.chi(var msg:twmncrbuttondown);
  995. begin
  996.    {inherited;
  997.    bu.wrr('caption mouse test',20);
  998.    bu.wrln(inttostr(msg.HitTestCode));
  999.    bu.wrln(inttostr(msg.MouseMsg));
  1000.    if (msg.HitTestCode=HTCAPTION) and (msg.MouseMsg=516) then
  1001.       close;
  1002.    //endif   }
  1003.    close;
  1004.  
  1005. end;
  1006.  
  1007.  
  1008. //-----------------------------------border draw
  1009. procedure tform2.fpai(var msg:twmncpaint);
  1010. var
  1011.    dc:hdc;
  1012.    pen:hpen;
  1013.    op:hpen;
  1014.    ob:hbrush;
  1015.    i:integer;
  1016.  
  1017. function sob(inob:hgdiobj):hgdiobj;
  1018. begin
  1019.    result:=selectobject(dc,inob);
  1020. end;
  1021.  
  1022. begin
  1023.    dc:=getwindowdc(handle);
  1024.  
  1025.    msg.Result:=1;
  1026.    pen:=createpen(ps_solid,1,rgb(255,0,0));
  1027.    op:=sob(pen);
  1028.    ob:=sob(getstockobject(null_brush));
  1029.  
  1030.    randomize;
  1031.    for i:=1 to 2 do
  1032.       rectangle(dc,0,i,width,i+5);
  1033.    //endfor
  1034.  
  1035.  
  1036.    sob(op);
  1037.    sob(ob);
  1038.    deleteobject(pen);
  1039.    releasedc(handle, canvas.Handle);
  1040.  
  1041. end;
  1042.  
  1043. //--------------------override wnd proc form2
  1044. procedure tform2.WndProc(var msg:tmessage);
  1045.  
  1046. function r(inw:integer):string;
  1047. begin
  1048.    result:=inttostr(inw)+'-';
  1049. end;
  1050. function u(inw1{ftg}:integer;inw2:integer):string;
  1051. begin
  1052.    result:=inttostr(inw1)+'/'+inttostr(inw2)+'-';
  1053. end;
  1054. function hh(inw:integer):string;
  1055. var
  1056.    i:integer;
  1057.    tms:string;
  1058.    tmw,yo:integer;
  1059. begin
  1060.    tmw:=inw;
  1061.    tms:='';
  1062.    //bu.wrln(tmw);
  1063.    for i:=8 downto 0 do
  1064.       begin
  1065.          yo:= tmw div round(power(16,i));
  1066.          //bu.wrln(yo);
  1067.          case yo of
  1068.             15:tms:=tms+'F';
  1069.             14:tms:=tms+'E';
  1070.             13:tms:=tms+'D';
  1071.             12:tms:=tms+'C';
  1072.             11:tms:=tms+'B';
  1073.             10:tms:=tms+'A';
  1074.             // 0:tms:=tms;
  1075.          else
  1076.             tms:=tms+inttostr(yo);
  1077.          end;
  1078.          tmw:=tmw-yo*round(power(16,i));
  1079.       end;
  1080.    //endfor
  1081.     result:=tms+'-';
  1082. end;
  1083.  
  1084. begin
  1085.     wmsgstr:=hh(msg.Msg)+u(msg.WParamhi,msg.wparamlo)+
  1086.        u(msg.LParamhi,msg.lparamlo)+u(msg.Resulthi,msg.resultlo);
  1087.     {if assigned(bu) then
  1088.        bu.wrln(wmsgstr);
  1089.     //endif      }
  1090.     //bu.wrln(msg.)
  1091.     if msg.Msg=$112 then
  1092.        if ismaz=false then
  1093.           begin
  1094.              //inherited;
  1095.              ismaz:=true;
  1096.              //windowstate:=wsmaximized;
  1097.              if windowstate=wsmaximized then
  1098.                 begin
  1099.                    sendmessage(handle,wm_syscommand,sc_restore,0);
  1100.                    windowstate:=wsnormal;
  1101.                 end
  1102.              else
  1103.                 begin
  1104.                    sendmessage(handle,wm_syscommand,sc_maximize,0);
  1105.                    windowstate:=wsmaximized;
  1106.                 end;
  1107.              //endif
  1108.              {width:=screen.Width;
  1109.              height:=screen.Height;
  1110.              left:=0;
  1111.              top:=0;  }
  1112.              //invalidate;
  1113.              //refresh;
  1114.              //sendmessage(handle,WM_NCPAINT,0,0);
  1115.              //msg.Result:=1;
  1116.              exit;
  1117.           end;
  1118.        {else
  1119.           begin
  1120.              ismaz:=false;
  1121.              sendmessage(handle,wm_syscommand,sc_restore,0);
  1122.              exit;
  1123.           end;  }
  1124.        //endif
  1125.     //endi
  1126.     inherited;
  1127. end;
  1128.  
  1129. //------------------------------grid window proc
  1130. procedure tform2.newwndpro(var msg:tmessage);
  1131. {var
  1132.    curect:trect; }
  1133.  
  1134. procedure drawme;
  1135. var
  1136.    dc:hdc;
  1137.    bm:tbitmap;
  1138.    w,h,i,j:integer;
  1139.    s:prgbarray;
  1140.  
  1141. begin
  1142.    dc:=getwindowdc(rxdbgrid1.handle);
  1143.    bm:=tbitmap.Create;
  1144.    bm.Width:=rxdbgrid1.Width;
  1145.    bm.Height:=rxdbgrid1.Height;
  1146.    w:=bm.Width-1;
  1147.    h:=bm.Height-1;
  1148.    bitblt(bm.Canvas.Handle,0,0,w,h,dc,0,0,srccopy);
  1149.    for i:=0 to h-1 do
  1150.       begin
  1151.          s:=bm.ScanLine[i];
  1152.          for j:=0 to w-1 do
  1153.             begin
  1154.                s[j].rgbtBlue:=max(s[j].rgbtBlue * j div w,0);
  1155.             end;
  1156.          //endfor
  1157.       end;
  1158.    //endfor
  1159.    bitblt(dc,0,0,w,h,bm.Canvas.Handle,0,0,srccopy);
  1160.    releasedc(rxdbgrid1.Handle,dc);
  1161.  
  1162. end;
  1163.  
  1164. begin
  1165.    {if lock_upd then
  1166.       is_upd:=false;
  1167.    //endif      }
  1168.    
  1169.    if ((msg.Msg=WM_PAINT) or (msg.Msg=WM_ERASEBKGND)
  1170.       or (msg.Msg=WM_NCPAINT) {or (msg.Msg=WM_WINDOWPOSCHANGING) }
  1171.       {or (msg.Msg=WM_NCCALCSIZE)} {or (msg.Msg=WM_GETMINMAXINFO)}) and (is_upd) then
  1172.       exit;
  1173.    //endif
  1174.  
  1175.  
  1176.    if (msg.Msg=WM_ERASEBKGND) then
  1177.       begin
  1178.          {getwindowrect(grih,curect);
  1179.          grib.Width:=curect.Right-curect.Left;
  1180.          grib.Height:=curect.Bottom-curect.Top;
  1181.          callwindowproc(oldwpro,grib.handle,msg,wparam,lparam);}
  1182.          
  1183.          exit;
  1184.       end;
  1185.    //endif
  1186.  
  1187.    with msg do
  1188.       result:=callwindowproc(oldwpro,grih, msg,wparam,lparam);
  1189.    //endwith
  1190.    //sleep(1000);
  1191.  
  1192.     //--------------------------buff output
  1193.    {if msg.Msg=WM_PAINT then
  1194.       drawme;
  1195.    //endif       }
  1196.  
  1197. end;
  1198.  
  1199. //---------------------replace grid winproc
  1200. procedure tform2.replgrwinpro;
  1201. begin
  1202.    grih:=rxdbgrid1.Handle;
  1203.    newwpro:=classes.MakeObjectInstance(newwndpro);
  1204.    oldwpro:=pointer(getwindowlong(grih,GWL_WNDPROC));
  1205.    setwindowlong(grih,GWL_WNDPROC,longint(newwpro));
  1206.  
  1207. end;
  1208.  
  1209. //---------------------------------------------------
  1210. procedure TForm2.FormShow(Sender: TObject);
  1211. var
  1212.    //tmp_str:string;
  1213.    //tmuser,tmpass:string;
  1214.    //act:tcloseaction;
  1215.    //h:integer;
  1216.    rx:tdbgridop;
  1217.  
  1218. begin
  1219.    mkrg;
  1220.    {h:=rxdbgrid1.Canvas.TextHeight('test');
  1221.    thagrid(rxdbgrid1).RowCount:=2; }
  1222.    //thagrid(rxdbgrid1).RowHeights[0]:=70;
  1223.    rx:=rxdbgrid1;
  1224.    rx.TitleHeight:=70;
  1225.    rx.UseMultiTitle:=true;
  1226.    //rx.VTitleMargin:=4;
  1227.    //rx.optionseh
  1228.  
  1229.    bkt:=tbkt.create(true,self);
  1230.    with bkt do
  1231.       begin
  1232.          hbkt:=handle;
  1233.          resume;
  1234.       end;
  1235.    //endwith
  1236.    if not(directoryexists(FL_LDIR)) then
  1237.       mkdir(FL_LDIR);
  1238.    //endif
  1239.    if fileexists(FL_BK) then
  1240.       deletefile(FL_BK);
  1241.    //endif
  1242.    if fileexists(FL_SYS) then
  1243.       deletefile(FL_SYS);
  1244.    //endif
  1245.    {with tasyfo.Create(nil) do
  1246.       begin
  1247.          windows.ShowWindow(handle, SW_SHOWNORMAL);
  1248.          windows.SetWindowPos(handle,HWND_TOP,
  1249.          250,400,50,50, SWP_NOACTIVATE);
  1250.       end;
  1251.    //endwith   }
  1252. end;
  1253.  
  1254.  
  1255.  
  1256. procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
  1257. {var
  1258.   //al:boolean;
  1259.   exco:cardinal; }
  1260.  
  1261. begin
  1262.    AdoConnection1.close;
  1263.    if assigned(bkt) then
  1264.       begin
  1265.          bkt.Terminate;
  1266.          bkt.WaitFor;
  1267.       end;
  1268.    //endif
  1269.    if assigned(refr) then
  1270.       begin
  1271.          refr.Terminate;
  1272.          refr.WaitFor;
  1273.       end;
  1274.    //endif
  1275.    if assigned(debu) then  //tmemorystream
  1276.       begin
  1277.          debu.clear;
  1278.          debu.Free;
  1279.       end;
  1280.    //endif
  1281.    //terminatethread(hbkt,exco);
  1282.    //waitforsingleobject(hbkt,INFINITE);
  1283.  
  1284.  
  1285.    {al:=true;
  1286.    while al=true do
  1287.       if getexitcodethread(bkt.Handle,exco) then
  1288.          if exco<>STILL_ACTIVE then
  1289.             al:=false;
  1290.          //endif
  1291.       //endif
  1292.    //wend  }
  1293.    
  1294.  
  1295. end;
  1296.  
  1297. //-----------------------------open connection
  1298. procedure tform2.ftgrgproc(sender:tobject);
  1299. var
  1300.    rg:tradiogroup;
  1301.    aco:tadoconnection;
  1302. begin
  1303.    rg:=(sender as tradiogroup);
  1304.    aco:=adoconnection1;
  1305.  
  1306.    termrefr;
  1307.    aco.Close;        //FTG-FTG
  1308.    ibfkcode:=false;
  1309.    if pos('freecs',ansilowercase(ftgarr[rg.itemindex].coname))<>0 then
  1310.       begin
  1311.          aco.ConnectionString:=ftgarr[rg.Itemindex].servnam;
  1312.          ibfkcode:=true;
  1313.       end
  1314.    else
  1315.       if pos('mssql',ansilowercase(ftgarr[rg.itemindex].coname))<>0 then
  1316.          aco.connectionstring:=
  1317.          'Provider=SQLNCLI.1;Password='+ftgarr[rg.itemindex].pass+';'+
  1318.          'Persist Security Info=True;User ID='+ftgarr[rg.itemindex].login+';'+
  1319.          {'Initial catalog=Expenses;}'Data Source='+ftgarr[rg.Itemindex].servnam
  1320.       else
  1321.          if pos('as sysdba', ansilowercase(ftgarr[rg.itemindex].pass))<>0 then
  1322.             aco.ConnectionString:=
  1323.             'Provider=MSDASQL.1;Password='+ftgarr[rg.itemindex].pass
  1324.             +';Persist Security Info=true;'+'User ID='+ftgarr[rg.itemindex].login+
  1325.             ';Extended Properties="DRIVER=Oracle in OraDb10g_home1;'+
  1326.             'UID='+ftgarr[rg.itemindex].login+';PWD='+ftgarr[rg.itemindex].pass+
  1327.             ';DBQ='+ftgarr[rg.itemindex].servnam+'"'
  1328.          else
  1329.             aco.connectionstring:=
  1330.             'Provider=OraOLEDB.Oracle.1;Password='+ftgarr[rg.itemindex].pass+
  1331.             ';Persist Security Info=True;'+
  1332.             'User ID='+ftgarr[rg.itemindex].login+
  1333.             ';Data Source='+ftgarr[rg.itemindex].servnam;
  1334.          //endif
  1335.       //endif
  1336.    //endif
  1337.    aco.LoginPrompt:=false;
  1338.    try
  1339.       aco.OPEN; //ftg
  1340.       statusstr:=ftgarr[rg.itemindex].servnam+' success';
  1341.    except
  1342.       statusstr:=ftgarr[rg.itemindex].servnam+' failed'
  1343.    end;
  1344.  
  1345.    chaque;
  1346.  
  1347.  
  1348.  
  1349. end;
  1350.  
  1351. //---------------------------set active query
  1352. procedure tform2.chaque;
  1353. var
  1354.   tms:string;
  1355.   aq:tadoquery;
  1356.   n_rows:integer;
  1357.  
  1358. begin
  1359.    if (copy(ansiuppercase(trimleft(tmp_baseq)),1,6)<>'SELECT') and
  1360.       (copy(ansiuppercase(trimleft(tmp_baseq)),1,4)<>'WITH') then
  1361.       begin
  1362.          if messagebox(handle,pansichar('confirm: '+tmp_baseq),
  1363.          'sys', MB_YESNO+MB_ICONWARNING)=IDYES then
  1364.             begin
  1365.                try
  1366.                   aq:=adoquery2;
  1367.                   aq.SQL.Text:=tmp_baseq;
  1368.                   n_rows:=aq.ExecSQL;
  1369.                   statusstr:='rows affected '+inttostr(n_rows);
  1370.                   shopo9;
  1371.                except
  1372.                   on E: Exception do
  1373.                      begin
  1374.                         statusstr:=E.Message;
  1375.                         shopo9;
  1376.                      end;
  1377.                   //---
  1378.                end;
  1379.             end;
  1380.          //endif
  1381.          exit;
  1382.       end;
  1383.    //endif
  1384.  
  1385.    is_upd:=true;
  1386.    if refmode=true then
  1387.       tms:='refr;'
  1388.    else
  1389.       tms:='norefr;noresize;';
  1390.    //endif
  1391.  
  1392.    //if pos
  1393.    if ibfkcode then
  1394.       memo1.Text:=tmp_baseq+' '+tmp_filst+tmp_sortli+';'+tms
  1395.    else
  1396.       if pos('SQLNCLI',adoconnection1.ConnectionString)<>0 then
  1397.          memo1.Text:=
  1398.          'select  a.* from ('+
  1399.          tmp_baseq+') a '+tmp_filst+tmp_sortli+';'+tms
  1400.       else
  1401.          memo1.Text:=
  1402.          'select rownum, a.* from ('+
  1403.          tmp_baseq+') a '+tmp_filst+tmp_sortli+';'+tms;
  1404.       //endif
  1405.    //endif
  1406.  
  1407.    button1click(nil);
  1408.    is_upd:=false;
  1409. end;
  1410.  
  1411. //--------------------------------------new connection
  1412. procedure tform2.modo(isedit:boolean);
  1413. var
  1414.    fo:tform;
  1415.    i:integer;
  1416.    ini:tinifile;
  1417.    g:thagro;
  1418.  
  1419.  
  1420. function getcomp(instr:string):tedit;
  1421. {var
  1422.    j:integer; }
  1423.  
  1424. begin
  1425.    {bu.wrr('find components',40);
  1426.  
  1427.    for j:=0 to fo.ComponentCount-1 do
  1428.       begin
  1429.          bu.wrln(fo.Components[j].Name);
  1430.       end;
  1431.    //endfor      }
  1432.    result:=fo.FindComponent(instr) as tedit;
  1433. end;
  1434.  
  1435. begin
  1436.    {if button<>mbright then
  1437.       exit;
  1438.    //endif  }
  1439.  
  1440.    g:=gl_ragro;
  1441.    //----------------------
  1442.       fo:=tform.CreateNew(nil);   //ftg
  1443.       fo.Width:=350;
  1444.       fo.Height:=150;
  1445.       for i:=1 to 4 do
  1446.          begin
  1447.             with tlabel.create(fo) do
  1448.                begin
  1449.                   parent:=fo;
  1450.                   left:=10;
  1451.                   top:=20*i-15;
  1452.                   case i of
  1453.                      1:caption:='NAME';
  1454.                      2:caption:='SERVER';
  1455.                      3:caption:='LOGIN';
  1456.                      4:caption:='PASS';
  1457.                   end;
  1458.                end;
  1459.             //endwith
  1460.             with tedit.Create(fo) do
  1461.                begin
  1462.                   parent:=fo;
  1463.                   top:=20*i-15;
  1464.                   left:=60;
  1465.                   width:=280;
  1466.                   height:=19;
  1467.                   name:='edit'+inttostr(i);
  1468.                   if isedit then
  1469.                      begin
  1470.                      case i of
  1471.                         1:text:=ftgarr[g.itemindex].coname;
  1472.                         2:text:=ftgarr[g.itemindex].servnam;
  1473.                         3:text:=ftgarr[g.itemindex].login;
  1474.                         4:text:=ftgarr[g.itemindex].pass;
  1475.                      end;
  1476.                      end
  1477.                   else
  1478.                      text:='';
  1479.                   //endif
  1480.                   showhint:=true;
  1481.                   case i of
  1482.                      1:hint:='NAME';
  1483.                      2:hint:='SERVER';
  1484.                      3:hint:='LOGIN';
  1485.                      4:hint:='PASS';
  1486.                   end;
  1487.                end;
  1488.             //endwith
  1489.          end;
  1490.       //endfor
  1491.    //------------------------
  1492.    with tbutton.Create(nil) do
  1493.       begin
  1494.          parent:=fo;
  1495.          caption:='ok';
  1496.          top:=90;
  1497.          width:=50;
  1498.          left:=10;
  1499.          modalresult:=mrok;
  1500.       end;
  1501.    //end with
  1502.    with tbutton.Create(nil) do
  1503.       begin
  1504.          parent:=fo;
  1505.          caption:='cancel';
  1506.          top:=90;
  1507.          width:=50;
  1508.          left:=70;
  1509.          modalresult:=mrcancel;
  1510.       end;
  1511.    //end with
  1512.    if fo.showmodal=mrok then
  1513.       begin
  1514.          randomize;
  1515.          if isedit then
  1516.             i:=strtoint(ftgarr[g.itemindex].num)
  1517.          else
  1518.             i:=random(10000);
  1519.          //endif
  1520.          ini:=tinifile.Create(extractfilepath(application.ExeName)+'\ftg.ini');
  1521.          ini.WriteString('CONAME','name'+inttostr(i),getcomp('edit1').text);
  1522.          ini.WriteString('SERVERS','serv'+inttostr(i),getcomp('edit2').text);
  1523.          ini.WriteString('LOGINS','login'+inttostr(i),getcomp('edit3').text);//FTG
  1524.          ini.writestring('PASSES','pass'+inttostr(i), getcomp('edit4').text);//FTG
  1525.          ini.UpdateFile;
  1526.          ini.Free;
  1527.          mkradgro;
  1528.       end;
  1529.    //endif
  1530.    fo.Free;
  1531.  
  1532. end;
  1533.  
  1534. //-------------------------------------------------------
  1535. procedure tform2.mkradgro;
  1536. var
  1537.    ini:tinifile;
  1538.    FTGS,ftgs3,ftgs5,ftgs6:tstringlist;
  1539.    i:integer;
  1540.    pa:tpanel;
  1541.    rg:thagro;
  1542.  
  1543. procedure apserv(servnam, lognam,pasnam, coname:string;nu:integer);
  1544. begin
  1545.    ini.WriteString('SERVERS','serv'+inttostr(nu),servnam);
  1546.    ini.WriteString('LOGINS','login'+inttostr(nu),lognam);//FTG
  1547.    ini.writestring('PASSES','pass'+inttostr(nu), pasnam);//FTG
  1548.    ini.WriteString('CONAME','name'+inttostr(nu),coname);
  1549. end;
  1550.  
  1551.  
  1552. function ftgpa:string;
  1553. begin
  1554.    result:=extractfilepath(application.exename)
  1555.    //FTG ! getdir(0,spath);
  1556. end;
  1557.  
  1558. begin
  1559.  
  1560.    panel1.FindChildControl('ubl').Free;
  1561.    pa:=tpanel.Create(panel1);
  1562.    with pa do
  1563.       begin
  1564.          parent:=panel1;
  1565.          name:='ubl';
  1566.          height:=150;
  1567.          align:=albottom;
  1568.          popupmenu:=pom4;
  1569.       end;
  1570.    //endwith
  1571.    rg:=thagro.Create(pa);
  1572.    rg.ShowHint:=true;
  1573.    rg.Parent:=pa;
  1574.    rg.Align:=alclient;
  1575.    rg.OnClick:=ftgrgproc;
  1576.    //rg.inmodo:=modo;
  1577.    gl_ragro:=rg;
  1578.  
  1579.    FTGS:=tstringlist.Create;
  1580.    ftgs3:=tstringlist.Create;
  1581.    ftgs5:=tstringlist.Create;
  1582.    ftgs6:=tstringlist.Create;
  1583.    ini:=tinifile.Create(ftgpa+'ftg.ini');
  1584.  
  1585.  
  1586.    ini.ReadSection('SERVERS',FTGS);
  1587.    if ftgs.count=0 then
  1588.       begin
  1589.          apserv('emg-oracle1.europaplus.ru/MONIT','MONIT','MONIT','Cert/MONIT',1);
  1590.          ini.ReadSection('SERVERS',FTGS);
  1591.       end;
  1592.    //endif
  1593.    ini.ReadSection('LOGINS',ftgs3);
  1594.    ini.ReadSection('PASSES',ftgs5);
  1595.    ini.ReadSection('CONAME',ftgs6);
  1596.  
  1597.    setlength(ftgarr,ftgs.Count);
  1598.  
  1599.    for i:=0 to ftgs.Count-1 do
  1600.       begin                              //FTG
  1601.          ftgarr[i].num:=copy(ftgs[i],5,length(ftgs[i])-4);
  1602.          ftgarr[i].servnam:=ini.ReadString('SERVERS',ftgs[i],'');
  1603.          ftgarr[i].login:=ini.readstring('LOGINS',ftgs3[i],'');
  1604.          ftgarr[i].pass:=ini.ReadString('PASSES',ftgs5[i],'');
  1605.          ftgarr[i].coname:=ini.ReadString('CONAME',ftgs6[i],'');
  1606.          rg.Items.Add(ftgarr[i].coname);
  1607.       end;
  1608.    //endfor
  1609.    pa.Height:=ftgs.Count*25+10;
  1610.  
  1611.    {if not(fileexists(ftgpa+'\ftg.ini')) then
  1612.       begin   }
  1613.    FTGS.free;
  1614.    ftgs3.free;
  1615.    ftgs5.Free;
  1616.    ini.Free;
  1617.  
  1618.    rg.OnMouseMove:=rgmmove;
  1619.    for i:=0 to rg.ControlCount-1 do
  1620.       (rg.Controls[i] as tradiobutton).onmousemove:=rgmmove;
  1621.    //endfor
  1622.  
  1623.    rg.ItemIndex:=0;
  1624. end;
  1625.  
  1626. //------------------------------set hint of rgroup
  1627. procedure tform2.rgmmove(sender:tobject;shift:tshiftstate;x,y:integer);
  1628. {var
  1629.    rg:thagro;
  1630.    i:integer;  }
  1631.  
  1632. begin
  1633.    {if sender is thagro then
  1634.       rg:=sender as thagro
  1635.    else
  1636.       rg:=(sender as tcontrol).parent as thagro;
  1637.    //endif
  1638.    i:=floor((mouse.CursorPos.y-rg.parent.Top-self.top-30)/25);
  1639.    if (i>=0) and (i<rg.Items.count) then
  1640.       begin
  1641.          statusstr:=rg.Items[i];
  1642.          //dopstr:=ftgarr[i].login;
  1643.       end;
  1644.    //endif    }
  1645.  
  1646. end;
  1647.  
  1648.  
  1649. //------------------------------------------------------------
  1650. //            make list of querys
  1651. //------------------------------------------------------------
  1652. procedure tform2.mkzapgri;
  1653. var
  1654.    pa:tpanel;
  1655.    lv:tlistview;
  1656.    fs:tfilestream;
  1657.    sl:tstringlist;
  1658.    tms:string;
  1659.    i:integer;
  1660.    li:tlistitem;
  1661.  
  1662. begin
  1663.  
  1664.    tms:=curzapfile;//extractfilepath(application.ExeName)+'\zaps.txt';
  1665.    sl:=tstringlist.Create;
  1666.  
  1667.    if not(fileexists(tms)) then
  1668.       begin
  1669.          sl.Add(tmp_baseq);
  1670.          fs:=tfilestream.Create(tms,fmcreate);
  1671.          sl.SaveToStream(fs);
  1672.          fs.Free;
  1673.       end;
  1674.    //endif
  1675.  
  1676.    sl.clear;
  1677.    sl.LoadFromFile(tms);
  1678.  
  1679.    if not assigned(gl_lv) then
  1680.       begin
  1681.          spli(panel2);
  1682.          pa:=pane('zap',50,alclient,panel2);
  1683.          lv:=tlistview.Create(self);
  1684.          lv.Parent:=pa;
  1685.          lv.Align:=alclient;
  1686.          lv.Columns.Insert(0);
  1687.          lv.Columns[0].Width:=700;
  1688.          //lv.Checkboxes:=true;
  1689.          lv.ViewStyle:=vsreport;
  1690.          lv.SmallImages:=il;
  1691.          lv.MultiSelect:=true;
  1692.          lv.OnDblClick:=onlvcli;
  1693.          lv.OnMouseDown:=lvmodon;
  1694.          //lv.PopupMenu:=pom;
  1695.          lv.DragMode:=dmautomatic;
  1696.       end
  1697.    else
  1698.       begin
  1699.          lv:=gl_lv;
  1700.          lv.Clear;
  1701.       end;
  1702.    //endif
  1703.  
  1704.    randomize;
  1705.    for i:=sl.Count-1 downto 0 do
  1706.       begin
  1707.          li:=lv.Items.Add;
  1708.          li.Caption:=sl.Strings[i];
  1709.          li.ImageIndex:=random(4);
  1710.       end;
  1711.    //endfor
  1712.    sl.Free;
  1713.  
  1714.    gl_lv:=lv;
  1715. end;
  1716.  
  1717. //--------------------------on listview click
  1718. procedure tform2.onlvcli(sender:tobject);
  1719. var
  1720.    lv:tlistview;
  1721.  
  1722. begin
  1723.    lv:=sender as tlistview;
  1724.    if lv.SelCount>0 then
  1725.       begin
  1726.          tmp_baseq:=adno(lv.Selected.Caption,true);
  1727.          tmp_filst:='';
  1728.          tmp_sortli:='';
  1729.          colresize:=true;
  1730.          chaque;
  1731.       end;
  1732.    //endif
  1733. end;
  1734.  
  1735. //------------------------sql listview right button click
  1736. procedure tform2.lvmodon(sender:tobject;button:tmousebutton;
  1737. shift:tshiftstate;x,y:integer);
  1738. {var
  1739.    lv:tlistview;  }
  1740.  
  1741. begin
  1742.    //lv:=sender as tlistview;
  1743.    if (button=mbright) {and (lv.selcount>0)} then
  1744.       pom5.Popup(mouse.CursorPos.X, mouse.cursorpos.Y,0);
  1745.    //endif
  1746.  
  1747.    {f:=tform.createnew;
  1748.    f.     }
  1749.  
  1750. end;
  1751.  
  1752. //----------------------------show menu of query files
  1753. procedure tform2.tvmodon(sender:tobject;button:tmousebutton;
  1754. shift:tshiftstate;x,y:integer);
  1755. begin
  1756.    if (button=mbright) then
  1757.       pom8.popup(mouse.CursorPos.X,mouse.CursorPos.Y,0);
  1758.    //endif
  1759. end;
  1760.  
  1761. //------------------------------group check onclick
  1762. procedure tform2.grchcli(sender:tobject);
  1763. begin
  1764. end;
  1765. //-----------------------group modo
  1766. procedure tform2.grmodon(sender:tobject;var dragobject:tdragobject);
  1767. begin
  1768.    deltax:=mouse.CursorPos.X;
  1769.    deltay:=mouse.CursorPos.Y;
  1770.    {deltax:=round(dragobject.MouseDeltaX);
  1771.    deltay:=round(dragobject.MouseDeltaY); }
  1772.    {bu.wrln('-*---');
  1773.    bu.wrln(mouse.CursorPos.x);
  1774.    bu.wrln(mouse.CursorPos.y);    }
  1775.    {bu.wrln((sender as tcontrol).left);
  1776.    bu.wrln((sender as tcontrol).Top);  }
  1777. end;
  1778.  
  1779. //------------------group box drover & drop
  1780. procedure tform2.grdrova(sender,source:tobject;x,y:integer;
  1781. state:tdragstate; var accept:boolean);
  1782. begin
  1783. //
  1784. end;
  1785. procedure tform2.grdrop(sender,source:tobject;x,y:integer);
  1786. var
  1787.    pa8:tpanel;
  1788.    mo:tpoint;
  1789.  
  1790. begin
  1791.    pa8:=(source as tpanel);
  1792.    mo:=mouse.cursorpos;//ftg
  1793.    pa8.left:=pa8.left+mo.x-deltax;
  1794.    pa8.top:=pa8.Top+mo.y-deltay;
  1795.    if mo.Y<deltay then
  1796.       pa8.Top:=pa8.Top-25;
  1797.    //endif
  1798.    {bu.wrln('-------');
  1799.    bu.wrln(x-deltax);
  1800.    bu.wrln(y-deltay);
  1801.    bu.wrln(deltax);
  1802.    bu.wrln(deltay); }
  1803.    //arrchecks;
  1804.    redrtree;
  1805. end;
  1806.  
  1807. //---------------------------compare func for sort
  1808. function compaf(item1,item2:pointer):integer;
  1809. begin
  1810.    if (tcontrol(item1).top)<(tcontrol(item2).Top) then
  1811.       result:=-1
  1812.    else
  1813.       if (tcontrol(item1).top)>(tcontrol(item2).Top) then
  1814.          result:=1
  1815.       else
  1816.          result:=0;
  1817.    //endif
  1818. end;
  1819. //-----------------------arrange checks
  1820. function tform2.arrchecks:tlist;
  1821. var
  1822.    i:integer;
  1823.    pa:tpanel;
  1824.    li:tlist;
  1825.    //sorted:boolean;
  1826.    //co:tcontrol;
  1827.  
  1828.  
  1829. begin
  1830.    li:=tlist.Create;
  1831.    pa:=panel1.findcomponent('abl') as tpanel;
  1832.    for i:=0 to pa.ComponentCount-1 do
  1833.       li.Add(pa.Components[i]);
  1834.    //endif
  1835.    li.sort(compaf);
  1836.  
  1837.    for i:=0 to li.Count-1 do
  1838.       begin
  1839.          tcontrol(li[i]).top:=3+25*i;
  1840.          tcontrol(li[i]).Left:=1+10*i;
  1841.       end;
  1842.    //endfor
  1843.    result:=li;
  1844.  
  1845. end;
  1846.  
  1847.  
  1848. //--------------------------
  1849. procedure tform2.spli(pare:twincontrol);
  1850. begin
  1851.    with tsplitter.Create(pare) do
  1852.       begin
  1853.          parent:=pare;
  1854.          align:=altop;
  1855.          //height:=1;
  1856.          minsize:=15;
  1857.          autosnap:=false;
  1858.          beveled:=true;
  1859.          //minsize:=panel1.FindChildControl('ubl').height;
  1860.          resizestyle:=rsupdate;
  1861.       end;
  1862.    //endwith
  1863. end;
  1864. //-----------------------
  1865. function tform2.pane(innam:string;ha:integer;ali:talign;pare:twincontrol):tpanel;
  1866. var
  1867.    inpa:tpanel;
  1868. begin
  1869.    inpa:=tpanel.Create(pare);
  1870.    with inpa do
  1871.       begin
  1872.          parent:=pare;
  1873.          name:=innam;
  1874.          height:=ha;
  1875.          align:=ali;
  1876.          caption:='';
  1877.          fullrepaint:=false;
  1878.          parentbackground:=false;
  1879.          parentcolor:=true;
  1880.       end;
  1881.    //endwith
  1882.  
  1883.    result:=inpa;
  1884. end;
  1885.  
  1886.  
  1887. //---------------------------make aggregate tree & control
  1888. procedure tform2.mkutree;
  1889. type
  1890.    ans = (smon,sday,suser,smach);
  1891.    tans = set of ans;
  1892.  
  1893. var
  1894.    pa,pa3:tpanel;
  1895.  
  1896. //----------------------
  1897. procedure chbo(cap:string;taga:integer);
  1898. var
  1899.    hy:integer;
  1900.    pa9:tpanel;
  1901. begin
  1902.    hy:=pa.ComponentCount*25;
  1903.    pa9:=tpanel.Create(pa);
  1904.    with pa9 do
  1905.       begin
  1906.          parent:=pa;
  1907.          top:=hy+3;
  1908.          //bu.wrln(top);
  1909.          height:=24;
  1910.          //align:=alnone;
  1911.          tag:=taga;
  1912.          dragmode:=dmautomatic;
  1913.          onstartdrag:=grmodon;
  1914.          ondragover:=grdrova;
  1915.          ondragdrop:=grdrop;
  1916.          width:=pa.Width-41;
  1917.          left:=1+pa.ComponentCount*10; //ftg
  1918.       end;
  1919.    //endwith
  1920.  
  1921.    with tcheckbox.Create(pa9) do
  1922.       begin
  1923.          parent:=pa9;
  1924.          //align:=alclient;
  1925.          left:=20;
  1926.          top:=1;
  1927.          width:=50;//parent.Width-24;
  1928.          height:=parent.Height-3;
  1929.          //top:=hy+3;
  1930.          //height:=24;
  1931.          caption:=cap;
  1932.          checked:=false;
  1933.          tag:=taga;
  1934.          onclick:=grchcli;
  1935.          ondragover:=grdrova;
  1936.          ondragdrop:=grdrop;
  1937.       end;
  1938.    //endwith
  1939. end;
  1940. //------------------------------
  1941. procedure chbos(instr:tans);
  1942. var
  1943.    tms:ans;
  1944.    j:integer;
  1945.    tmst:string;
  1946. begin
  1947.    j:=1;
  1948.    for tms in instr do
  1949.       begin
  1950.          case tms of
  1951.             smon:tmst:='month';
  1952.             sday:tmst:='day';
  1953.             suser:tmst:='user';
  1954.             smach:tmst:='machine';
  1955.          else
  1956.             tmst:='';
  1957.          end;
  1958.          chbo(tmst,j);
  1959.          j:=j+1
  1960.       end;
  1961.    //endfor
  1962. end;
  1963.  
  1964. //------------------------
  1965. begin
  1966.  
  1967.  
  1968.    spli(panel1);
  1969.    pa:=pane('abl',15,altop,panel1);
  1970.    pa.OnDragOver:=grdrova;
  1971.    pa.OnDragDrop:=grdrop;
  1972.  
  1973.    {pa3:=}pane('trb',100,alclient,panel1);
  1974.    //pa.Caption:='groups';
  1975.    chbos([smon,sday,suser,smach]);
  1976.    redrtree;
  1977. end;
  1978. //----------------------------make tree
  1979. procedure tform2.redrtree;
  1980. var
  1981.    pa3:tpanel;//ftg
  1982.    //tv:ttreeview;
  1983.    i:integer;
  1984.    vob:tvob;
  1985.    //i:integer;
  1986.    //sq:array[1..4] of string;
  1987.  
  1988. procedure recufi(indir:string;parno:ttreenode);
  1989. var
  1990.    sr:tsearchrec;
  1991.    finde:integer;
  1992.    tno:ttreenode;
  1993.  
  1994. procedure maction;
  1995. begin
  1996.    vob:=tvob.Create;
  1997.    vob.filpath:=indir+'\'+sr.Name;
  1998.    liob.Add(vob);
  1999.    if (sr.Attr and fadirectory)<>0 then
  2000.       begin
  2001.          vob.isfil:=0;
  2002.          tno:=gtv.Items.Addobject(nil,sr.Name,vob);
  2003.          tno.ImageIndex:=random(4);
  2004.          recufi(indir+'\'+sr.name,tno);
  2005.       end
  2006.    else
  2007.       if parno=nil then
  2008.          begin
  2009.             vob.isfil:=1;
  2010.             tno:=gtv.Items.AddObject(nil,sr.Name, vob);
  2011.          end
  2012.       else
  2013.          begin
  2014.             vob.isfil:=1;
  2015.             tno:=gtv.Items.AddChildObject(parno,sr.Name,vob);
  2016.          end;
  2017.       //endif
  2018. end;
  2019.  
  2020. begin
  2021.    finde:=findfirst(indir+'\*.zpu',faanyfile,sr);
  2022.    while finde=0 do
  2023.       begin
  2024.          maction;
  2025.          finde:=findnext(sr);
  2026.       end;
  2027.    //wend
  2028. end;
  2029.  
  2030. begin
  2031.    //sq[1]:='select to_char(extract(year from sess_table))||'+
  2032.    //chr(39)+'-'+chr(39)+'||to_char(;
  2033.    pa3:=panel1.FindChildControl('trb') as tpanel;
  2034.    pa3.DestroyComponents;
  2035.    liob.Clear;
  2036.    gtv:=ttreeview.Create(pa3);
  2037.    gtv.Parent:=pa3;
  2038.    gtv.Align:=alclient;
  2039.    gtv.Images:=il;
  2040.    gtv.OnClick:=tvonkli;
  2041.    gtv.OnMouseDown:=tvmodon;
  2042.    gtv.DragMode:=dmautomatic;//ftg
  2043.    gtv.OnDragOver:=grdrova;//ftg
  2044.    gtv.OnDragDrop:=tvdrop;
  2045.    recufi(extractfilepath(application.exename),nil);
  2046.    {for i:=0 to ili.Count-1 do
  2047.       begin
  2048.          if ((ili[i] as tcontrol).components[0] as tcheckbox).checked=true then  }
  2049. end;
  2050.  
  2051.  
  2052. //-------------------------------------------------------tree view drop
  2053. procedure tform2.tvdrop(sender,source:tobject;x,y:integer);
  2054. var
  2055.    //li:tlistitem;
  2056.    tn:ttreenode;
  2057.    sl:tstringlist;
  2058.    fnam:string;
  2059.    tmi:integer;
  2060.  
  2061. begin
  2062.    tn:=gtv.GetNodeAt(x,y);
  2063.  
  2064.    if (gtv.SelectionCount>0) and (tvob(tn.data).isfil=1) then
  2065.       begin
  2066.          fnam:=tvob(tn.data).filpath;
  2067.          sl:=tstringlist.Create;
  2068.          sl.loadfromfile(fnam);
  2069.          sl.insert(0,gl_lv.Selected.caption);
  2070.          sl.SaveToFile(fnam);
  2071.  
  2072.          sl.clear;
  2073.          tmi:=gl_lv.selected.Index;
  2074.          sl.LoadFromFile(curzapfile);
  2075.          sl.Delete(sl.Count-1-tmi);
  2076.          sl.SaveToFile(curzapfile);
  2077.  
  2078.          sl.Free;
  2079.          mkzapgri;
  2080.       end;
  2081.    //endif
  2082. end;
  2083.  
  2084.  
  2085. //----------------------------------select query list
  2086. procedure tform2.tvonkli(sender:tobject);
  2087. var
  2088.    //tv:ttreeview;
  2089.    //pa9:tpanel;
  2090.    vo:tvob;
  2091.  
  2092. begin
  2093.    //pa9:=panel1.findchildcontrol('trb') as tpanel;
  2094.    //tv:=pa9.components[0] as ttreeview;
  2095.    vo:=tvob(gtv.Selected.data);
  2096.    if vo.isfil=1 then
  2097.       begin
  2098.          curzapfile:=vo.filpath;
  2099.          mkzapgri;
  2100.       end;
  2101.    //endif
  2102. end;
  2103.  
  2104.  
  2105. //-----------------------------
  2106. procedure tform2.mkrg;
  2107. var
  2108.    p:array[0..4] of tpoint;
  2109.    rg1, rg2:hrgn;
  2110.  
  2111. begin
  2112.    p[0].x:=1;p[0].Y:=1;p[1].X:=width;p[1].Y:=1;
  2113.    p[2].X:=width;p[2].Y:=height;
  2114.    p[3].X:=1;p[3].Y:=height;p[4].X:=1;p[4].Y:=1;
  2115.  
  2116.    rg1:=createpolygonrgn(p,5,alternate);
  2117.    rg2:=createellipticrgn(width-120,-100,width+50,28);
  2118.    combinergn(rg1,rg1,rg2,RGN_XOR);
  2119.  
  2120.    setwindowrgn(handle,rg1,true);
  2121.    //bu.wrr('check set wreg',20);
  2122.    //bu.wrln(inttostr(clientwidth)+'-'+inttostr(clientheight));
  2123.  
  2124. end;
  2125. //----------------------------------------------------------------
  2126. //                 form creation
  2127. //----------------------------------------------------------------
  2128. procedure TForm2.FormCreate(Sender: TObject);
  2129. var
  2130.    i:integer;
  2131.    //w:dword;
  2132.    im:tmenuitem;
  2133.    al:tlist;
  2134.    ac:taction;
  2135. //----------------------------
  2136. begin
  2137.    curzapfile:='';
  2138.    {w:=getwindowlong(handle,GWL_STYLE);
  2139.    w:=w and not WS_MINIMIZEBOX;
  2140.    w:=w and not WS_MAXIMIZEBOX;
  2141.    w:=setwindowlong(handle,GWL_STYLE,1);     }
  2142.    lokpli:=tlist.Create;
  2143.    liob:=tlist.Create;
  2144.    ismaz:=false;
  2145.    bu.ini;
  2146.    initializecriticalsection(crise);
  2147.    inb:=tbitmap.create;
  2148.    inb9:=tbitmap.Create;
  2149.    grib:=tbitmap.Create;
  2150.    colresize:=true;
  2151.    refrall:=false;
  2152.    is_upd:=false;
  2153.    lock_upd:=false;
  2154.    refmode:=false;
  2155.    //mkrg;
  2156.    rxdbgrid1.Parent:=panel3;
  2157.    rxdbgrid1.Align:=alclient;
  2158.    rxdbgrid1.OptionsEh:=rxdbgrid1.optionseh+[dghmultisortmarking];
  2159.    {tpa:=tpanel.Create(self);
  2160.    tpa.Parent:=rxdbgrid1;
  2161.    tpa.Left:=0;
  2162.    tpa.Top:=30;
  2163.    tpa.Width:=17;
  2164.    tpa.Height:=30;}
  2165.  
  2166.    zbu:=tzbutton.Create(self);
  2167.    zbu.Parent:=rxdbgrid1;
  2168.    zbu.Width:=8;
  2169.    zbu.Height:=16;
  2170.    zbu.Left:=1;
  2171.    zbu.Top:=26;
  2172.    zbu.ButtonColor:=clblue;
  2173.    //zbu.start;
  2174.    zbu.OnClick:=refmodcha;
  2175.  
  2176.    //-----------------------------------
  2177.    al:=tlist.Create;
  2178.    pom:=tpopupmenu.Create(self);
  2179.    pom4:=tpopupmenu.Create(self);
  2180.    pom5:=tpopum.Create(self);
  2181.    pom9:=tpopum.create(self);
  2182.    pom6:=tpopupmenu.Create(self);
  2183.    pom8:=tpopum.create(self);
  2184.    pom8.forecheck:=false;
  2185.    //pom8.Color:=rgb(200,0,0);
  2186.  
  2187.    for i:=1 to 13 do
  2188.       begin
  2189.          ac:=taction.Create(self);
  2190.          ac.Tag:=i;
  2191.          ac.OnExecute:=menucli;
  2192.          al.Add(ac);
  2193.          im:=tmenuitem.Create(self);
  2194.          im.Action:=al.items[i-1];
  2195.          case i of
  2196.          1: im.caption:='sort ascending';
  2197.          2: im.Caption:='sort descending';
  2198.          3: im.Caption:='x clear sort';
  2199.          4: im.Caption:='export to excel';
  2200.          //----------------------------------
  2201.          5: im.Caption:='new connection';
  2202.          6: im.Caption:='edit connection';
  2203.          7: im.Caption:='delete connection';
  2204.          //----------------------------------
  2205.          8: im.Caption:='new query';
  2206.          9: im.Caption:='edit query';
  2207.          10:im.Caption:='delete query';
  2208.          11:im.Caption:='tkprof';
  2209.          12:im.Caption:='new file';
  2210.          13:im.Caption:='new folder';
  2211.  
  2212.          end;
  2213.          if i<5 then
  2214.             pom.Items.Add(im)
  2215.          else
  2216.             if i<8 then
  2217.                pom4.Items.Add(im)
  2218.             else
  2219.                if i<11 then
  2220.                   pom5.appitem(im.caption,i,menucli,0)
  2221.                else
  2222.                   if i<12 then
  2223.                      pom6.Items.Add(im)
  2224.                   else
  2225.                      pom8.appitem(im.Caption,i,menucli,0);
  2226.                   //endif
  2227.                //endif
  2228.             //endif
  2229.          //endif
  2230.       end;
  2231.    //endfor
  2232.  
  2233.    rxdbgrid1.PopupMenu:=pom6;
  2234.    rxdbgrid1.ontitlebtnclick:=menuou;
  2235.    //memo1.PopupMenu:=pom4;
  2236.  
  2237.    //-----------------------------------
  2238.    tmp_baseq:='select * from sess_table where program_name<>'+
  2239.    chr(39)+'perl.exe'+chr(39);//FTG
  2240.    tmp_filst:='';
  2241.    tmp_sortli:='';
  2242.  
  2243.    replgrwinpro;
  2244.    //spli;
  2245.    //mkzapgri;
  2246.    mkradgro;
  2247.    mkutree;
  2248. end;
  2249.  
  2250. //----------------------out menu
  2251. procedure tform2.menuou(sender:tobject;acol:integer;column:tcolumneh);
  2252. begin
  2253.    glocol:=column;
  2254.    pom.Popup(mouse.cursorpos.x,mouse.cursorpos.y);
  2255. end;
  2256.  
  2257.  
  2258. //-------------------------------------memo dialog form
  2259. function tform2.memofo(var inst:string):integer;
  2260. var
  2261.    f:tform;
  2262.    m:tmemo;
  2263.    b:tbutton;
  2264. begin
  2265.    f:=tform.createnew(nil);
  2266.    f.Width:=400;
  2267.    f.Height:=300;
  2268.    m:=tmemo.create(f);
  2269.    m.ScrollBars:=ssvertical;
  2270.    m.WordWrap:=true;
  2271.    m.Text:=adno(inst,false);
  2272.    m.parent:=f;
  2273.    m.left:=1;
  2274.    m.Top:=1;
  2275.    m.Width:=f.Width-2;
  2276.    m.Height:=f.Height-30;
  2277.    m.Anchors:=[akleft,akright,aktop,akbottom];
  2278.    b:=tbutton.Create(f);
  2279.    b.Parent:=f;
  2280.    b.Caption:='ok';
  2281.    b.ModalResult:=mrok;
  2282.    b.Left:=10;
  2283.    b.Top:=f.Height-25;
  2284.    b.Anchors:=[akleft,akbottom];
  2285.    b:=tbutton.Create(f);
  2286.    b.Parent:=f;
  2287.    b.Caption:='cancel';
  2288.    b.ModalResult:=mrcancel;
  2289.    b.Left:=90;
  2290.    b.Top:=f.Height-25;
  2291.    b.Anchors:=[akleft,akbottom];
  2292.  
  2293.    result:=f.showmodal;
  2294.    inst:=noad(m.Text);
  2295.  
  2296.    f.Free;
  2297. end;
  2298.  
  2299. //----------------------------------popup menu action
  2300. procedure tform2.menucli(sender:tobject);
  2301. var
  2302.    ac:tcomponent;
  2303.    ini:tinifile;
  2304.    tmi:integer;
  2305.    tms:string;
  2306.    sl:tstringlist;
  2307.    fs:tfilestream;
  2308.    //---------------------
  2309.    sti:tstartupinfo;
  2310.    pinf:tprocessinformation;
  2311.    rist:longbool;
  2312.    err:integer;
  2313.  
  2314. procedure bazs;
  2315. begin
  2316.    if tmp_sortli='' then
  2317.       tmp_sortli:=' order by ';
  2318.    //endif
  2319.    if tmp_sortli<>' order by ' then
  2320.       tmp_sortli:=tmp_sortli+',';
  2321.    //endif
  2322. end;
  2323.  
  2324. begin
  2325.    ac:=sender as tcomponent;
  2326.    //messagebox(handle,pansichar(inttostr(ac.tag)),'sys',0);
  2327.    case ac.Tag of
  2328.    1: begin
  2329.          bazs;
  2330.          tmp_sortli:=tmp_sortli+'"'+glocol.FieldName+'"';
  2331.          //glocol.title.sortmarker:=smupeh;
  2332.          chaque;
  2333.       end;
  2334.    2: begin
  2335.          bazs;
  2336.          tmp_sortli:=tmp_sortli+'"'+glocol.FieldName+'" desc';
  2337.          chaque;
  2338.          //glocol.Title.SortMarker:=smdowneh;
  2339.       end;
  2340.    3:begin
  2341.         tmp_sortli:='';
  2342.         {for i:=0 to rxdbgrid1.Columns.Count-1 do
  2343.            rxdbgrid1.Columns[i].Title.SortMarker:=smnoneeh;
  2344.         //endfor }
  2345.         chaque;
  2346.       end;
  2347.    4:statusstr:='excel plz wait';
  2348.    5:modo(false);
  2349.    6:modo(true);
  2350.    7:begin
  2351.         tms:=ftgarr[gl_ragro.itemindex].num;
  2352.         ini:=tinifile.Create(extractfilepath(application.ExeName)+'\ftg.ini');
  2353.         ini.DeleteKey('SERVERS','serv'+tms);
  2354.         ini.DeleteKey('LOGINS','login'+tms);
  2355.         ini.DeleteKey('PASSES','pass'+tms);
  2356.         ini.deletekey('CONAME','name'+tms);
  2357.         mkradgro;
  2358.      end;
  2359.    8,9,10:begin
  2360.         if (gl_lv.SelCount=0) and (ac.Tag<>8) then
  2361.            exit
  2362.         else
  2363.            if (gl_lv.SelCount>0) then
  2364.               tmi:=gl_lv.Selected.Index;
  2365.            //endif
  2366.         //endif
  2367.  
  2368.         fs:=tfilestream.Create(curzapfile
  2369.         {extractfilepath(application.exename)+'\zaps.txt'},
  2370.         fmopenread);
  2371.         fs.Seek(0,sofrombeginning);
  2372.         {sz:=fs.Size;
  2373.         getmem(buf,sz);
  2374.         fs.ReadBuffer(buf[0],sz);}
  2375.         sl:=tstringlist.create;
  2376.         sl.LoadFromStream(fs);
  2377.         //freemem(buf,sz);
  2378.         //setlength(buf,0);
  2379.         fs.Free;
  2380.         if ac.Tag=8 then
  2381.            begin
  2382.               tmi:=sl.add('');
  2383.               tms:='';
  2384.            end
  2385.         else
  2386.            tms:=sl.Strings[sl.count-1-tmi];
  2387.         //endif
  2388.  
  2389.         if (ac.Tag=10) or ((ac.Tag<>10) and (memofo(tms)=mrok)) then  //ftg
  2390.            begin
  2391.               if ac.Tag=10 then
  2392.                  sl.Delete(sl.Count-1-tmi)     //tstringlist
  2393.               else
  2394.                  if ac.Tag=8 then
  2395.                     sl.strings[tmi]:=tms
  2396.                  else
  2397.                     sl.strings[sl.Count-1-tmi]:=tms;
  2398.                  //endif
  2399.               //endif
  2400.               fs:=tfilestream.create(curzapfile
  2401.               {extractfilepath(application.exename)
  2402.               +'\zaps.txt'},fmcreate);
  2403.               //fs.Seek(0,sofrombeginning);
  2404.               {for i:=0 to sl.Count-1 do
  2405.                  begin
  2406.                     tms:=sl.Strings[i]{+chr(13)+chr(10);
  2407.                     if (i<sl.Count-1) or (ac.Tag<>10) then
  2408.                        fs.writebuffer(pchar(tms)^,length(tms));
  2409.                     //endif
  2410.                  end;
  2411.               //endfor    }
  2412.               sl.SaveToStream(fs);
  2413.               fs.Free;
  2414.               mkzapgri;
  2415.            end;
  2416.         //endif
  2417.         sl.Free;
  2418.      end;
  2419.    11:begin
  2420.          tms:=adoquery1.Fields.FieldByName('TRAS_FILE').asstring;
  2421.  
  2422.          fillchar(sti,sizeof(sti),0);
  2423.          sti.cb:=sizeof(sti);
  2424.          sti.dwFlags:=0;
  2425.          sti.wshowwindow:=SW_HIDE;
  2426.  
  2427.          rist:=createprocess(nil,
  2428.          pansichar('tkprof.exe "'+tms+'" "'+tms+'.txt"'),nil,nil,false,
  2429.          NORMAL_PRIORITY_CLASS,nil,nil,sti,pinf);
  2430.  
  2431.          if rist then
  2432.             begin
  2433.                waitforsingleobject(pinf.hprocess,INFINITE);
  2434.                closehandle(pinf.hProcess);
  2435.                closehandle(pinf.hThread);
  2436.             end
  2437.          else
  2438.             raise exception.create(inttostr(getlasterror));
  2439.          //endif
  2440.  
  2441.  
  2442.          {shellexecute(handle,'open','cmd.exe',
  2443.          pansichar('/c tkprof "'+tms+'" "'+tms+'.txt"'),'',sw_hide);
  2444.          //winexec(pansichar('cmd /c tkprof.exe '+tms+' '+tms+'.txt'),0);  }
  2445.          shellexecute(handle,'open',pansichar(tms+'.txt'),'','',sw_shownormal);
  2446.       end;
  2447.    //------------------------------------
  2448.    12,13:begin
  2449.          tms:='';
  2450.          if memofo(tms)=mrok then
  2451.             begin
  2452.                if (gtv.SelectionCount>0) and
  2453.                   (tvob(gtv.Selected.Data).isfil=0) then
  2454.                   begin//FTG
  2455.                      if ac.Tag=12 then
  2456.                         begin
  2457.                            fs:=tfilestream.Create(
  2458.                            tvob(gtv.Selected.Data).filpath+
  2459.                            '\'+noad9(tms)+'.zpu',fmcreate);
  2460.                            fs.Free;
  2461.                         end
  2462.                      else
  2463.                         mkdir(tvob(gtv.Selected.Data).filpath+
  2464.                         '\'+noad9(tms)+'.zpu');//FTG
  2465.                      //endif
  2466.                   end
  2467.                else
  2468.                   begin
  2469.                      if ac.Tag=12 then
  2470.                         begin
  2471.                            fs:=tfilestream.Create(
  2472.                            extractfilepath(application.exename)+
  2473.                            '\'+noad9(tms)+'.zpu',fmcreate);
  2474.                            fs.Free;
  2475.                         end
  2476.                      else
  2477.                         mkdir(extractfilepath(application.ExeName)+
  2478.                         '\'+noad9(tms)+'.zpu');
  2479.                      //endif
  2480.                   end;
  2481.                //endif
  2482.                redrtree;
  2483.             end;
  2484.          //endif
  2485.       end;
  2486.    end;
  2487.  
  2488.  
  2489. end;
  2490.  
  2491.  
  2492. procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton;
  2493.   Shift: TShiftState; X, Y: Integer);
  2494. begin
  2495.    {if button=mbright then
  2496.       close;
  2497.    //endif  }
  2498. end;
  2499.  
  2500. procedure TForm2.FormResize(Sender: TObject);
  2501. begin
  2502.    mkrg;
  2503. end;
  2504.  
  2505. //-------------------------------update column sizes
  2506. procedure tform2.fkcolupd;
  2507. var
  2508.    i:integer;
  2509.    g:tdbgridop;
  2510.  
  2511. procedure marks(ii:integer);
  2512. begin
  2513.    if pos(g.Columns[ii].FieldName+' desc', tmp_sortli)<>0 then
  2514.       g.Columns[ii].Title.SortMarker:=smdowneh
  2515.    else
  2516.       if pos(g.Columns[ii].FieldName,tmp_sortli)<>0 then
  2517.          g.Columns[ii].Title.SortMarker:=smupeh;
  2518.       //endif
  2519.    //endif
  2520. end;
  2521.  
  2522. begin
  2523.    g:=rxdbgrid1;
  2524.    if colresize then
  2525.  
  2526.       for i:=0 to g.columns.count-1 do
  2527.          begin
  2528.             if i=0 then
  2529.                g.Columns[i].Width:=1
  2530.             else
  2531.                g.columns[i].width:=50;
  2532.             //endif
  2533.             g.Columns[i].Title.Caption:=
  2534.             '.|'+rxdbgrid1.Columns[i].Title.Caption;
  2535.             g.Columns[i].Title.TitleButton:=true;
  2536.             marks(i);
  2537.          end
  2538.       //endfor
  2539.  
  2540.    else
  2541.       begin
  2542.          i:=0;
  2543.          while (i<length(fkarr)) and (i<g.Columns.Count) do
  2544.             begin
  2545.                g.Columns[i].Width:=fkarr[i];
  2546.                g.Columns[i].Title.Caption:=
  2547.               '.|'+g.Columns[i].Title.Caption;
  2548.                g.Columns[i].Title.TitleButton:=true;
  2549.                marks(i);
  2550.                i:=i+1;
  2551.             end;
  2552.          //wend
  2553.       end;
  2554.    //endif
  2555. end;
  2556.  
  2557.  
  2558.  
  2559. procedure TForm2.ADOQuery1BeforeClose(DataSet: TDataSet);
  2560. var
  2561.    i:integer;
  2562. begin
  2563.    //lokpli.Clear;
  2564.    if rxdbgrid1.Columns.Count<2 then
  2565.       exit;
  2566.    //endif
  2567.  
  2568.    setlength(fkarr,0);
  2569.    for i:=0 to rxdbgrid1.columns.Count-1 do
  2570.       begin
  2571.          setlength(fkarr, length(fkarr)+1);
  2572.          fkarr[length(fkarr)-1]:=rxdbgrid1.Columns[i].Width;
  2573.       end;
  2574.    //endfor
  2575. end;
  2576.  
  2577.  
  2578. //----------------------------------------------------------------
  2579. //        clone active form
  2580. //----------------------------------------------------------------
  2581. {procedure tform2.cloneme;
  2582. var
  2583.    clf:tform2;
  2584.    ms:tmemorystream;
  2585.  
  2586. begin
  2587.    ms:=tmemorystream.Create;
  2588.    try
  2589.       ms.WriteComponent(self);
  2590.       clf:=tform2.CreateNew(application);
  2591.       ms.position:=0;
  2592.       ms.ReadComponent(clf);
  2593.       clf.Show;
  2594.    finally
  2595.       ms.Free;
  2596.    end;
  2597. end;}
  2598.  
  2599. //----------------------------------------------------chr(13)chr(10)
  2600. function tform2.noad(instr:string):string;
  2601. var
  2602.    adpo:integer;
  2603.  
  2604. begin
  2605.    adpo:=pos(chr(13),instr);
  2606.    while adpo<>0 do
  2607.       begin
  2608.          instr:=copy(instr,1,adpo-1)+'#%13%#'+copy(instr,adpo+1,length(instr)-adpo);
  2609.          adpo:=pos(chr(13),instr);
  2610.       end;
  2611.    //wend
  2612.    adpo:=pos(chr(10),instr);
  2613.    while adpo<>0 do
  2614.       begin
  2615.          instr:=copy(instr,1,adpo-1)+'#%10%#'+copy(instr,adpo+1,length(instr)-adpo);
  2616.          adpo:=pos(chr(10),instr);
  2617.       end;
  2618.    //wend
  2619.    result:=instr;
  2620. end;
  2621. //----------------------------------------------------chr(13)chr(10)
  2622. function tform2.adno(instr:string; goo:boolean):string;
  2623. var
  2624.    adpo:integer;
  2625.  
  2626. begin
  2627.    adpo:=pos('#%13%#',instr);
  2628.    while adpo<>0 do
  2629.       begin
  2630.          if goo then
  2631.             instr:=copy(instr,1,adpo-1)+' '+copy(instr,adpo+6,length(instr)-adpo-5)
  2632.          else
  2633.             instr:=copy(instr,1,adpo-1)+chr(13)+copy(instr,adpo+6,length(instr)-adpo-5);
  2634.          //endif
  2635.          adpo:=pos('#%13%#',instr);
  2636.       end;
  2637.    //wend
  2638.    adpo:=pos('#%10%#',instr);
  2639.    while adpo<>0 do
  2640.       begin
  2641.          if goo then
  2642.             instr:=copy(instr,1,adpo-1)+' '+copy(instr,adpo+6,length(instr)-adpo-5)
  2643.          else
  2644.             instr:=copy(instr,1,adpo-1)+chr(10)+copy(instr,adpo+6,length(instr)-adpo-5);
  2645.          //endif
  2646.          adpo:=pos('#%10%#',instr);
  2647.       end;
  2648.    //wend
  2649.    result:=instr;
  2650. end;
  2651. //--------------------------------------------chr(13)chr(10)space
  2652. function tform2.noad9(instr:string):string;
  2653. var
  2654.    adpo:integer;
  2655.  
  2656. begin
  2657.    adpo:=pos(chr(13),instr);
  2658.    while adpo<>0 do
  2659.       begin
  2660.          instr:=copy(instr,1,adpo-1)+''+copy(instr,adpo+1,length(instr)-adpo);
  2661.          adpo:=pos(chr(13),instr);
  2662.       end;
  2663.    //wend
  2664.    adpo:=pos(chr(10),instr);
  2665.    while adpo<>0 do
  2666.       begin
  2667.          instr:=copy(instr,1,adpo-1)+''+copy(instr,adpo+1,length(instr)-adpo);
  2668.          adpo:=pos(chr(10),instr);
  2669.       end;
  2670.    //wend
  2671.    adpo:=pos(chr(32),instr);
  2672.    while adpo<>0 do
  2673.       begin
  2674.          instr:=copy(instr,1,adpo-1)+''+copy(instr,adpo+1,length(instr)-adpo);
  2675.          adpo:=pos(chr(32),instr);
  2676.       end;
  2677.    //wend
  2678.    result:=instr;
  2679. end;
  2680.  
  2681.  
  2682.  
  2683. //----------------------------------------execute command
  2684. procedure tform2.execomm(incom:string);
  2685. var
  2686.    i:integer;
  2687.    coll,lcoll:integer;  
  2688.    //fkmass:array of integer;
  2689.  
  2690. begin
  2691.    //----------------inside commands
  2692.    if (incom='noresize') then
  2693.       begin
  2694.          colresize:=false;
  2695.          exit;
  2696.       end;
  2697.    //endif
  2698.    if (incom='resize') then
  2699.       begin
  2700.          colresize:=true;
  2701.          exit;
  2702.       end;
  2703.    //endif
  2704.    if (incom='refr') then
  2705.       begin
  2706.          if assigned(refr) then
  2707.             exit;
  2708.          //endif
  2709.          colresize:=false;
  2710.          refr:=trefr.create(false,self);
  2711.          exit;
  2712.       end;
  2713.    //endif
  2714.    if (incom='norefr') then
  2715.       begin
  2716.          colresize:=true;
  2717.          if not assigned(refr) then
  2718.             exit;
  2719.          //endif
  2720.          with refr do
  2721.             begin
  2722.                Terminate;
  2723.                waitfor;
  2724.             end;
  2725.          //endwith
  2726.          freeandnil(refr);
  2727.          exit;
  2728.       end;
  2729.    //endif
  2730.  
  2731.    termrefr;
  2732.    adoquery1beforeclose(nil); //clear list combo
  2733.    //lokpli.Clear;
  2734.    for i:=0 to lokpli.Count-1 do
  2735.       begin
  2736.          tcofi(lokpli.Items[i]).isact:=false;
  2737.          tcofi(lokpli.Items[i]).co.Visible:=false;
  2738.       end;
  2739.    //endfor          
  2740.  
  2741.    coll:=rxdbgrid1.Col;
  2742.    lcoll:=rxdbgrid1.leftcol;
  2743.  
  2744.    //sendmessage(memo1.Handle,WM_SETREDRAW,0,0);
  2745.    is_upd:=true;
  2746.  
  2747.    rxdbgrid1.columns.clear;
  2748.    rxdbgrid1.DataSource:=nil;
  2749.  
  2750.    //bu.wrln('checkpoint 3');
  2751.    adoquery1.Close;
  2752.  
  2753.    try
  2754.       adoquery1.sql.text:=incom;
  2755.       adoquery1.open;
  2756.       //statusstr:=q
  2757.       if length(txtout)>0 then
  2758.          txtout[0]:='refr ok';
  2759.       //endif
  2760.    except
  2761.       on e: exception do
  2762.       begin
  2763.          statusstr:=e.Message;
  2764.          shopo9;
  2765.          //memofo(statusstr);
  2766.          //messagebox(handle,pansichar(e.message),'sys',0);
  2767.          //tmps:=e.Message;
  2768.          is_upd:=false;
  2769.          //exit;
  2770.          {messagebox(handle,pansichar(tmps+chr(13)+'--------------'+chr(13)+
  2771.          noad(adoquery1.SQL.text)),'sys',MB_ICONINFORMATION or MB_OK);}
  2772.          raise exception.Create('exec terminated');
  2773.       end;
  2774.    end;
  2775.  
  2776.    rxdbgrid1.DataSource:=datasource1;
  2777.  
  2778.  
  2779.  
  2780.    rxdbgrid1.Col:=coll;
  2781.    rxdbgrid1.LeftCol:=lcoll;
  2782.  
  2783.                      //ftg .
  2784.    //bu.wrln('checkpoint 1');
  2785.    fkcolupd;
  2786.  
  2787.    //updfilters;
  2788.    for i:=0 to rxdbgrid1.Columns.Count-1 do
  2789.       begin
  2790.          if lokpli.Count<(i+1) then
  2791.             lokpli.Add(tcofi.create(adoconnection1,rxdbgrid1,bu,self));
  2792.          //endif
  2793.          tcofi(lokpli.Items[i]).inico(i);
  2794.       end;
  2795.    //endfor
  2796.    {rxdbgrid1.invalidate;
  2797.    for i:=0 to rxdbgrid1.ControlCount-1 do
  2798.       begin
  2799.          rxdbgrid1.Controls[j].Invalidate;
  2800.       end;
  2801.    //endfor }
  2802.  
  2803.  
  2804.    is_upd:=false;
  2805.    
  2806.    //sendmessage(memo1.Handle,WM_SETREDRAW,1,0);
  2807.  
  2808.    //memo2.clear;
  2809.    for i:=0 to rxdbgrid1.columns.count-1 do
  2810.       begin
  2811.          //memo2.lines.add(rxdbgrid1.columns[i].title.caption);
  2812.       end;
  2813.    //endfor
  2814. end;
  2815. //----------------------------------------------show error message
  2816. procedure tform2.shopo9;
  2817. begin
  2818.    pom9.cleara;
  2819.    pom9.appitem(statusstr,1,nil,1);
  2820.    pom9.popup(100,100,550);
  2821. end;
  2822.  
  2823.  
  2824. //----------------------------------------------------------------
  2825. //           ADO QUERY
  2826. //----------------------------------------------------------------
  2827. procedure TForm2.Button1Click(Sender: TObject);
  2828. var
  2829.    i,j:integer;
  2830.    //tmpo:integer;
  2831.    comms:tstringlist;
  2832.    tmpstr:string;
  2833.  
  2834. begin
  2835.    comms:=tstringlist.Create;
  2836.    tmpstr:=noad(memo1.Text);
  2837.    i:=pos(';',tmpstr);
  2838.    while i<>0 do
  2839.       begin
  2840.          comms.Add(copy(tmpstr,1,i-1));
  2841.          tmpstr:=copy(tmpstr,i+1,length(tmpstr)-i);
  2842.          i:=pos(';',tmpstr);
  2843.       end;
  2844.    //wend
  2845.    try
  2846.    for i:=0 to comms.Count-1 do
  2847.       begin
  2848.          if comms[i]='clone' then
  2849.             begin
  2850.                tmpstr:=application.exename+' "'+in_server+';';
  2851.                for j:=i+1 to comms.Count-1 do
  2852.                   tmpstr:=tmpstr+comms[j]+';';
  2853.                //endfor
  2854.                tmpstr:=tmpstr+'"';
  2855.                winexec(pansichar(tmpstr),0);
  2856.                break;
  2857.             end
  2858.          else
  2859.             execomm(comms[i]);
  2860.          //endif
  2861.       end;
  2862.    //endfor
  2863.    except end;
  2864.    comms.Free;
  2865. end;
  2866.  
  2867. //--------------------------------------------------------
  2868. //          updating filters state
  2869. //--------------------------------------------------------
  2870. procedure tform2.updstate(sender:tobject);
  2871. var
  2872.    i:integer;
  2873.    f:tcofi;
  2874.    s,a:string;
  2875.    dtp:integer;
  2876.  
  2877. begin
  2878.    s:='';
  2879.    //bu.wrr('updstate',40);
  2880.    for i:=0 to lokpli.Count-1 do
  2881.       begin
  2882.          f:=tcofi(lokpli[i]);
  2883.          if not(f.qu.active) then
  2884.             continue;
  2885.          //endif
  2886.          if f.co.Value<>null then
  2887.             begin
  2888.                if s='' then
  2889.                   s:=' where '
  2890.                else
  2891.                   s:=s+' and ';
  2892.                //endif
  2893.                dtp:=dtype(f.qu.FieldByName(f.co.keyfield));
  2894.                if (dtp=0) or (dtp=3) then
  2895.                   try
  2896.                      a:=chr(39)+f.co.value+chr(39)
  2897.                   except
  2898.                      a:=chr(39)+inttostr(f.co.value)+chr(39);
  2899.                   end
  2900.                else
  2901.                   if dtp=1 then
  2902.                      a:=inttostr(f.co.Value)
  2903.                   else
  2904.                      if dtp=2 then
  2905.                         a:='to_date('+chr(39)+datetimetostr(f.co.value)+chr(39)+','+
  2906.                         chr(39)+'dd.mm.yyyy HH24:MI:ss'+chr(39)+')';
  2907.                      //endif
  2908.                   //endif
  2909.                //endif
  2910.                s:=s+'"'+f.co.KeyField+'"='+a;
  2911.             end;
  2912.          //endif
  2913.       end;
  2914.    //endfor
  2915.    tmp_filst:=s;
  2916.    chaque;
  2917.  
  2918.  
  2919. end;
  2920.  
  2921.  
  2922. //--------------------------------------------------------
  2923. //     combo boxes dropdown and closeup
  2924. //--------------------------------------------------------
  2925. procedure tform2.closup(Sender: TObject; Accept: Boolean);
  2926. begin
  2927.    updstate(sender);
  2928.    lock_upd:=false;
  2929. end;
  2930. //-----------------------------------
  2931. procedure tform2.cmbcle(sender: tobject);
  2932. var
  2933.   co:tdlo;
  2934. begin
  2935.    co:=(sender as tdlo);
  2936.    co.Value:=null;
  2937.    //co.Tag:=5;
  2938.    updstate(sender);
  2939. end;
  2940. //-----------------------------------
  2941. procedure tform2.cmbbdo(sender:tobject;topbutton:boolean;
  2942.      var autorepeat:boolean; var handled:boolean);
  2943. var
  2944.    co:tdlo;
  2945.    qu:tadoquery;
  2946.    tms,tmp_filst3:string;
  2947.    po,po3,po4:integer;
  2948.    tmf:string;
  2949.  
  2950.  
  2951. begin
  2952.    if sender is tdlo then
  2953.       co:=sender as tdlo
  2954.    else
  2955.       co:=(sender as tcontrol).parent as tdlo;
  2956.    //endif
  2957.  
  2958.    qu:=(co.listsource.dataset as tadoquery);
  2959.    {if co.Tag=5 then
  2960.       begin    }
  2961.          qu.DisableControls;
  2962.          qu.Close;
  2963.          tms:=co.ListField;
  2964.          po:=pos('where',tmp_filst);
  2965.          //---------------------
  2966.          if po<>0 then
  2967.             tmp_filst3:=' and'+copy(tmp_filst,po+5,length(tmp_filst)-po-4)
  2968.          else
  2969.             tmp_filst3:=tmp_filst;
  2970.          //endif
  2971.  
  2972.          po3:=0;
  2973.          po4:=0;
  2974.          tmf:=tmp_filst3;
  2975.          po:=pos(tms,tmp_filst3);
  2976.          if po<>0 then
  2977.             begin
  2978.                po3:=pos('and',copy(tmp_filst3,1,po-1));
  2979.                po4:=pos('and',copy(tmp_filst3,po+length(tms),
  2980.                length(tmp_filst3)-po-length(tms)+1));
  2981.             end;
  2982.          //endif
  2983.          if po3<>0 then
  2984.             begin
  2985.                if po4=0 then
  2986.                   tmf:=copy(tmp_filst3,1,po3-1)
  2987.                else
  2988.                   begin
  2989.                      po4:=po4+po+length(tms)-1;
  2990.                      tmf:=copy(tmp_filst3,1,po3-1)+' '+
  2991.                      copy(tmp_filst,po4,length(tmp_filst3)-po4+1);
  2992.                   end;
  2993.                //endif
  2994.             end;
  2995.          //endif
  2996.  
  2997.          if pos('SQLNCLI',qu.connection.ConnectionString)<>0 then
  2998.             qu.SQL.text:='select '+tms+' from ('+tmp_baseq+') as a '+
  2999.             'where 6=6 '+tmf+' group by '+tms+' order by 1'
  3000.          else
  3001.             qu.SQL.text:='select '+tms+' from ('+tmp_baseq+') '+
  3002.             'where 6=6 '+tmf+' group by '+tms+' order by 1';
  3003.          //endif
  3004.          //bu.wrln(qu.SQL.text);
  3005.          qu.Open;
  3006.          qu.EnableControls;
  3007.          handled:=false;
  3008.      { end
  3009.    else
  3010.       handled:=false;  }
  3011.    //endif
  3012. end;
  3013.  
  3014. procedure tform2.dropdon(Sender: TObject);
  3015. begin
  3016.    lock_upd:=true;
  3017. end;
  3018.  
  3019.  
  3020.  
  3021.  
  3022. //----------------------------------------------------------------
  3023. //           DETAIL
  3024. //----------------------------------------------------------------
  3025. procedure TForm2.Button2Click(Sender: TObject);
  3026. var
  3027.    i:integer;
  3028.    j:integer;
  3029.    tmp_str:string;
  3030.    tmpquery:TDataSet;
  3031.    fou:tfilestream;
  3032.  
  3033.  
  3034.  
  3035. //-------------------------------create process  
  3036. procedure createpro;
  3037. var
  3038.    stainf:tstartupinfo;
  3039.    rist:longbool;
  3040.    proinf:tprocessinformation;
  3041.    err:integer;
  3042.  
  3043. begin
  3044.    fillchar(stainf, sizeof(stainf),0);
  3045.    with stainf do
  3046.       begin
  3047.          cb:=sizeof(stainf);
  3048.          dwflags:=STARTF_USESHOWWINDOW or
  3049.          STARTF_FORCEONFEEDBACK;
  3050.          wShowWindow:=SW_SHOWNORMAL;
  3051.       end;
  3052.    //endwith
  3053.    Rist:=createprocess(nil,
  3054.    'notepad c:\temp\ftg.txt', //commandline
  3055.    nil,//securityattributes
  3056.    nil,//threadattributes
  3057.    false,//have inherited handles
  3058.    NORMAL_PRIORITY_CLASS,//creation flags
  3059.    nil,//lpenvironment
  3060.    nil,//lpcurrentdirectory
  3061.    stainf, proinf);
  3062.  
  3063.    if Rist then
  3064.       with proinf do
  3065.          begin
  3066.             Waitforinputidle(hProcess,INFINITE);
  3067.             closeHandle(hThread);
  3068.             closeHandle(hProcess);
  3069.          end
  3070.       //endwith
  3071.    else
  3072.       Err:=GetLastError;
  3073.    //endif
  3074.    //bu.wrln(err);
  3075.  
  3076.          
  3077. end;
  3078.  
  3079. begin
  3080.    if not(directoryexists('c:\temp')) then
  3081.       mkdir('c:\temp');
  3082.    //endif
  3083.    fou:=tfilestream.Create('c:\temp\ftg.txt', fmcreate);
  3084.  
  3085.    tmpquery:=(adoquery1 as TADOQuery);
  3086.    for i:=0 to tmpquery.FieldCount-1 do
  3087.       begin
  3088.          try
  3089.          tmp_str:=tmpquery.fields[i].fieldname;
  3090.          for j:=1 to 30-length(tmp_str) do
  3091.             tmp_str:=tmp_str+' ';
  3092.          //endfor
  3093.          tmp_str:=tmp_str+tmpquery.fields[i].asstring+chr(13)+chr(10);
  3094.  
  3095.          fou.WriteBuffer(pchar(tmp_str)^,length(tmp_str))
  3096.  
  3097.          //ftgform3.memo1.lines.add(tmp_str);
  3098.          except end;
  3099.       end;
  3100.    //endfor
  3101.    fou.Free;
  3102.    //winexec('notepad c:\temp\ftg.txt',SW_SHOWNORMAL);
  3103.    createpro;
  3104. end;
  3105.  
  3106.  
  3107.  
  3108.  
  3109. procedure TForm2.RxDBGrid1ColWidthsChanged(Sender: TObject);
  3110.  
  3111. begin
  3112.    //bu.wrln('colwid');
  3113.    updfilters;
  3114. end;
  3115.  
  3116. procedure TForm2.RxDBGrid1DblClick(Sender: TObject);
  3117. begin
  3118.    button2click(nil);
  3119. end;
  3120.  
  3121.  
  3122.  
  3123. //-------------------------------------------------------------
  3124. //         recalc filter positions
  3125. //-------------------------------------------------------------
  3126. procedure tform2.updfilters;
  3127. var
  3128.    i:integer;
  3129. begin
  3130.    if is_upd then
  3131.       exit;    
  3132.    //endif
  3133.    //bu.wrln('---->');
  3134.    //lockwindowupdate(rxdbgrid1.Handle);
  3135.    if assigned(lokpli) then
  3136.       for i:=0 to lokpli.Count-1 do
  3137.          tcofi(lokpli[i]).upfipo;
  3138.       //endfor
  3139.    //endif
  3140.    //lockwindowupdate(0);
  3141. end;
  3142.  
  3143. procedure TForm2.RxDBGrid1HScro(rez_val: Integer);
  3144. begin
  3145.    //bu.wrln('hscro');
  3146.    updfilters;
  3147. end;
  3148.  
  3149. //----------------------------------------------------------------
  3150. //   copy grid to export to excel
  3151. //----------------------------------------------------------------
  3152. procedure TForm2.gricop4excel;
  3153. begin
  3154.    rxdbgrid1.SelectedRows.SelectAll;
  3155.    dbgrideh_docopyaction(rxdbgrid1,false);
  3156. end;
  3157.  
  3158.  
  3159. //----------------------------------------------override default handler
  3160. procedure tform2.DefaultHandler(var message);
  3161. begin
  3162.    with tmessage(message) do
  3163.       begin
  3164.          if msg=KICKM then
  3165.             close
  3166.          else
  3167.             inherited defaulthandler(message);
  3168.          //endif
  3169.       end;
  3170.    //endwith
  3171. end;
  3172.  
  3173. initialization
  3174.    KICKM:=registerwindowmessage('kickmnutproj');
  3175.  
  3176. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement