通用方法代码

//全屏窗口:

  with MainForm do

  begin

    { Position form }

    Top := 0 ;

    Left := 0 ;

    { Go full screen}

    BorderStyle := bsNone ;

    WindowState := wsmaximized;

    ClientWidth := Screen.Width ;

    ClientHeight := Screen.Height;

    Refresh;

   SetForegroundWindow(Handle) ;

   SetActiveWindow(Application.Handle) ;

  end;


// 动态加载image 图片

var

  jpg: TJPEGImage; // 要use Jpeg单元

begin

  // 最大化

  Ima_back.Align:= alClient;

  // 显示jpg大图片的方式

  jpg := TJPEGImage.Create;

  jpg.LoadFromFile(getcurrentdir() + '\back.jpg');

  Ima_back.Picture.Bitmap.Assign(jpg); // 因为 img 控件是基于bmp的

  jpg.Free;

end;


//控件居中

lbHead.Left := round((Width - 8 - lbHead.Width) / 2); //常量8用于处理边界问题 

lbHead.Top := round((Height - 8 - lbHead.Height) / 2);  // 垂直居中

 

// 位置大小 按比例缩放

Button1.Left:=round(left*clientwidth/fwidth);   

Button1.Top:=round(top*clientheight/fheight);  

------

// 所有控件随着比例变化

//定义全局变量  OldWidth:Integer;

procedure TForm1.FormResize(Sender: TObject);

begin

  form1.ScaleBy(Self.Width,OldWidth);

  OldWidth:=Self.width;

end;

------

procedure TForm1.FormShow(Sender: TObject);

begin

  OldWidth:=Self.width;

end;

 


