我的delphi笔记-来自为知笔记
来源:互联网 发布:淘宝刷直通车是黑车 编辑:程序博客网 时间:2024/04/29 09:14
Type TArrayString = Array of String;//自定义类型......function GetArrayString(VLength: Integer): TArrayString;//返回一个宽度VLength的数组var I: Integer;begin SetLength(Result, VLength); for I := Low(Result) to High(Result) do Result[I] := IntToStr(I);end;
来源: <http://zhidao.baidu.com/link?url=2HUKVljBKKRnHA-lasJ7ayvJI3zz6wuXLZTisfV2Qr9BgEWlNnv6bKByizF672Z9phBQ3KTizjtteeElmDPj0q>
Type TArrayString = Array of String;//自定义类型......function GetArrayString(VLength: Integer): TArrayString;//返回一个宽度VLength的数组var I: Integer;begin SetLength(Result, VLength); for I := Low(Result) to High(Result) do Result[I] := IntToStr(I);end;
如果需要让别的单元可以调用,可以在interface部分,type下的public,或者在type下都可以.例如: public function test(i : integer): string; { Public declarations } 如果需要在整个单元内使用,可以在type下的private部分声明,或者"紧接着implementation之后": implementation function TForm1.test(i: integer): string; begin i := i + 1; result := inttostr(i); end; 如果只是想过程里使用,可以在过程内部里面声明.例如: procedure TForm1.Button1Click(Sender: TObject); var i : integer; function TForm1.test(i: integer): string; begin i := i + 1; result := inttostr(i); end; begin //....正文内容 end;
来源: <http://zhidao.baidu.com/link?url=gvIPzMEQFGc45RbF0KJSZK8kXcJfCTshPIfj2iOEPGA27sFyXJTW2AlgsZYdQFI65QptWSTfa9jNN3UyxF1zka>
自己写的关于Delphi的字符串筛选函数
有时候要用到筛选字符串的时候,自己研究了很久,先凑合着用。目前只支持ascii筛选吧,暂时不支持汉字的。
比如说
var
string1::string;
wz:Integer; 用于定位位置
begin
string1:='汉字ff的j支f持 ';
for wz:=1 to Length(st2) do //整个循环用于将不需要的字符筛选出来
begin
if st2[wz] <> 'f' then
begin
st3:=st3+st2[wz];
end;
end;
showMessage( st3 );
end
输出结果是 “汉字的j支持” 把字符f筛选出去了
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
博主一直以为Delphi中没有分割字符串的函数,在此之前曾经自己写过一个SplitStrings,一直使用至今,但在一次翻阅Delphi帮助时,无意中在Classes单元中发现Delphi本身就有分割字符串的函数--ExtractStrings,而且功能还不弱,分割的同时还可以去空字符串和去空白(可以自定义)。反正比我写的好啊!^_^
Unit
Classes
Syntax
ExtractStrings(Separators: TSysCharSet; WhiteSpace: TSysCharSet; Content: PAnsiChar; Strings: TStrings): Integer;
Description < by specified null-terminated the of fill to ExtractStrings>
< is character quote if quoted in appear can characters that (Note quote. end final until inside when ignored are Separators separators. as treated always double) or (single and characters, newline returns, Carriage substrings. separating delimiters, used set> < beginning at occur they Content parsing be> < into parse> < already strings any so ExtractStrings, cleared not The added. all which>< Strings added number returns>
ExtractStrings does not add empty strings to the list.
[E文看着比较累,还是中文一下吧]: WhiteSpace 参数指定每个子串开头被忽略的字符s。
Content 参数就是被分割的“源”串了。
Strings 参数用于接收分割后的各个子串。它的原有内容不会被清空。别忘了对Strings进行Create哦。
另外,EctractStrings不会把空串放入Strings中去。
举个例子吧:
如果我想分割以下字符串: ABC|... DEF|#### GHI|"中华网URL
希望得到下面四个字符串:
1、ABC
2、DEF
3、GHI
4、中华网URL
那么可以用下面的代码:
view plaincopy to clipboardprint?
uses Classes;
var
ASource: PChar;
AStr: String;
ACount: Integer;
AStrings: TStringList;
begin
ASource := 'ABC|... DEF|#### GHI|"中华网URL';
AStrings := TStringList.Create;
try
ACount := ExtractStrings(['|'], [' ','#','.'], ASource, AStrings);
//........................
finally
AStrings.Free;
end;
end.
来源: <http://www.delphitop.com/html/zifuchuan/338.html>
//分割字符串 ExtractStrings
var
s: String; List: TStringList;begin s := 'about: #delphi; #pascal, programming'; List := TStringList.Create; ExtractStrings([';',',',':'],['#',' '],PChar(s),List); //第一个参数是分隔符; 第二个参数是开头被忽略的字符 ShowMessage(List.Text); //about //delphi //pascal //programming List.Free;end;
来源: <http://www.cnblogs.com/del/archive/2007/12/11/991479.html>
如果需要让别的单元可以调用,可以在interface部分,type下的public,或者在type下都可以.例如: public function test(i : integer): string; { Public declarations } 如果需要在整个单元内使用,可以在type下的private部分声明,或者"紧接着implementation之后": implementation function TForm1.test(i: integer): string; begin i := i + 1; result := inttostr(i); end; 如果只是想过程里使用,可以在过程内部里面声明.例如: procedure TForm1.Button1Click(Sender: TObject); var i : integer; function TForm1.test(i: integer): string; begin i := i + 1; result := inttostr(i); end; begin //....正文内容 end;
Unit
Classes
Syntax
ExtractStrings(Separators: TSysCharSet; WhiteSpace: TSysCharSet; Content: PAnsiChar; Strings: TStrings): Integer;
Description < by specified null-terminated the of fill to ExtractStrings>
< is character quote if quoted in appear can characters that (Note quote. end final until inside when ignored are Separators separators. as treated always double) or (single and characters, newline returns, Carriage substrings. separating delimiters, used set> < beginning at occur they Content parsing be> < into parse> < already strings any so ExtractStrings, cleared not The added. all which>< Strings added number returns>
ExtractStrings does not add empty strings to the list.
[E文看着比较累,还是中文一下吧]: WhiteSpace 参数指定每个子串开头被忽略的字符s。
Content 参数就是被分割的“源”串了。
Strings 参数用于接收分割后的各个子串。它的原有内容不会被清空。别忘了对Strings进行Create哦。
另外,EctractStrings不会把空串放入Strings中去。
举个例子吧:
如果我想分割以下字符串: ABC|... DEF|#### GHI|"中华网URL
希望得到下面四个字符串:
1、ABC
2、DEF
3、GHI
4、中华网URL
那么可以用下面的代码:
view plaincopy to clipboardprint?
uses Classes;
var
ASource: PChar;
AStr: String;
ACount: Integer;
AStrings: TStringList;
begin
ASource := 'ABC|... DEF|#### GHI|"中华网URL';
AStrings := TStringList.Create;
try
ACount := ExtractStrings(['|'], [' ','#','.'], ASource, AStrings);
//........................
finally
AStrings.Free;
end;
end.
Delphi判断文件或文件夹是否存在
2009-04-17 09:17:35| 分类: Delphi文件及文件|举报|字号 订阅
if DirectoryExists('路径') then
Function FileExists(const FileName:String):Boolean;
看到这个函数时我首先看到的是它返回是数据类型是一个布尔类型:Boolean;
然后参数名可以很清楚看到是一个常量的字符类型:而由FileName我们可以知道这个就是我们要查找的文件了,
如果文件存在的话就返回True ,否则,返回False
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
获取当前执行文件目录
在Delphi SysUtils 单元中有 ExtractFileDir 与 ExtractFilePath两个类似的函数, 两个函数有以下的区别:
ExtractFilePath 传回值的最後一个字元是反斜杠“/”。
ShowMessage(ExtractFileDir(Application.Exename)); // 返回值为 c:/temp
ShowMessage(ExtractFilePath(Application.Exename)); // 返回值为 c:/temp/
相同点: 如果执行文件在根目录下(如:C:/SAMPLE.EXE)的话, 两者的传回值相同, 且最后一个字符都是“/”。
===============================================================================
edit1.Text:=ParamStr(0);//自己全路径c:/555/qq.exe,可用于控制台
edit1.text:=ExpandFileName(ParamStr(0)); //获取本程序的完整路径 c:/qq/2.exe
edit2.text:=ExtractFileDir(ParamStr(0)); //获取本程序的路径 c:/qq
edit3.text:=application.Exename; //获取本程序的完整路径 c:/qq/2.exe,和第1个一样
edit4.text:=ExtractFilename(Application.Exename); //获得文件名2.exe
ExpandFileName() 返回文件的全路径(含驱动器、路径)
ExtractFileExt() 从文件名中抽取扩展名
ExtractFileName() 从文件名中抽取不含路径的文件名
ExtractFilePath() 从文件名中抽取路径名
ExtractFileDir() 从文件名中抽取目录名
ExtractFileDrive() 从文件名中抽取驱动器名
ChangeFileExt() 改变文件的扩展名
ExpandUNCFileName() 返回含有网络驱动器的文件全路径
ExtractRelativePath() 从文件名中抽取相对路径信息
ExtractShortPathName() 把文件名转化为DOS的8·3格式
MatchesMask() 检查文件是否与指定的文件名格式匹配
Delphi 数据类型列表
Ord(False) = 0
Ord(True) = 1
Succ(False) = True
Pred(True) = False1 ByteBoolFalse <> True
Ord(False) = 0
Ord(True) <> 0
Succ(False) = True
Pred(False) = True1 WordBool2 LongBool4 枚举 子界 实数 Real5.0×10-324 .. 1.7×103088[精度]15..16Real482.9×10-39 .. 1.7×10386[精度]11..12;
向后兼容Single1.5×10-45 .. 3.4×10384[精度]7..8Double5.0×10-324 .. 1.7×103088[精度]15..16Extended3.6×10-4951 .. 1.1×10493210[精度]19..20Comp-263 + 1 .. 263 - 18[精度]19..20Currency-922337203685477.5808 ..
922337203685477.58078[精度]19..20字符串 ShortString255个字符2..256B向后兼容AnsiString大约 231 个字符4B..2GB8位(ANSI)字符WideString大约 230 个字符4B..2GB多用户服务和
多语言应用程序;
和com定义的BSTR兼容其他String
String[0..255]
PChar
PAnsiString
PWideString 结构类型集合 Set最多256个元素[0..255] 数组静态数组 动态数组 记录 Record 文件 File 类 Class 类引用 Class reference 接口 Interface 指针类型无类型指针 Pointer 有类型指针预定义类型指针PAnsiString
PString
PByteArray
PCurrency
PDouble
PExtended
PSingle
PInteger
POleVariant
PShortString
PTextBuf
PVarRec
PVariant
PWideString
PWordArray 过程类型程序过程类型 Procedural 对象过程类型 Procedural 变体类型 Variant OleVariant
- 我的delphi笔记-来自为知笔记
- 来自为知笔记
- 我的delphi笔记(二)
- 我的delphi下的接口编程学习笔记
- delphi笔记
- delphi 笔记
- delphi 笔记
- Delphi 笔记
- delphi笔记
- Delphi笔记
- 学习delphi不错的笔记
- Delphi 的一些笔记
- (来自高程我的笔记)关于位操作符的补码与反码与按位非操作符
- 我的笔记
- 我的Struts笔记
- 我的笔记~
- 我的seo笔记
- 我的java笔记
- POJ-3158
- ios内存管理&1之常见的内存管理
- poj2406 Power Strings
- STM32标准库文件使用
- PHP Ajax 跨域问题最佳解决方案
- 我的delphi笔记-来自为知笔记
- mysql中的定义条件和处理程序
- StringBuilder源码分析
- 链表结点的逆置
- 口袋西游背包数组分析
- 利用模板巧妙实现二级接口
- 我的delphi笔记(二)
- Swagger工具
- Unicode与JavaScript详解