第一种方法,使用SelectDirectory 函数 ,在ShellApi中
procedure TForm2.BtSelectPathClick(Sender: TObject);
var
strCaption,strDirectory:String;
wstrRoot:WideString;
begin
strCaption:='这是浏览文件夹的说明文字,可以根据需要进行书写。'
+#13#10+'一般二行文字就满了。';
//该参数是浏览文件夹窗口的显示说明部分
wstrRoot:='';
//这个参数表示所显示的浏览文件夹窗口中的根目录,默认或空表示“我的电脑”。
SelectDirectory(strCaption,wstrRoot,strDirectory);
EdLocalPath.Text:=strDirectory;
end;
第二种方法
要求:利用Win32 API SHBrowseForFolder开启一个选择文件目录的对话框,预先定位到默认的目录,最后返回所选择的结果,如果没有进行选择(即单击“取消”结束选择)则返回空''。
代码如下:(以下两个函数定义需要在uses中引入两个单元ShlObj,Windows;)
function BrowseCallbackProc(Wnd: HWND; uMsg: UINT; l ......
//加一下按钮,加一个对话框就OK啦
procedure TForm1.Button1Click(Sender: TObject);
var
S: String;
begin
if OpenDialog1.Execute then
begin
s := OpenDialog1.FileName;
WinExec( PChar(s), SW_NORMAL);
end;
end;
---------------------------------------------------------------
我们常用的函数有两个,WinExec 和 ShellExecute。
1) 使用 WinExec 函数 (属于 WinProcs单元)
· 声明形式 UNIT WinExec(LPCSTR lpCmdLine, UINT uCmdShow);
[例] var SDir:string;
SetLength(SDir,144);
GetWindowsDirectory(PChar(SDir),144);
SetLength(SDir,StrLen(PChar(SDir)));
SDir:=SDir+'\notepad.exe'+' '+savedialog1.FileName;
WinExec(PChar(SDir), SW_SHOWMAXIMIZED);
注意:如果 SDir 不是有效路径不会提示错误。
[例] winexec('command.com /c copy *.* c:\',SW_Normal);
[例] winexec('start abc.txt');
2)使用 ShellExecute 函数(属于ShellAPI ......
一、Dll建立
(一)DLL项目的建立
library mydll;
uses
base in 'base.pas';
exports
Triple name 'Tr';
{$R *.res}
begin
end.
(二)函数单元
unit base;
interface
uses windows;
function Triple(N:integer):integer;stdcall;
implementation
function Triple(N:integer):integer;stdcall;
begin
result:=n*3;
end;
end.
二、静态调用
unit Unit1;
interface
uses
Windows, SysUtils, Controls, Forms,
StdCtrls, Classes;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
const
gdi32='mydll';
function triple(n:integer):integer;stdcall;external gdi32 name 'Tr';
{$ ......
delphi保存读取utf-8的文本文件
给客户做了一个批量识别图像并合成双层pdf的程序,最后客户需要生成的同时附带一份记事本文件,就是OCR过后的文本,并指定utf-8格式的。在处理utf-8时出现了点小问题,现在总结如下
首先 利用delphi自带的UTF8Encode函数,将普通字符转换为utf-8编码
创建一个流,MemoryStream或FileStream都可
函数看起来如下
引用
procedure SaveUTF8File(AContent:WideString;AFileName: string);
var
ffileStream:TFileStream;
futf8Bytes: string;
S: string;
begin
ffileStream:=TFileStream.Create(AFileName,fmCreate);
futf8Bytes:= UTF8Encode(AContent);
ffileStream.Write(futf8Bytes[1],Length(futf8Bytes));
ffileStream.Free;
end;
运行后查看生成的文件,全是乱码,上网搜索发现
unicode文本文件:头两个字符分别是FF FE(16进制)
utf-8文本文件:头两个字符分别是EF BB(16进制)
原来是忘了把文件头加进去了
于是加入代码后
引用
procedure SaveUTF8File(AContent:WideString;AFileName: string);
var
ffi ......
想没想过在DELPHI中显示GIF动画?Delphi的用户是非常幸运的,因为有免费控件可以使用。最著名的控件是Anders Melander编写的TGifImage,并提供完整的源程序。它原来的主页是www.melander.dk/delphi/gifimage/,不过有很长时间没有更新了。如果要在新版本的Delphi中使用,可以从http://finn.mobilixnet.dk/delphi/下载Finn Tolderlund改写的Delphi 5/6/7版本的TGifImage。 现在看看怎么在DELPHI中使用GIFImage.pas文件,显示GIF动画首先,新建一个工程,在Project-OPTIONS菜单中的Directories/Conditionals页中的search中添加一个路径,这个路径指向GIFImage.pas所在文件夹然后在FORM1的PUBLIC区添加一个变量GIF,定义为TGIFImage类型在form1的onCreate中添加代码:GIF := TGIFImage.Create; 在form1上添加一个按钮button1,添加一个image控件在button1的click事件中添加代码: Gif.LoadfromFile('d:\abc.gif'); GIF.Paint(Image1.Canvas,Image1.ClientRect,[goAsync,goLoop,goAnimate]);
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,GIFImage, ExtCtrls;
type
TForm1 = class(TForm)
......
delphi很早就已经可以进行三层的开发了. 但一直到现在, 网上这方面的东西太少 了. 要么太老, 甚至不完全正确. 例如:
如何进行多表更新(提交), 很多回复还是说用ADOConnection的事务, (如果要同时更新SQL SERVER和Oracle数据库的表怎么办).
当然也有说用SetComplete, SetAbort的. 但说的很简单, 其中的注意事项又是什么呢. 还有的推荐看李维的那本分布式开发的书. 那本书中是写了很多值得学习和了解的东西. 但有些东西已经过时了或者说的不详细, 例如win2000中已经有COM+了. COM+已经整合了mts及其它一些东西了. 另个, 也有些贴子上有人说, 应用服务器上只用一个TDataSetPrivoder和一个 TDataSet(ADO, Query, DBXQuery之一)就可以了. 但具体怎么用呢?又看不到下文.
另外, 还有一些朋友在用第三方的一些控件. 我看了一下, 大多就像个嵌入到IE中的ActiveX, 感觉也没有什么意思---直接弄个ActiveX到IE中就不行了.
1. 如何只用一个TDataSetPrivoder和一个TADOQuery.
delphi的TRemoteDataModule集成了IAppServer接口.并且实现了IAppServer接口的方法:
view plaincopy to clipboardprint?
{ IAppServer }
function AS_GetProviderNames: OleVariant; saf ......