// 只允许输入数字

  if not (key in ['0'..'9',#8]) then

    key := #0;


// 有小数位进1 

Ceil(21.1)

// 设置Panel 圆角   fhr :Thandle;

fhr:=createroundrectrgn(0,0,pl_hint.width,pl_hint.height,10,10);

 setwindowrgn(pl_hint.handle,fhr,true);


  // 多个按钮公用事件  , 分别设置按钮Tag属性 

  case (Sender as TcxButton).Tag of

    1: fdTitle.Execute();

    2: fdHint.Execute();

    3: fdGrid.Execute();

    4: fdChart.Execute();

    5: fdNote.Execute();

    6: fdMemo.Execute();

  end;


// ADO 存储过程

ADOStoredProc1.close; 
ADOStoredProc1.parameters.parambyname(’@dwmc’).value:=’
某某单位’;   
ADOStoredProc1.prepared:=true; 
ADOStoredProc1.open; 
label1.caption:=  ADOStoredProc1.fields[0].asstring;


// dbGrideh 控件属性

    Config.edTHeight.Text := IntToStr(dbGrid.TitleParams.RowHeight);  // 表头高

    Config.fdGridT.Font :=  dbGrid.TitleFont; // 表头字体

    Config.ColorT.ColorValue :=  dbGrid.FixedColor; // 表头颜色

    Config.edRHeight.Text := IntToStr(dbGrid.RowHeight);    // 行高

    Config.fdGridI.Font := dbGrid.Font;   // 表内字体

    Config.Color1.ColorValue :=  dbGrid.OddRowColor; // 奇数行颜色

    Config.Color2.ColorValue :=  dbGrid.EvenRowColor; // 偶数行颜色

 

//  dbGridEh 字体居中

var
  Count: integer;
begin
  for Count:=0 to DBGrid1.Columns.Count-1 do
  begin
   DBGrid1.Columns[Count].Title.Alignment := taCenter;
   DBGrid1.Columns[Count].Alignment := taCenter;
  end;
end;


   

=============================

// 截取字符

如果要使用LeftStr,RightStr,MidStr必需引用系统单元StrUtils;

copy(s,1,10) 

// UNI 控件  需要引用  SQLServerUniProvider 单元

RecordCount QUERY 行数


// 获取文件名,不带后缀名

var

  fFileName:String;

  fLenExt:Integer;

begin

  // 打开选择的发织单文件

  OpenD.Execute();

 

  fFileName :=  ExtractFileName(OpenD.FileName);

  fLenExt :=  length(ExtractFileExt(OpenD.FileName));

  fFileName := Copy(fFileName,1, length(fFileName)- fLenExt);

  //

  edCodeIn.Text :=  fFileName;


//  TkbmMemTable   

    保存文件 :  aKbmMem.SaveToFileViaFormat( aFileName, self.kbmMWJSONStreamFormat1 );   // 需要添加kbmMWJSONStreamFormat1 控件

 

// 打开文件

procedure TfrmMain.OpenMemTable;

var

  mt: TkbmMemTable;

begin

 

  // 打开临时表

  if not mt_keylist.Active then

  begin

 

    // 从文件中装入

    if FileExists(fDataFileName) then

    begin

 

      if not mt_keylist.Active then

       mt_keylist.Open;

 

      mt := TkbmMemTable.Create(nil);

     try

 

       // 装入文件

       mt.CreateTableAs(mt_keylist, [mtcpoStructure, mtcpoProperties,

         mtcpoAppend, mtcpoFieldIndex, mtcpoDontDisableIndexes,

         mtcpoIgnoreErrors]);

       // mtcpoStringAsWideString,mtcpoWideStringUTF8]);

       mt.Open;

       mt.LoadFromFileViaFormat(fDataFileName, sfCSV); // kbmCSVStreamFormat1);

 

       // mt.LoadFromFile(fDataFileName);

 

       //

       // mt.CopyRecords( mt, mt_keylist, mt.RecordCount, False, False );

       // mt_keylist.LoadFromFile( fDataFileName );

 

       // mt_keylist.Indexes.Clear;

       mt.CopyRecords(mt, mt_keylist, mt.RecordCount, False, '', True);

 

       //

       mt.Close;

     finally

       mt.Free;

      end; // try

 

    end; // if

 

    // 打开

    if not mt_keylist.Active then

     mt_keylist.Open;

 

    // 都不要选中

    mt_keylist.First;

   mt_keylist.DisableControls;

    try

 

     mt_keylist.Filtered := False;

     mt_keylist.Filter := '';

      while not mt_keylist.Eof do

     begin

 

       mt_keylist.Edit;

       mt_keylistcSelected.AsBoolean := False;

       mt_keylist.Post;

 

       mt_keylist.Next;

 

      end; // while

 

    finally

     mt_keylist.EnableControls;

    end; // try

 

  end; // if

 

end;


 

//三个函数引用自SysUtils单元  // 判断文件是否存在 //创建文件夹

FileExists(Path)检查目录是否存在function FileExists(const FileName: string): Boolean; 
DirectorysExists(Path)创建目录function DirectoryExists(const Directory: string): Boolean; 
CreateDirectory(Path)创建目录function ForceDirectories(Dir: string): Boolean; 
ForceDirectories(Path)创建目录 
CreateDirectory(Path)创建目录 
forcedirectories和CreateDirectory都能创建文件 
ForceDirectories可以创建多层目录.  
如果你创建一个目录为c:\mymusic\music  
如果你的C盘不存在一个叫mymusic的文件夹  
的话程序会自动创建,函数执行的结果是,  
创建了两个文件夹,mymusic和music,music为  
mymusic的子文件夹.  

CreateDirectory只能创建一个文件夹,如果  
mymusic不存在,则反回创建music文件夹失败! 

// 获取文件名

x:=ExtractFileName(str);  //取文件名+扩展名,不包含文件路径
 y:=ExtractFileExt(str);   //取文件的扩展名

 


// TStringList 加载文件, 自动分割字符串

var

  icount :integer;

  sl1,sl2 :TStringList;

  i,j :integer;

  li :TListItem;

 

if FileExists('eml.txt') then

  begin

 

  // 加载邮件

    sl1 := TStringList.Create;

    try

     sl1.LoadFromFile('eml.txt');

      for i := 0 to sl1.Count - 1 do

     begin

       sl2 := TStringList.Create;

       try

        //SplitColumns(sl1.Text,sl2,'‖');

         sl2.StrictDelimiter := True ;  // 不允许空格为分隔符

         sl2.Delimiter := '‖';

         sl2.DelimitedText := sl1.Strings[i];

         li := lvMail.Items.Add;

         li.Caption := sl2.Strings[0];

         for j := 1 to sl2.Count - 1 do

          li.SubItems.Add(sl2.Strings[j]);

       finally

         FreeAndNil(sl2);

       end;

     end;

    finally

     FreeAndNil(sl1);

    end;

 

  end;


//TWebBrowser 操作 

web.stop; //停止

 web.Navigate('about:blank');   // 空页面

            while web.ReadyState < READYSTATE_INTERACTIVE do

             Application.ProcessMessages;

            if Assigned(web.Document) then

             web.OleObject.Document.Writeln( _Data_Mail.idMessage1.Body.Text );   // 写入内容


//  查询数据窗口

 

procedure TeQryProgressNJ.InitVariable;  

begin

 

  // 初始化数据集

 _DataConnect.InitDataSet(ep_progress_fty);

 

  //

  inherited;

 

  //哪一页, 放的是哪个数据集

  glMasterGrid.Tag := xClasses.setTagValue( glMasterGrid.Tag, 0, ttIndex ); {放第0个}

  glProgress.Tag := xClasses.setTagValue( glProgress.Tag, 0, ttIndex ); {放第0个}

 

end;

 

//  GUI  激活设置页面

dgMaster.ActiveLevel := glProgress;

 

// 所有参数必须赋值 SetMasterParams;

 with self.dsMaster.Params do

  begin

 

    //1 - 日期类型

    ParamByName( 'pDateKind' ).AsInteger := 0;

 

    //获取日期范围

    GetDateTimeBound( fBeginDateTime, fEndDateTime );

    ParamByName( 'pSysBeginDate' ).Value := fBeginDateTime;

    ParamByName( 'pSysEndDate' ).Value := fEndDateTime;

end  // with

 

//  设置可编辑数据,不能编辑的栏位变成灰色  procedure SetViewOnly( const Value: Boolean ); override;

procedure TeQryProgressNJ.SetViewOnly(const Value: Boolean);

var

  i: Integer;

begin

 

  inherited;

 

  tvProgress.BeginUpdate;

 

  tvProgress.OptionsData.Editing := not Value;

  for i := 0 to tvProgress.ColumnCount - 1 do

  begin

    //

    tvProgress.Columns[ i ].Options.Editing := not tvProgress.Columns[ i ].DataBinding.Field.ReadOnly;

    // 变颜色

    if (not Value) and (not tvProgress.Columns[i].Options.Editing) then

     tvProgress.Columns[i].Styles.Content := _DataProj.ReadOnlyStyle

    else

     tvProgress.Columns[i].Styles.Content := nil;

  end; //for

 

  tvProgress.EndUpdate;

 

 

end;


// 执行临时SQL查询语句 OpenQryA

_DataComm.OpenQryE( Format( _SQL_MailUser,[ xUserManager.UserID ] ) );

  with _DataComm.qryE do

  begin

    //

  end;

 


// 报表相关事件

procedure SetReportDataSet(); override; // 设置报表数据集

procedure OnLoadReport ( const AReportName: string ); override;  // 打开报表

procedure OnCloseReport( const AReportName: string ) ; override;   // 关闭报表

 

_DataReport.TempDataSet.DataSet := _DataK.kp_qrydayofdept;

 


// cxGrid 条件颜色

if AViewInfo.GridRecord.Values[tvMasterGridxState.Index] = 2 then

  begin

       ACanvas.Canvas.Brush.Color:=$00D2CEF9;  // 作废

      // ACanvas.Font.Color:=clFuchsia;

      //  ACanvas.canvas.Font.Color:=clblack;

  end else

  if AViewInfo.GridRecord.Values[tvMasterGridxIsRework.Index] = 1 then

    ACanvas.Canvas.Brush.Color:=$00CEEDF0;  // 返工

// 布尔类型必需加上

if not VarIsNull(AViewInfo.GridRecord.Values[tvMasterGridxIsRework.Index]) then

 

 

// 使用现有颜色 Style  ( OnGetContentStyle 事件 )

  if not VarIsNull(ARecord.Values[tvMasterGridxState.Index]) then

  begin

 

    if ARecord.Values[tvMasterGridxState.Index] = 2 then

     AStyle := _DataProj.ErrorStyle;

 

  end;

 


// 浏览界面加载选择窗口

 fOrderNO := xDBCommon.ShowDataLookupForm( TeOrderLookup, nil, 'xOrderNO', 'xOrderNO',

    'xOrderNO', et_card_view_OrderNo.AsWideString );

 

  edOrderNo.Text := fOrderNO;

 


//  打开编辑窗口,并触发事件

xDBCommon.ShowModalEditForm( TeFlowCardEdit, et_card_viewsID.AsInteger, self.Caption + '-[返工]', xDBClasses.etModify, OnEditReWork ); 

{ 参数说明: 编辑窗体名; 关键字; 标题; 打开方式(只读,新增,修改);事件 }  onEditRework 在本窗口编写:

procedure OnEditReWork( Sender: TObject ); 

   if Sender is TeFlowCardEdit then

   TeFlowCardEdit( Sender ).fReWork := 1;

 

 


//浏览界面

//如果是多页,必须这样初始化

  self.InitDataSetList( [

    _DataH.ht_empl_view, _DataH.hp_qryemplsimple, 

   _DataH.hp_qryempladdresslist, _DataH.hp_qryEmplChart ]

    );


//复制并新增记录

    procedure CopyAndAppendRecord( const ADataSet: TDataSet; const ANewCount: Integer = 1 );

 

CopyAndAppendRecord( _DataT.tt_packinglist_item, 1 ); // 复制一条明细


// 数值类型显示中文

 

浏览界面

1. 设置字段Properties 属性为ImageComboBox .

2. // 添加中文数组变量如:   _Dept_Type: array[0..2] of string = ('部门', '车间', '小组');

3.返回窗口单元设置初始化参数 调用类别代码 { _Dept_Type, tvMasterGridxType =控件字段名}

    xCxVCLUtils.FillImageComboBox( _Dept_Type, TcxImageComboBoxProperties( tvMasterGridxType.Properties ).Items );

// 调用方式: procedure FillImageComboBox( const AStringArray: array of string; AItems: TcxImageComboBoxItems ; const ALowIs0: Boolean = False );     ALowIs0  是否从0开始!

 

明细表显示中文

xEhVCLUtils.FillGridColumnsEh(  _Dept_Type, dgDetail.FieldColumns['xType'] );


//  下拉列表 显示中文  使用控件(TcxDbImageComboBox),    

    // 数组填充

   xcxVclutils.FillImageComboBox( xDBConstEmail._MailKind, edKind.Properties.Items );   {edKind = 控件名}

 

// 使用SQL插入到COMBOBOX控件列表 (edFactCode 控件名)

    xDBCommon.FillStringsBySQL( xSQLConstU._SQL_Get_FactoryList, edFactCode.Properties.Items );

---------------------

// 明细加载下拉列表   在GUI 添加下列代码

 

 //单据类型

 xEhVCLUtils.FillGridColumnsEh(xDBConstE._Style_DataType, dgPoList.FieldColumns['xDataType'], 1);

 

//  数组填充

  //xEhVCLUtils.FillGridColumnsEh( xDbConstE._Accessory_Buy_Type, dgDetail.FieldColumns['xBuyType'] );

 

  //  SQL填充

  xDBCommon.FillColumnsEhBySQL( xSQLConstZ._SQL_GET_CURList, dgDetail.FieldColumns['rCUR'] );

 

// 循环加入列表

with _DataComm.qryA do

  begin

    Close;

    Query.Text := Format( xSQLConstT._SQL_GET_ProcEUnitlist,[] );

    Open;

 

    while not Eof do

    begin

     dgDetail.FieldColumns['xBUnit'].KeyList.add(FieldByName( 'xCaption' ).AsString);

     dgDetail.FieldColumns['xBUnit'].PickList.add(FieldByName( 'xCaption' ).AsString);

     next;

    end;

  end;


字段改变时, 填充对应字段

1. 设置SQL查询语句,如打开xSQLConstU 添加下列代码   

    // 通过工厂代码获取工厂名称

   _SQL_Get_FactoryName = 'select sID, xFactName from ht_factory where xFactCode = ''%s'' ';

 

2.  添加 procedure DeptEdit.MasterDatasetOnFieldValueChange(const aField: TField) 代码

   if SameText( aField.FieldName, '_FactCode') then

begin

 QryAssignToMaster( aField, format( xSQLConstU._SQL_GetFactoryName,

 [ aField.AsString ] ), [ 'rFactory_ID','_FactName' ] );

   end


 

//  1. 打开选择窗口 选择数据( ThDeptlookup窗口,MasterDataset主表   )

ShowDataLookupForm( ThDeptlookup, MasterDataset,

// 需要查询结果的字段

'sCode',

// 更新到对应的列,这里与上面的栏位信息要一一对应起来

'_MDeptCode',

// 查找字段,打开查找窗口时,自动将光标移动到找到这个栏位

'sCode',

// 查找字段对应的数值( 这里表示通过部门的代码sCode查询到相应的记录

_DataDemo.ht_dept_MDeptCode.AsString);

-------------------------

 

// 载入窗口附带参数设置

if not ViewOnly then

  begin

  //  1. 打开选择窗口

ShowDataLookupFormEx( TeAllOrderlookup, 

  //主表

MasterDataSet,

// 调取的参数 

'sID',

// 填充的参数

'rSale_ID', 

// 查找的关键字段

'sID',

// 对应查找的字段

_DataDemo.et_packingrSale_ID.AsInteger, 

// 传入的参数

VarArrayOf([ 1,MasterDataSet.FieldByName('rCust_ID').AsInteger ]));

  end;

 

 


// 动态创建TAB 页面  ,将查询结果创建到TAB页面

with _DataComm.qryA do

begin

if Active then close;

Query.Text := xSQLConstU._SQL_Get_FactoryList;

open;

 

if not IsEmpty then

begin

while not eof do

begin

  tcMasterTab.Tabs.AddObject( Fields[1].AsString,Tobject( Fields[0].AsInteger) );

  next;

end;

end;

 

    end;


多明细表设置 (在初始化参数内添加下列代码)

 

//设置明细表关键字段值(唯一值) 需引用 xDBClasses 单元

DetailKeyType := ktSystem;

 

//当有多个明细表时,从第二个明细表开始设置 dID的值的生成方式

//ktSystem 表示明细表的dID是唯一的,ktMax默认使用,但是不同的人的dID会重复,不唯一

InitDetaildataSetList([ _DataDemo.ht_empl_work ],[ktSystem]);   // 注意: 从第1个开始 , 0 忽略

 

//显示顺序(设置操作当前明细)  需引用 xClasses 单元  {设置成99 明细编辑控件将无法使用}

tstWork.Tag := setTagValue( tstWork.Tag, 1, ttIndex );//  tstWork 工作经历(TabSheet 名称)

//照片

tsDetailEdit_PIC.Tag := setTagValue( tsDetailEdit_PIC.Tag, 99, ttIndex );

//附件

tsDetailEdit_Accessory.Tag := setTagValue( tsDetailEdit_Accessory.Tag, 99, ttIndex );


设置日期格式 FormatDateTime('yyyy年mm月dd日',now())   ,Date 日期,time时间

通用日期格式 EncodeDate(2000,1,1) 


设置数值格式

EditFormat 编辑格式   DisPlayFormat 显示格式

 

数据集格式设置:

      _DataDemo.zt_customerxTaxRate.EditFormat := '0.##';

 

  _DataDemo.zt_customerxTaxRate.EditFormat  := '0.00'; //NV只要两位

 

 //设置显示格式 - 小数位要显示完整

 NumericFieldDisplayFormat := '0.0000;-0.0000;#';

 NumericFieldEditFormat := '0.00';

 

end;

 


// 有明细数据时不允许修改主表

1. Edit/ OnEditing属性 添加 CxEditOnEditing  事件

 // 不允许编辑

  if not ( _DataT.pt_outprocessrSupp_ID.AsInteger > 0 ) then

  begin

    CanEdit := False;

   MsgBoxI(_STR_NotSuppHint);

  end;

 


// 设置 DBGridEh 根据条件显示不同颜色  添加 OnGetCellParams 事件

 

  // 单价高于默认,或者外发数高出生产单数 改变明细表颜 行颜色

  if Assigned( Column ) and

     ( _DataT.pt_outprocess_itemxPrice1.AsFloat  > _DataT.pt_outprocess_itemxPrice.AsFloat)  then

  begin

    Background := $00D3D3FE;

    //AFont.Color := clWhite;

  end;

  //  单个字段字体颜色

  if Assigned( Column ) and (( Column.FieldName = 'xPrice1' ) and

    ( _DataT.pt_outprocess_itemxPrice1.AsFloat > _DataT.pt_outprocess_itemxPrice.AsFloat)  then

    AFont.Color := clRed;


Lookup 选择窗口从外面传入条件 

// 外面传入

  if VarType( AParamValue ) in [varSmallint, varInteger, varShortInt, varByte, varWord, varLongWord, varInt64] then

  begin

   _DataT.pp_outprocLookup.Params.ParamByName( 'pSupp' ).AsInteger := AParamValue;

  end


多浏览页面明细表 ,双击无法编辑  设置明细表TVMasterGrid2 OnCellDblCick 属性为 tvMasterGridCellDblClick


// 不是编辑状态下不加载窗口退出

if ViewOnly then   exit;


//刷新数据集

self.CallEditDataByKeyValue( _DataT.pt_outprocesssID.AsInteger, True );


// 读写配置文件

var iniFile: TiniFile

begin

// 打开文件(当前目录 + 文件名)

iniFile := TiniFile.Create( GetAppPath + xDBConst._checked_configFile );

 

// 判断目录是否存在

if DirectoryExists(fFileName) then

 

//ExtractFilePath(ParamStr(0))

 

// 写入文件 布尔类型

IniFile.WriteBool( 'Empl', 'cbxIsEmplBase', cbxIsEmplBase.Checked );

 

// 其他类型:String  Integer float  datatime等数据类型  

 

// 读取 布尔类型 (读取不到数据时,默认为True)

cbxIsEmplBase.Checked := IniFile.ReadBool( 'Empl', 'cbxIsEmplBase', True );

 

IniFile.free; // 释放

IniFile.DeleteKey(’小节名’,’关键字’); //删除配置内容 


// 执行SQL语句

_DataComm.ExecSQL( 'exec ep_updateallMoney ' + _DataDemo.et_invoicesid.AsString + ',2' );


 

GetTickCount()

通常用来计算某个操作所使用的时间: 

Start:=GetTickCount; 

...//执行耗时的操作

 

Stop:=GetTickCount; 

TimeUsed:=(Stop-Start)/1000; //使用了xxx秒

 

 

// 延时

sleep (1000) // 延时1秒后向下执行


MEMO 加载文本文件

 fileName:= ‘f:\QuerySql.txt';

  //如果文件存在

  if fileExists(fileName) then

    SQLMemo.Lines.LoadFromFile(fileName);


// 生成单号

fCode := _DataComm.GetCodeValue( 'zt_customer', 'sCode', fPrefix,

       Ord( ctUserPrefix ) );

      if fCode <> '' then

       _DataY.zt_customersCODE.AsString := fCode;


 // 清空明细 (多明细会一起清除)

 DeleteDetailTables(_DataT.tt_packinglist_summID.AsInteger) ;

 

  //清空明细 (循环删除,DBgridEh1=控件名)

  With DBGridEh1.DataSource.Dataset Do

  Try

  DisableControls;

  While not Eof Do Delete;

  Finally

  EnableControls;

  End;


// 多个明细表字段值改变事件  添加 TDataSource  OnDataChange事件

if Assigned( Field ) and ( Field.DataSet.State in [dsInsert, dsEdit] )

    and not DisableOnFieldValueChange  then

  begin

    // 合同明细改变

    if sametext( field.FieldName, 'xNW' ) then

    begin

      // 金额

     _DataT.tt_packinglist_sumxAmount.AsFloat := field.AsFloat * _DataT.tt_packinglist_sumxPrice.AsFloat;

    end;

  end;

 


// 是否关闭系统

CanClose := MsgBoxQ( getmsg('_STR_IsClose') );


 

// 打开浏览窗口 :窗体名,功能名

ShowMDIForm( tep_progress_qry, actep_progress_fty.Caption );


设置cxGrid  左上角自定义显示栏位的 选项

OptionsCustomize - BandsQuickCustomization / ColumnsQuickCustomization


// 查找字符串 返回位置 Pos, PosEx  应用StrUtils 单元

Pos('查找内容','字符') 

PosEx('查找内容','字符','起始位置') 

 

if Pos('查找内容','字符串')  > 0  then  {存在}


// listbox 选中名

ListBox1.Items[ListBox1.ItemIndex]


// TreeView 设置选中状态背景颜色, 失去焦点 保持颜色显示

TreeView有个HideSelection属性,把它设为False。


// 判断当前表是否存在相同记录

  if (not _DataT.tt_Pack_item.Locate( 'xCode',

      VarArrayof( [FieldByName( 'xBox_ID' ).AsInteger] ), [] )) and (FieldByName( 'xQty' ).AsFloat > 0) then


//跳出循环 break  ,

// 如条件成立,进度直接进入下一行 

kmb.next;  

continue; //   如果是 while 循环必需加上,否则不会进入下一条. 


// 浏览窗口改变选项自动查询

self.OnConditionChange(Sender);

  actQuery.Execute;


捕获异常

try

    //

except

    on E: Exception do
end;
 

// CheckListBox 用法 

for i := CheckListBox1.Items.Count-1 downto 0 do  //从后面往前面删
   begin
   if CheckListBox1.Checked[i] then  // 是否选中
      begin
         CheckListBox1.Items.Delete(i);
      end;
   end;

 

获取选中的名称: clbCol.Items[clbCol.ItemIndex]  


// 树形下拉列表   (TcxDBLookupComboBox  控件)

1. 添加数据集 

2. 打开数据集

procedure    OpenDept_Lookup;

begin

  //

  if not zt_dept_lookup.Active then

   zt_dept_lookup.Open;

end;

3. 在编辑窗体初始化内 调用打开代码 ,  _Data.OpenDept_Lookup;

4. 设置  编辑下拉控件 HelpKeyword属性为: @zt_dept_lookup   , helpType为  htKeyword

5. 设置Properties - ListSource 属性为 _Data.desDeptList; 

    keyFieldNames 为 sID   , 添加ListColumns 字段

 


// 替换所有空格

reHint.Lines.Text := StringReplace(reHint.Lines.Text, #13#10, ' ', [rfReplaceAll]);


// 设置cxGrid控件筛选后,数据集随着更新,  (比如默认 查询20条数据,筛选后只剩10条数据, 数据集其实还是有20条数据, 并没有跟着变化)

 

例:控件cxGrid1的tvMasterGrid绑定数据集。设置tvMasterGrid的OptionsCustomize中的ColumnFiltering属性为True,然后设置需要筛选列的Options中的Filtering属性为True,这样就可以通过该列实现刷选过滤功能。

   通过以下2中方法可以实现:

1. 在tvMasterGrid的DataController - Filter - OnBeforeChange事件中写代码

  et_order_view.Filtered:= True;

 et_order_view.Filter := AFilterText;

2. 直接设置tvMasterGrid的属性实现,这个属性一般比较难找到。

在cxGridDBTableView1属性栏找DataController——>Filter——>AutoDataSetFilter设置为True即可。

 

通过以上方法可以通过过滤前后AdoQuery1的RecordCount来验证一下。

 

 (注:tvMasterGrid如果是手动创建的,在该窗体的FormClose事件中把tvMasterGrid的Filtered属性再设置为原有状态,不然下次打开该窗口查询会报错。)

(经过测试,不需要还原, 也不会报错!)

 


// 弹出输入框   str := '999';

  if InputQuery('批量生成流程票', '需要生成的张数', str) then

  begin

  end

 


// 让窗体显示在屏幕右下角

aEMailHint.Top := screen.WorkAreaHeight - aEMailHint.Height;

 aEMailHint.Left := Screen.WorkAreaWidth - aEMailHint.Width;

 


// 查找句柄

   handle := FindWindow(nil,PChar('窗口的标题'));//查到窗体句柄

查找子句柄

  //H0 := FindWindowEx(0, 0, 'TMainForm', nil);  // TMainForm 类名 (第一个参数为0 代表以桌面为主窗体,查找所有子窗体)

  //H1 := FindWindowEx(H0, 0, 'MDIClient', nil);

  //H2 := FindWindowEx(H1, 0, 'TaEmail', nil);

 


// 给窗体发送自定义消息

1. 定义消息:

   const

     WM_IsDone = WM_USER+5;

 

2. 发送消息

   // 发送消息通知主窗口 已经收取完毕  _handle  主窗体句柄

     SendMessage(_handle,WM_IsDone,0,0);

 

3. 主窗体接收消息

   //  同样先定义消息      

      const

        WM_IsDone = WM_USER+5;

 

    // 定义接收消息方法

       // 接收消息

      procedure WndProc(var message: TMessage);override;

   

       procedure TaEmail.WndProc(var message: TMessage);

begin

 

  if message.Msg= WM_IsDone  then

  begin

    MsgBoxi('成功接收消息!');   // 需要做的事

  end;

  //

  inherited WndProc(message);

 

end;


// 多线程使用

 

1. 定义线程类

type

  TMyThread = class(TThread)

  private

    { Private declarations }  

     fPos:Integer;  // 变量

  protected

 

    procedure GetMailList;

    procedure UpdatepBar;   // 同步到主线程

 

    procedure Execute; override;

 

  end;

 

2. 编写线程需要做的事

        procedure TMyThread.Execute;

begin

  { Place thread code here }

 

  FreeOnTerminate:= True;  // 执行完自动释放线程

 

  self.GetMailList;  // 处理事件

  

end;

----------------------------

procedure TMyThread.GetMailList;

begin

     //  编写事件

       fPos := 50;

    // 调用同步

    Synchronize(UpdatepBar);   /

   Sleep(50);

end;

-----------------------

procedure TMyThread.UpdatepBar;

begin

  aEMailHint.pbar.Position := fPos;

end;

 


// 调用目录选择框

引用 Filectrl 单元

procedure TForm1.Button1Click(Sender: TObject);
var
Dir: String;
begin
SelectDirectory('Select a directory', '', Dir);
ShowMessage(Dir);
end; 

 


// 使用 UniConnection1 控件连接数据库  必需引用以下单元

SQLServerUniProvider

ODBCuniProvider


// 获取当前日期 是一年中第几周    uses dateutils;

weekoftheyear(strtodatetime('2009-03-5'))

DayOfTheWeek('20160101') // 一周中的第几天


// 取整数   uses Math;

delphi的取整函数round、trunc、ceil和floor


// 更新表栏位时 加上以下语句, 防止闪动

 

dgDetail.Columns.BeginUpdate;

 

    // do

 

dgDetail.Columns.EndUpdate;

 


//Delphi中本年、本月、本周第一天和最后一天

uses DateUtils;

 

function StartOfTheYear(const AValue: TDateTime): TDateTime;

function EndOfTheYear(const AValue: TDateTime): TDateTime;

function StartOfAYear(const AYear: Word): TDateTime;

function EndOfAYear(const AYear: Word): TDateTime;

 

function StartOfTheMonth(const AValue: TDateTime): TDateTime;

function EndOfTheMonth(const AValue: TDateTime): TDateTime;

function StartOfAMonth(const AYear, AMonth: Word): TDateTime;

function EndOfAMonth(const AYear, AMonth: Word): TDateTime;

 

function StartOfTheWeek(const AValue: TDateTime): TDateTime;          {ISO 8601}

function EndOfTheWeek(const AValue: TDateTime): TDateTime;            {ISO 8601}

function StartOfAWeek(const AYear, AWeekOfYear: Word;                {ISO 8601}

   const ADayOfWeek: Word = 1): TDateTime;

function EndOfAWeek(const AYear, AWeekOfYear: Word;                 {ISO 8601}

   const ADayOfWeek: Word = 7): TDateTime;

 


// 自定义提示框  6 = True  7 = False

if MessageBox(0,'确定要停止代理服务吗?','提示',mb_yesno+MB_ICONASTERISK) = 7 then

1. 警告信息框 MessageBox(Handle,'警告信息框','警告信息框',MB_ICONWARNING); 
2.疑问信息框 MessageBox(Handle,'疑问信息框','疑问信息框',MB_ICONQUESTION); 
3.错误提示框 MessageBox(Handle,'错误信息框','错误信息框',MB_ICONERROR); 
4.提示信息框 MessageBox(Handle,'提示信息框','提示信息框',MB_ICONASTERISK); 
5.说明信息框 MessageBox(Handle,'说明信息框','说明信息框',MB_HELP); 
6.提示信息框 MessageBox(Handle,'提示信息框','提示信息框',MB_OK); 
7.确认信息框 MessageBox(Handle,'确认信息框','确认信息框',MB_OKCANCEL); 
8.重试信息框 MessageBox(Handle,'重试信息框','重试信息框',MB_RETRYCANCEL); 
9.是否信息框 Application.MessageBox(Handle,'是否信息框','是否信息框',MB_YESNO); 
10.是否取消信息框 Application.MessageBox(Handle,'是否取消信息框','是否取消信息框',MB_YESNOCANCEL); 
11 简单提示信息框 ShowMessage('这个就是ShowMessage函数生成的信息提示框!'); 


// KbmMW  引用单元

kbmMWSecurity,

  kbmMWServiceUtils,

  kbmMWGlobal,

  kbmMWXML

 

 


// 日期增减 年,月   引用单元DateUtils

IncMonth( 日期, 月数 )

IncYear( 日期, 年数 )


// 按回车切换焦点   keyDown 事件

 if Key = vk_Return then

   FindNextControl(ActiveControl,True,False,False).SetFocus;

 


// 获取外网IP 函数 引用 uses   ComObj;

 

function TProxyServer.GetPublicIP: string;

var

   xml : OleVariant;

   r:string;

   p1,p2 : Integer;

begin

   xml := CreateOleObject('Microsoft.XMLHTTP');

  xml.Open('GET','http://www.net.cn/static/customercare/yourIP.asp', False);

   xml.Send;

   r := xml.responseText;

  p1:=Pos('<h2>',r); // 找到 h2 标签

  p2:=Pos('</h2>',r);   // 找到 h2 结束标签

   Result := Copy(r, p1+4, p2-p1-4);

end;

 


// 动态拖动改变控件位置大小

添加单元 uControlMove

 

调用

 tsizer.create(self,tcontrol(sender));


//  通过工程文件 实现登录窗口 先出现 

 

//工程文件

 if ufrmLogin.Login() then  //呼叫登录窗口

    Application.Run;

 

// 登录窗口 添加  (需动态创建窗口)

function Login: Boolean;

begin

  //动态创建登录窗口

  with TfrmLogin.Create(nil) do

  begin

    //只有返回OK的时候认为登录成功

    Result := ShowModal() = mrOk;

    Free;

  end;

end;

 

// 验证

//如果通过检查,返回OK

    Self.ModalResult := mrOk;

 


// UNI 连接字符串

Provider Name=SQL Server;Data Source=127.0.0.1;Initial Catalog=FeilungDB;Port=0;User ID=sa;Password=jiang;Login Prompt=False

// windows

Provider Name=SQL Server;Data Source=127.0.0.1;Initial Catalog=HRDB;Port=0;Authentication=Windows;Login Prompt=False

 


Delphi 自带了 Base64 编解码的单元,叫 EncdDecd,

对流的编解码:

procedure EncodeStream(Input, Output: TStream); // 编码

procedure DecodeStream(Input, Output: TStream); // 解码

// 对字符串的编解码:

function EncodeString(const Input: string): string; // 编码

function DecodeString(const Input: string): string; // 解码


 

// 子窗体不随主窗体最小化   重载窗口CreateParams过程

TForm2= class(TForm)

protected

  procedure CreateParams(var Params: TCreateParams); override;

end;

 

procedure TForm2.CreateParams(var Params: TCreateParams);

begin

  inherited;

  Params.WndParent :=   0 ;//就是桌面

end;

   // 或者设置Params.WndParent := GetDesktopWindow;


// 获取系统参数   196239  = sID  (st_systemdata  )

_DataZ.getSystemDataIsOk( 196239 );


// 设置明细表按钮状态

procedure SetDBButtons( const AIsEditing: Boolean ); override; {设置单据按钮}

 

act_ModifyVatID.Enabled := Assigned( ActiveDetailDataSet ) and ActiveDetailDataSet.Active

    and ( ActiveDetailDataSet = _DataP.pt_produce_qty )

    and ( getTagValue( act_ModifyVatID.Tag, ttEmpower ) < 5 )

    and ( self.DataStatus = xdsApproved );

 

 


// 获取服务器时间

DateOf(xSvrUtils.GetServerDateTime());// Date;


// 上传到服务器

       xSvrUtils.putEmailFileToServer(_List_ID);

 

// 没有找到文件 从服务器下载

  if not FileExists(_fFileName) then

 xSvrUtils.GetServerEmailFile(_DataMail.sp_getemaillistsID.AsInteger);

 

 


// MEMO 

// 循环往上滚动

  if Memo1.Perform(EM_SCROLL,SB_LINEDOWN,0)=0 then

  begin

  Memo1.Perform(WM_VSCROLL,SB_TOP,0);

  end

  else

  begin

 SendMessage(Memo1.Handle,WM_VSCROLL,SB_LINEDOWN,0);

  end;

 

// 执行到底 SendMessage(Memo1.Handle, EM_SCROLL, SB_BOTTOM, 0);

//一步一步往下走 SendMessage(Memo1.Handle,WM_VSCROLL,SB_LINEDOWN,0);

// 往下走 SendMessage(Memo1.Handle,EM_SCROLL,SB_PAGEDOWN,0);

 

if Memo1.Perform(EM_SCROLL, SB_LINEDOWN, 0)=0 then//下滚

button2.Enable := False;

if Memo1.Perform(EM_SCROLL, SB_LINEUP, 0)=0 then//上滚

button1.Enable := False;

 


// kbmmw 数据集 提交事务    tt_pdf_data.Resolve();

//

ClearDataSetData 清空数据


// 非模态创建的窗体 Show , ,关闭时 自动释放资源

 注意要在窗体的OnClose和OnDestroy事件中分别写入事件处理代码。

OnClose:

Action := caFree;

OnDestroy:

Form1 := nil;


// 编码,  解码  EncdDecd 单元 : EncodeString、DecodeString、EncodeBase64、DecodeBase64

 

// 先用EncodeString 编码,  再继续用EncodeBase64 编码

 Edit2.Text := EncodeString(Edit1.Text);

 

 Edit3.Text := EncodeBase64( BytesOf(Edit2.Text), Length( BytesOf(Edit2.Text) ) ) ;

 

// 解码,还原

 Edit4.Text :=  DecodeString( StringOf( DecodeBase64(Edit3.Text) ) );

 


// 复制数据  

//新增之后自动添加明细表  procedure MasterDataSetAfterNew;override;

procedure TpOPDEdit.MasterDataSetAfterNew;

begin

  //

  inherited MasterDataSetAfterNew( );

 

  //新增之后自动添加明细表

  _DataComm.QryAssignToTable( 'select xDeptName, xNote5, xType, xState, xPlan from pv_opd_templet',

    pt_opd_date,

    [ 'xDeptName', 'xNote5', 'xType', 'xState', 'xPlan']

    );

 

end;


 

// 明细表增加计算字段

1. dbGridEh 添加字段 ,类型为 : fkCalculated 

 

2. 添加数据集 OnCalcFields 事件 

procedure ThStudyEdit.ht_Study_jeCalcFields(DataSet: TDataSet);

begin

  inherited;

 

  // 计算金额

  ht_Study_jecTotal.AsFloat := ht_Study_jexQty.AsFloat * ht_Study_jexPrice.AsFloat;

 

end;


//  dbo 连接 Excel 字符串

 

// xls 2007

  _SQL_InputXLS_ADO2007 = 'Provider=Microsoft.ACE.OLEDB.12.0;Data Source=%s;Extended Properties= Excel 12.0;Persist Security Info=True' ;

 

  // xls 2003

  _SQL_InputXLS_ADO2003 = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Extended Properties=Excel 8.0';

 


// HR 请输入有效值  引用单元 xStrConstant

MsgBoxW( Format( _STR_NULL_Error, [ lblType.Caption ] ) );


// 显示编辑窗口 

//1. 显示窗口

  if self.WindowState <> wsMinimized then

    self.WindowState := wsMinimized;

 

  //板单发出

  xDBCommon.ShowEditFormOnTop(

 

    TlStyle_IssueEdit, -1, act_Style_Issue.Caption,

    @lStyle_IssueEdit, xDBClasses.etAppend

 

    ); //xDBCommon


// 安装字体

 AddFontResource 把您的字体送入 Windows 字体列表。 
2.使用 SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0) 广播通知。 


 

-- HR 人事档案导入工具, 需要设置为目标数据库

update st_systemdata set xValue = 1 where sID = 2003 


// 系统权限管理  Tag 说明

 


// 直接打印报表

self.DoPrintReport( '报表名称' );

 


// 按下左键

  if GetAsyncKeyState(Vk_Lbutton) <> 0 then

    showmessage('鼠标左键按下') ;


// 浏览多页面 同步选择sID

hp_Study_view.Locate( 'sID',VarArrayof( [hp_studyitem_viewsID.AsInteger] ), [] );


// 插入列表Combobox 

edDataType.Properties.Items.Insert(0).DisplayName := '*' ;


// 获取月份第一天与最后一天

USER :DateUtils   使用 StartOfTheMonth 和 EndOfTheMonth 函数获取即可;

 


// 浏览窗口多页面  哪一页, 放的是哪个数据集

  glMasterGrid.Tag := xClasses.setTagValue( glMasterGrid.Tag, 0, ttIndex ); {放第0个}

  glProgress.Tag := xClasses.setTagValue( glProgress.Tag, 0, ttIndex ); {放第0个}


// 只要时间格式    !99:99;1;_  加一个空格 , 必需用下划线格式,否则时间输入10会变成01

!9999/99/00 00:00;1;_


// 日期相减  DaysBetween(xEDate.AsDateTime, xBDate.AsDateTime)


// 改变日期时间不变

    // 获取小时,分钟

      fHour := HourOf(kt_ctrlover_batchxEDate.AsDateTime);

       fMin := MinuteOf(kt_ctrlover_batchxEDate.AsDateTime);

// 修改日期后,再加上 原 小时、分钟

       kt_ctrlover_batchxEDate.AsDateTime := DateOf(aField.AsDateTime);

       kt_ctrlover_batchxEDate.AsDateTime := IncHour( kt_ctrlover_batchxEDate.AsDateTime,fHour);

       kt_ctrlover_batchxEDate.AsDateTime := IncMinute( kt_ctrlover_batchxEDate.AsDateTime,fMin);
 

HR 函数

// 2015年11月23日: 将日期与日期相加后返回日期  xDBCommonH

function GetDateAddTime( const ADate, ATime: TDatetime): TDatetime

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值