------------------------------------------------------------------------------------------------------------------------
Function GetFileVersion(FileName: String): String; //获取文件的版本信息,以.号分开
Var
InfoSize, Wnd: DWORD;
VerBuf: Pointer;
szName: Array[0..255] Of Char;
Value: Pointer;
Len: UINT;
TransString: String;
sresult: String;
Begin
//获取版本信息的尺寸
InfoSize := GetFileVersionInfoSize(PChar(FileName), Wnd);
If InfoSize <> 0 Then
Begin
GetMem(VerBuf, InfoSize);
Try
//获取版本信息
If GetFileVersionInfo(PChar(FileName), Wnd, InfoSize, VerBuf) Then
Begin
Value := Nil;
//查询
VerQueryValue(VerBuf, '\VarFileInfo\Translation', Value, Len);
If Value <> Nil Then
Begin
//查询版本
TransString := IntToHex(MakeLong(HiWord(Longint(Value^)), LoWord(Longint(Value^))), 8);
StrPCopy(szName, '\StringFileInfo\' + Transstring + '\FileVersion');
If VerQueryValue(VerBuf, szName, Value, Len) Then
Begin
//转转字符串
sresult := StrPas(PChar(Value));
End;
End;
End;
Finally
FreeMem(VerBuf);
End;
result := sresult;
End
Else
result := '';
End;
------------------------------------------------------------------------------------------------------------------------
function shuzi(str:string):boolean;//判断是否为数字
var
i:integer;
begin
for i:=1 to length(str) do
if not (str[i] in ['0'..'9']) then
begin
result:=false;
exit;
end;
result:=true;
end;
//Get the Windows directory获取Windows路径
function GetWinDir:String;
var
Buf:array[0..MAX_PATH] of Char;
begin
FillChar(Buf,SizeOf(Buf),0);
GetWindowsDirectory(Buf, SizeOf(Buf));
Result:=Buf;
end;
//Get the System directory获取System32路径
function GetSysDir:String;
var
Buf:array[0..MAX_PATH] of Char;
begin
FillChar(Buf,SizeOf(Buf),0);
GetSystemDirectory(Buf, SizeOf(Buf));
Result:=Buf;
end;
memo本身就带有ScrollBars属性
取值 含义
SsNone 无滚动条
SsHorizontal 在底部水平滚动条
SsBoth 在底部和右边都存在滚动条
SsVertical 在右边有一个垂直滚动条
//如何在DELPHI中退出程序
application.Terminate;
halt(0);
exitprocess(0);
三种都可以,不过一般用application.Terminate
在你的多个窗体里肯定有一个是主窗体假设是form1
在form2中要uses unitl1;
然后在form2的onclose事件里写上form1.close;就行拉;
-----------------------------------------------------------------------------
//如何将String类型转换成PWideChar
----方法一------------------------------------------------------------------
Buffer: array[0..255] of WideChar
temp: string;
p: pwidechar;
p:=STRINGTOWIDECHAR(temp, Buffer, SizeOf(Buffer) div 2);
----方法二------------------------------------------------------------------
var
pw:pwidechar;
w:widestring;
s1,s2:string;
begin
s1:= 'aa ';
s2:= 'bb ';
w:=s1+s2;
pw:=@w[1];
showmessage(pw);
------------------------------------------------------------------------------
D7-D2010及XE 将所有的string类型改为AnsiString,将pchar 改为PAnsiChar试试。
neir:=getHTTPPage(edit2.Text);
cc:=RemoveHTML(neir);
lista(cc, ListView1);
//多线程范例
procedure TForm1.Button1Click(Sender: TObject);
var
CThread:Thandle;//声明了一个句柄
Tid:DWord;
begin
Cthread:=CreateThread(nil,0,@NewThread,nil,0,Tid); //创建一个线程,同时调用线程函数
end;
-------------------------------------------------------------------------------
//delphi怎么把一个String转成Tstream? 通常方法
var
ss : String;
kk : TStringStream; //把你的流转成这个就可以了
beign
kk := TStringStream.Create(ss); // String转成Tstream
ss := kk.DataString; // Tstream转成String
end
Application.ProcessMessages;//防止进程阻塞,使程序能够响应消息队列中的其他事件。
procedure TForm1.Button1Click(Sender: TObject);//delphi post登陆
var
strMsg:string;
sParams: TStringStream;
IdHTTP1:TIdHTTP;
begin
sParams := TStringStream.create('');
IdHTTP1:=TIdHTTP.Create(Nil);
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
try
sParams.WriteString('sname=daiang&spwd=dailng&scorpid=&sprdid=803&sdst=&smsg=ceshi');
strMsg:=IdHTTP1.post('http://tieba.baidu.com/f/commit/thread/add',sParams) ;
memo1.Text:=strmsg;
finally
sParams.Free;
IdHTTP1.Free;
end;
end;
uses HTTPApp//转码
memo2.Lines.text:=HTTPEncode(AnsiToUtf8(memo1.Lines.text));百度编码
memo2.Lines.text:=AnsiToUtf8(HTTPEncode(memo1.Lines.text));其他网页编码
uses Jpeg//Delphi中如何用Image控件显示网络图片
procedure TForm1.Button1Click(Sender: TObject);
var
imagestream:TMemoryStream;
jpg:TJpegImage;
begin
imagestream := TMemoryStream.Create();
jpg:=TJpegImage.Create;
idhttp1.Get('http://www.ggyy8.com/Files/comic/500x300/H/Naruto.jpg',imagestream);
imagestream.Position:=0;
jpg.LoadFromStream(imagestream);
image1.Picture.Assign(jpg);
end;
procedure TForm1.Button5Click(Sender: TObject);//uses:ActiveX
var
url,aaa,aaa1:String;
StrStream:TStringStream;
begin
url:='http://tieba.baidu.com/f?kz='+listview1.selected.caption ;
aaa:=getPage(url);//listview1.selected.caption');
aaa1:=ExtractEmails(aaa,'<td valign="top" class="content">(.*?)</td>');//回复</a></li>');
StrStream:=TStringStream.Create(aaa1);
WebBrowser1.Navigate('about:blank');
try
StrStream.Position:=0;
(WebBrowser1.Document as IPersistStreamInit).Load(TStreamadapter.Create(StrStream));
finally
StrStream.Free;
end;
end;
QuotedStr(edit1.text)
formatdatetime('yyyy-MM-dd',Date); delphi目前日期
function SplitString(const Source, ch: string): TStringList;//字符串分割等同VB Split
var
temp:String;
i:Integer;
begin
Result:=TStringList.Create;
//如果是空自符串则返回空列表
if Source='' then exit;
temp:=Source;
i:=pos(ch,Source);
while i<>0 do
begin
Result.add(copy(temp,0,i-1));
Delete(temp,1,i+Length(ch)-1);
i:=pos(ch,temp);
end;
Result.add(temp);
end;
mystream1 :=TMemoryStream.Create;//下载图片
IdHTTP1.Get('http://www.pconline.com.cn/pcedu/photo/0508/pic/050831girl18.jpg',mystream1);
mystream1.SaveToFile('050831girl18.jpg');
procedure TForm1.Button2Click(Sender: TObject);
Var
alist,Strings: TStringList;
i:integer;
begin
alist:= tstringlist.Create;
alist.LoadFromFile('数据.txt'); //程式读取TXT档的内容
Strings := TStringList.Create;
for I := 0 to alist.Count - 1 do
begin
Strings.Text := AnsiReplaceStr(alist[i], ', ',#10);
with listview1.Items.Add do
begin
Caption:=Strings[0] ;
SubItems.Add(Strings[1]) ;
SubItems.Add(Strings[2]) ;
end;
end;
end;
uses StrUtils;//分割字符串
var
Strings: TStringList;
begin
Strings := TStringList.Create;
Strings.Text := AnsiReplaceStr(Str, ',', #10);
end;
var//取字符串(1:字符)冒号后面的所有字符
str:string;
copy(str,pos(':',str)+1,length(str)-pos(':',str));
function quzhi(strData: string;zifu1: string;shu1: integer;zifu2: string): string ;//取值过程
begin
quzhi:=copy(strData,pos(zifu1,strData)+shu1,pos(zifu2,strData)-pos(zifu1,strData)-shu1);
End;
StringReplace ( "字符串", "搜索串" 或 起始位置, "替换串" [, 数量 [, 区分大小写]] )
S := StringReplace(S, ':', '$', [rfReplaceAll]);
在窗体中加入控件。
IdHTTP1: TIdHTTP;
Memo1: TMemo;
Button1: TButton;
Edit1: TEdit;
设置好IdHTTP1的代理等,在button1的事件中加入代码
procedure TForm1.Button1Click(Sender: TObject);
begin
IdHTTP1.Connected;
Memo1.Lines.Text:= IdHTTP1.Get(Edit1.Text); //用MEMO.Lines.LoadFormFile( "http://news.163.com/special/g/guoneinews.html ")一样可以的
end;
将控件的组件的PopupMenu属性改为PopupMenul。 //联系菜单
Mainmenu.MenuItem.ShortCut := 'Ctrl+X' //delphi mainmenu控件如何定义菜单项的快捷键
Var //读取TXT到listview1
alist,list : TStringlist;
I: Integer;
begin
alist:= tstringlist.Create;
alist.LoadFromFile('数据.txt'); //读取TXT档的内容
list:= tstringlist.Create;
list.Delimiter := ',';//分割符号,另外TXT中的空格是自动分隔符
ListView1.RowSelect := True;//listview1中选择整行
for I := 0 to alist.Count - 1 do
begin
list.DelimitedText := alist[i]; //list.DelimitedText是按行在读取的行值
with listview1.Items.Add do
begin
Caption:=list[0] ;
SubItems.Add(list[1]) ;
SubItems.Add(list[2]+' '+list[3]) ;
end;
end;
for i:=0 to alist.Count-1 do//按4循环
begin
INC(i,4);
end;
Var
alist: TStringList;
begin
alist:= tstringlist.Create;
alist.LoadFromFile('数据.txt'); //程式读取TXT档的内容
edit3.Text:= alist[strtoint(edit2.text)];//alist.Strings[0]
ListView1.columns.Clear;//添加标题格式
with listview1 do
begin
Columns.Add;
Columns.Add;
Columns.Add;
ViewStyle:=vsreport;
GridLines:=true;
columns.items[0].caption:='1姓名';
columns.items[1].caption:='2分数';
columns.items[2].caption:='3科目';
Columns.Items[0].Width:=100;
Columns.Items[1].Width:=100;
Columns.Items[2].Width:=141;
end
ListView1.columns.Clear;//清空标题
ListView1.Items.Clear;//清空内容
ListView1.RowSelect:= True; //listview1中选择整行
Inc(s,1) ;//s:=s+1
if edit1.Text<>'页面3' then
edit2.Text:= '页面' + inttostr(s) ;
n3.Checked:=not n3.Checked;
字体。字体名字前面带@的都是躺着的……不带的都是站着的……
form2.showmodal;//打开form2窗体
FloatToStr