当前位置:文档之家› delphi常用语句

delphi常用语句

1、显示窗体:
Frm_DBBind:=TFrm_DBBind.create(self);
with frm_DBBind do
begin
showModal;
free;
end;
2.当窗体不能关闭时,在其OnClose事件中释放
action:=caFree;
3.删除前的提示,在beforeDelete事件中
if messageBox(handle, '删除不能恢复,确认删除吗?', '确认', mb_YesNo)<>idYes then abort; //Abort终止
4.调节记录
with qry_Main do if not isEmpty then first;
with qry_Main do if not isEmpty then last; //最后一条记录
with qry_Main do if not bof then Prior; //移动到上一条纪录
with qry_Main do if not eof then next; //下一条记录
5.撤销操作
if qry_Main.state in [dsEdit,dsInsert] then qry_Main.cancel; //撤销
//with qry_Main do if state in [dsEdit,dsInsert] then cancel;
6.保存、删除、添加
with qry_Main do if state in [dsEdit,dsInsert] then post; //若处在修改、增加状态,则提交
with qry_Main do if not isEmpty then delete; //非空,删除
with qry_Main do insert;
7.打开数据集
with qry_Main do
try
close;
if not connection.Connected then connection.Open; //打开数据连接
//打开数据集
sql.Clear;
sql.text:='select * from langDefault as bases where 1=1 ';
//sql.Add(' and sForm=''Frm_MDI'' or sForm='+quotedStr('Frm_MDI')); //两者是等效的,两个单引号表示一个单引号
if (txt_Form.text<>'') then sql.add(' and sForm like '+quotedStr(txt_Form.text+'%')); //Access用星号表示模糊查询
sql.Add(' order by sForm ');
open;
//设置打开的数据集的外观
for i:=0 to fieldCount-1 do
fields[i].DisplayWidth:=10;
//设置某些字段的标题
f:=findField('一个不存在的字段');
F:=findField('sForm'); //查找字段,找不到返回null
if assigned(F) then f.DisplayLabel:='窗体名称'; //
//直接设置
fieldByName('sCaption').DisplayLabel:='标题';
fieldByName('sCaption').DisplayWidth:=20; //特别宽
//隐藏字段
if assigned(findField('nID')) then fieldByName('nID').Visible:=false; //隐藏
setFieldView(qry_Main, 'nID', '', -1, false);
//保险的一种方式
gs_DataFunction.SetFieldView(Qry_Main, 'lForm', '是否窗体', 16, true);
except
on x:Exception do showMessage('打开出错:'+x.Message);
end
8.打印
var s:string;
s:=extractFilePath(application.ExeName)+'语言设置.rmf'; //取当前目录的文件名
rpt_Main.LoadFromFile(s); //加载文件
//打印参数
rpt_Main.PrinterName:=cbx_Printer.Text; //默认打印机
rpt_Main.DefaultCopies:=strToIntDef(txt_Copies.Text,1); //默认打印份数
//预览或直接输出
if chk_P

review.checked then rpt_Main.ShowReport else rpt_Main.PrintReport; //预览,或者直接打印
窗体创建时候
cbx_Printer.Items.Assign( printers.Printer.Printers ); //本机安装的打印机列表
if cbx_Printer.Items.Count>0 then cbx_Printer.ItemIndex:=printers.Printer.PrinterIndex else cbx_Printer.Text:=''; //默认打印机
txt_Copies.text:='1';
9.导出Excel
if not saveDialog1.Execute then exit;
with qry_Main do begin
if isEmpty then exit; //无数据不需要处理
screen.Cursor:=crHourGlass; //指针变成玻璃杯
//
ExportExcelDB(qry_Main, saveDialog1.FileName, false);
//完成
screen.Cursor:=crDefault; //鼠标指针改回来
end;




ini文件操作:
uses iniFiles;
public
myini:TiniFile;
vstr,pwd:string;
vi:integer;
vb:boolean;
end;
myini:=TiniFile.Create('F:\my.ini');//建立连接
try
vi:=myini.ReadInteger('stu','ID',-1); //读取
vstr:=myini.ReadString('stu','Name','No name');
except
on x:Exception do showmessage('s:'+x.Message);
end;
vstr:='liuhong';
myini.WriteString('stu','Name',vstr); //写入
myini.WriteString('pwd','pwd','456'); //当不存在时候,自动创建
myini.free;//释放

相关主题
文本预览
相关文档 最新文档