用delphi快两年了,在这两年中,自己也总结了一些小技巧,请各位大侠,也亮出来!!
1.模拟单击Enter键,焦点往后移动
form.formkeypress(….)
begin
if key=#13 then
begin
key:=#0;
Perform(WM_NextDlgct,0,0);
End;
End;
procedure TfrChange.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState); //对窗体的onkeydown事件进行,不过要注意,窗体的keypreview要为true;
begin
if Key = 13 then selectnext(ActiveControl,True,True);
end;
2. procedure TfrmMain.FormCreate(Sender: TObject);
//*----------------------------------------------------------*/
//* 用于自适应系统分辨率 */
//----------------------------------------------------------*/
begin
if screen.Width <> 1024 then scaleby(screen.Width,1024); //其中1024为设计时分辨率
end;
3.keypress
procedure TfrmMain.edtTianKeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',#8,#13,#46]) then key := #0; //#8- BackSpace,#13-Enter,#46-Del
end;
4.DBGrid中的下拉列表和查找字段
设 置 好DBGrid 中 该 字 段 的PickList 字 符 串 列 表、 初 始 的 序 号 值DropDownRows 即 可
5..金钱转成大写
function TForm1.Moneytochinese(v:currency):string;
const
digits:array[0..9] of string=('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
poses:array[1..14] of string=('仟','佰','拾','亿','仟','佰','拾','万','仟','佰','拾','元','角','分');
illegals:array[1..8,1..2] of string=(('零亿','亿'),('零万','万'),('零仟','零'),('零佰','零'),('零拾','零'),('零元','元'),('零角','零'),('零分',''));
var i,j:integer;
s:string;
begin
result:='';
if v=0 then
exit;
s:=formatfloat('0',v*100);
while pos('00',s) <> 0 do
s[Pos('00',s)]:=' ';
s:=stringofchar(' ',14-length(s))+s;
for i:=1 to length(s) do
if(s[i]='') and(i in [4,8,12])then
result:=result+poses[i]
else
if s[i] in['0','1','2','3','4','5','6','7','8','9']then
begin
j:=ord(s[i]) - ord('0');
result:=result+digits[j]+poses[i];
end;
for i:=1 to 8 do//Iterate
while pos(illegals[i,1],result)<>0 do
begin
j:=pos(illegals[i,1],result);
delete(result,j,4);
insert(illegals[i,2],result,j);
end;//while
if copy(result,1,2)='亿'then
result:=copy(result,3,length(result));
if copy(result,1,2)='万'then
result:=copy(result,3,length(result));
if copy(result,1,2)='元'then
result:=copy(result,3,length(result));
//if copy(result,length(result)-1,2)='分'then
result:=result+'整';
end;
6.."我们是中国人" 显示长度为5
function GetStrLength(const S: string): integer;
begin
Result:=Length(WideString(S));
end;
1.模拟单击Enter键,焦点往后移动
form.formkeypress(….)
begin
if key=#13 then
begin
key:=#0;
Perform(WM_NextDlgct,0,0);
End;
End;
procedure TfrChange.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState); //对窗体的onkeydown事件进行,不过要注意,窗体的keypreview要为true;
begin
if Key = 13 then selectnext(ActiveControl,True,True);
end;
2. procedure TfrmMain.FormCreate(Sender: TObject);
//*----------------------------------------------------------*/
//* 用于自适应系统分辨率 */
//----------------------------------------------------------*/
begin
if screen.Width <> 1024 then scaleby(screen.Width,1024); //其中1024为设计时分辨率
end;
3.keypress
procedure TfrmMain.edtTianKeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',#8,#13,#46]) then key := #0; //#8- BackSpace,#13-Enter,#46-Del
end;
4.DBGrid中的下拉列表和查找字段
设 置 好DBGrid 中 该 字 段 的PickList 字 符 串 列 表、 初 始 的 序 号 值DropDownRows 即 可
5..金钱转成大写
function TForm1.Moneytochinese(v:currency):string;
const
digits:array[0..9] of string=('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
poses:array[1..14] of string=('仟','佰','拾','亿','仟','佰','拾','万','仟','佰','拾','元','角','分');
illegals:array[1..8,1..2] of string=(('零亿','亿'),('零万','万'),('零仟','零'),('零佰','零'),('零拾','零'),('零元','元'),('零角','零'),('零分',''));
var i,j:integer;
s:string;
begin
result:='';
if v=0 then
exit;
s:=formatfloat('0',v*100);
while pos('00',s) <> 0 do
s[Pos('00',s)]:=' ';
s:=stringofchar(' ',14-length(s))+s;
for i:=1 to length(s) do
if(s[i]='') and(i in [4,8,12])then
result:=result+poses[i]
else
if s[i] in['0','1','2','3','4','5','6','7','8','9']then
begin
j:=ord(s[i]) - ord('0');
result:=result+digits[j]+poses[i];
end;
for i:=1 to 8 do//Iterate
while pos(illegals[i,1],result)<>0 do
begin
j:=pos(illegals[i,1],result);
delete(result,j,4);
insert(illegals[i,2],result,j);
end;//while
if copy(result,1,2)='亿'then
result:=copy(result,3,length(result));
if copy(result,1,2)='万'then
result:=copy(result,3,length(result));
if copy(result,1,2)='元'then
result:=copy(result,3,length(result));
//if copy(result,length(result)-1,2)='分'then
result:=result+'整';
end;
6.."我们是中国人" 显示长度为5
function GetStrLength(const S: string): integer;
begin
Result:=Length(WideString(S));
end;
http://expert.csdn.net/Expert/topic/2158/2158219.xml?temp=.5424463
http://expert.csdn.net/Expert/topic/2153/2153923.xml?temp=.350094
在DELPHI中的字符串中,没有0子,只有从1开始,如string[0]是错的,只有string[1];因此
stirng:=’asd’;则string[1]:=’a’;而string[0]是错的,