Blbo字段存取
VAR
filename:string;
//这里是从系统中取得一个临时文件
function gettemporyfilename:string;
const max_path=144;
var
lppathbuffer:pchar;
lpbuffer:pchar;
begin
getmem(lpbuffer,max_path);
getmem(lppathbuffer,max_path);
gettemppath(max_path,lppathbuffer);
gettempfilename(lppathbuffer,'tem',0,lpbuffer);
freemem(lppathbuffer,max_path);
gettempfilename(gettempdrive('c'),'tem',0,lpbuffer);
result:=strpas(lpbuffer);
freemem(lpbuffer,max_path);
end;
//将一个AVI文件写到blob字段中去
procedure tform1,button1click(sender:tobject);
var
filestream:tfilesteam;//to load the avi file
blobstream:tblobstream;//to save to the bolb
begin
application.processmessages;
button1.enabled:=false;
button2.enabled:=false;
filestream:tfilestream.create('ppath',fmopenread);//ppath是这个avi的路径
table1.edit;
//为table1avi字段创建一个blobstream
blobstream:=tblobstream.create(table1avi,bmreadwrite);
//移动到stream的首位
blobstream.seek(0,sofrombeginning);
//清空流数据
blobstream.truncate;
//将filestream的内容拷贝到blobstream
blobstream.copyfrom(filestream,filestream.size);
//释放流
filestream.free;
blobstream.free;
//添加记录
table1.post;
//使buttons可用
button1.enabled:=true;
button2.enabled:=true;
end;
procedure tform1.button2click(sender:tobject);
var
filestream:tfilestream;//a temp file
bolobstream:tblobstream;//the AVI blob
begin
//为AVI字段创建BLOB数据流
bolobstream:=tblobstream.create(table1avi,bmread);
if blobstream.size=0 then
begin
blobstream.free;
exit;
end;
//关闭media player
mediaplayer1.close;
//重值文件名
mediaplayer1.filename:='';
//刷新显示窗口
mediaplayer1.display:=panel1;
panel1.refresh;
//创建前删除同名的临时文件
if filename<>'' then
deletefile(filename);
//设置临时文件名
filename:=gettemporaryfilename;
//为临时文件创建文件流
filestream:=tfilestream.create(filename,fmcreate or fmopenwrite);
//拷贝blob到临时文件中
filestream.copyfrom(blobstream,blobstream.size);
//释放流
filestream.free;
blobstream.free;
//设置media player播放AVI文件
mediaplayer1.filename:=filename;
mediaplayer1.devicetype:=dtavivideo;
mediaplayer1.open;
mediaplayer1.play;
end;
procedure tform1.formdestroy(sender:tobject);
begin
//取消临时文件和media player的关联
mediaplayer1.close;
mediaplayer1.filename:='';
//删除临时文件
if filename<>'' then
deletefile(filename);
end;
多任务栏
procedure TCustomForm.WMSysCommand(var Message: TWMSysCommand);
begin
with Message do
begin
if (CmdType and $FFF0 = SC_MINIMIZE) and (Application.MainForm = Self) then
Application.WndProc(TMessage(Message))
else if (CmdType and $FFF0 <> SC_MOVE) or (csDesigning in ComponentState) or
(Align = alNone) or (WindowState = wsMinimized) then
inherited;
if ((CmdType and $FFF0 = SC_MINIMIZE) or (CmdType and $FFF0 = SC_RESTORE)) and
not (csDesigning in ComponentState) and (Align <> alNone) then
RequestAlign;
end;
end;
可以得知,MainForm的一些事件被传给了应用程序对象Application,我们要做的就是截取这
些消息,干我们自己想干的.
1.在主窗体unit中
声明
procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
procedure CreateParams(var Params:TCreateParams); override;
实现
procedure TForm1.WMSysCommand(var Message: TWMSysCommand);
begin
case message.CmdType of
SC_MAXIMIZE,SC_MINIMIZE,SC_RESTORE: //这几个消息自己处理
DefWindowProc(Self.Handle,message.Msg,message.CmdType,0)
else
inherited; //交给DELPHI
end;
end;
procedure TForm1.CreateParams(var Params:TCreateParams);
begin
inherited CreateParams(Params);
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW ;//让主窗体出现在任务栏上
end;
好了,这样主窗体就会出现在任务栏上,而且最小化也不会消失,现在要做的就是
让Application在任务栏上的按钮消失,用以下代码
procedure TForm1.FormShow(Sender: TObject);
begin
showwindow(Application.Handle ,sw_hide);
end;
其它的窗体想出现在任务栏,只要像主窗体一样重载CreateParams方法,并用相同的代码,
这样就实现了一个应用程序有多个任务栏按钮,而且不会相互影响.